@@ -21,7 +21,7 @@ extern crate libc;
2121
2222use TypeStructure :: { TypeInt , TypeFunction } ;
2323use AstKind :: { ExprInt , ExprVar , ExprLambda } ;
24- use arena:: Arena ;
24+ use arena:: TypedArena ;
2525use std:: collections:: HashMap ;
2626use std:: mem;
2727
@@ -45,17 +45,20 @@ impl<'tcx> PartialEq for TypeStructure<'tcx> {
4545
4646impl < ' tcx > Eq for TypeStructure < ' tcx > { }
4747
48+ type TyArena < ' tcx > = TypedArena < TypeStructure < ' tcx > > ;
49+ type AstArena < ' ast > = TypedArena < AstStructure < ' ast > > ;
50+
4851struct TypeContext < ' tcx , ' ast > {
49- ty_arena : & ' tcx Arena ,
52+ ty_arena : & ' tcx TyArena < ' tcx > ,
5053 types : Vec < Type < ' tcx > > ,
5154 type_table : HashMap < NodeId , Type < ' tcx > > ,
5255
53- ast_arena : & ' ast Arena ,
56+ ast_arena : & ' ast AstArena < ' ast > ,
5457 ast_counter : uint ,
5558}
5659
5760impl < ' 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 > )
5962 -> TypeContext < ' tcx , ' ast > {
6063 TypeContext { ty_arena : ty_arena,
6164 types : Vec :: new ( ) ,
@@ -72,7 +75,7 @@ impl<'tcx,'ast> TypeContext<'tcx, 'ast> {
7275 }
7376 }
7477
75- let ty = self . ty_arena . alloc ( || s) ;
78+ let ty = self . ty_arena . alloc ( s) ;
7679 self . types . push ( ty) ;
7780 ty
7881 }
@@ -85,7 +88,7 @@ impl<'tcx,'ast> TypeContext<'tcx, 'ast> {
8588 fn ast ( & mut self , a : AstKind < ' ast > ) -> Ast < ' ast > {
8689 let id = self . ast_counter ;
8790 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 } )
8992 }
9093}
9194
@@ -127,8 +130,8 @@ fn compute_types<'tcx,'ast>(tcx: &mut TypeContext<'tcx,'ast>,
127130}
128131
129132pub 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 ( ) ;
132135 let mut tcx = TypeContext :: new ( & ty_arena, & ast_arena) ;
133136 let ast = tcx. ast ( ExprInt ) ;
134137 let ty = compute_types ( & mut tcx, ast) ;
0 commit comments