@@ -21,7 +21,7 @@ extern crate libc;
21
21
22
22
use TypeStructure :: { TypeInt , TypeFunction } ;
23
23
use AstKind :: { ExprInt , ExprVar , ExprLambda } ;
24
- use arena:: Arena ;
24
+ use arena:: TypedArena ;
25
25
use std:: collections:: HashMap ;
26
26
use std:: mem;
27
27
@@ -45,17 +45,20 @@ impl<'tcx> PartialEq for TypeStructure<'tcx> {
45
45
46
46
impl < ' tcx > Eq for TypeStructure < ' tcx > { }
47
47
48
+ type TyArena < ' tcx > = TypedArena < TypeStructure < ' tcx > > ;
49
+ type AstArena < ' ast > = TypedArena < AstStructure < ' ast > > ;
50
+
48
51
struct TypeContext < ' tcx , ' ast > {
49
- ty_arena : & ' tcx Arena ,
52
+ ty_arena : & ' tcx TyArena < ' tcx > ,
50
53
types : Vec < Type < ' tcx > > ,
51
54
type_table : HashMap < NodeId , Type < ' tcx > > ,
52
55
53
- ast_arena : & ' ast Arena ,
56
+ ast_arena : & ' ast AstArena < ' ast > ,
54
57
ast_counter : uint ,
55
58
}
56
59
57
60
impl < ' tcx , ' ast > TypeContext < ' tcx , ' ast > {
58
- fn new ( ty_arena : & ' tcx Arena , ast_arena : & ' ast Arena )
61
+ fn new ( ty_arena : & ' tcx TyArena < ' tcx > , ast_arena : & ' ast AstArena < ' ast > )
59
62
-> TypeContext < ' tcx , ' ast > {
60
63
TypeContext { ty_arena : ty_arena,
61
64
types : Vec :: new ( ) ,
@@ -72,7 +75,7 @@ impl<'tcx,'ast> TypeContext<'tcx, 'ast> {
72
75
}
73
76
}
74
77
75
- let ty = self . ty_arena . alloc ( || s) ;
78
+ let ty = self . ty_arena . alloc ( s) ;
76
79
self . types . push ( ty) ;
77
80
ty
78
81
}
@@ -85,7 +88,7 @@ impl<'tcx,'ast> TypeContext<'tcx, 'ast> {
85
88
fn ast ( & mut self , a : AstKind < ' ast > ) -> Ast < ' ast > {
86
89
let id = self . ast_counter ;
87
90
self . ast_counter += 1 ;
88
- self . ast_arena . alloc ( || AstStructure { id : NodeId { id : id} , kind : a } )
91
+ self . ast_arena . alloc ( AstStructure { id : NodeId { id : id} , kind : a } )
89
92
}
90
93
}
91
94
@@ -127,8 +130,8 @@ fn compute_types<'tcx,'ast>(tcx: &mut TypeContext<'tcx,'ast>,
127
130
}
128
131
129
132
pub fn main ( ) {
130
- let ty_arena = arena :: Arena :: new ( ) ;
131
- let ast_arena = arena :: Arena :: new ( ) ;
133
+ let ty_arena = TypedArena :: new ( ) ;
134
+ let ast_arena = TypedArena :: new ( ) ;
132
135
let mut tcx = TypeContext :: new ( & ty_arena, & ast_arena) ;
133
136
let ast = tcx. ast ( ExprInt ) ;
134
137
let ty = compute_types ( & mut tcx, ast) ;
0 commit comments