@@ -33,6 +33,8 @@ import util::common::new_def_hash;
33
33
import util:: common:: span;
34
34
import util:: typestate_ann:: ts_ann;
35
35
36
+ import util:: interner;
37
+
36
38
// Data types
37
39
38
40
tag mode {
@@ -159,19 +161,14 @@ const uint idx_native = 18u;
159
161
const uint idx_type = 19 u;
160
162
const uint idx_first_others = 20 u;
161
163
162
- type type_store = rec ( mutable vec[ raw_t] others ,
163
- hashmap[ raw_t, uint] other_structural ) ;
164
+ type type_store = interner:: interner [ raw_t] ;
164
165
165
166
type ty_param_substs_opt_and_ty = tup ( option:: t[ vec[ ty:: t ] ] , ty:: t ) ;
166
167
type node_type_table =
167
168
@mutable vec[ mutable option:: t [ ty:: ty_param_substs_opt_and_ty ] ] ;
168
169
169
170
fn mk_type_store ( ) -> @type_store {
170
- let vec[ raw_t] others = vec ( ) ;
171
- let hashmap[ raw_t, uint] ost =
172
- map:: mk_hashmap[ raw_t, uint] ( hash_raw_ty, eq_raw_ty) ;
173
-
174
- auto ts = @rec ( mutable others=others, other_structural=ost) ;
171
+ auto ts = @interner:: mk_interner[ raw_t] ( hash_raw_ty, eq_raw_ty) ;
175
172
176
173
intern ( ts, ty_nil, none[ str] ) ;
177
174
intern ( ts, ty_bool, none[ str] ) ;
@@ -194,7 +191,7 @@ fn mk_type_store() -> @type_store {
194
191
intern ( ts, ty_native, none[ str] ) ;
195
192
intern ( ts, ty_type, none[ str] ) ;
196
193
197
- assert _vec:: len ( ts. others ) == idx_first_others;
194
+ assert _vec:: len ( ts. vect ) == idx_first_others;
198
195
199
196
ret ts;
200
197
}
@@ -240,7 +237,7 @@ fn mk_raw_ty(&@type_store ts, &sty st, &option::t[str] cname) -> raw_t {
240
237
& mutable bool has_vars ,
241
238
& mutable bool has_locals ,
242
239
& t tt ) {
243
- auto rt = ts . others . ( tt) ;
240
+ auto rt = interner :: get [ raw_t ] ( * ts , tt) ;
244
241
has_params = has_params || rt. has_params ;
245
242
has_bound_params = has_bound_params || rt. has_bound_params ;
246
243
has_vars = has_vars || rt. has_vars ;
@@ -355,32 +352,13 @@ fn mk_raw_ty(&@type_store ts, &sty st, &option::t[str] cname) -> raw_t {
355
352
has_locals = has_locals) ;
356
353
}
357
354
358
- fn intern_raw_ty ( & @type_store ts , & raw_t rt) {
359
- auto type_num = _vec:: len[ raw_t] ( ts. others ) ;
360
- ts. others += vec ( rt) ;
361
- ts. other_structural . insert ( rt, type_num) ;
362
- }
363
-
364
355
fn intern ( & @type_store ts , & sty st, & option:: t[ str] cname ) {
365
- intern_raw_ty ( ts, mk_raw_ty ( ts, st, cname) ) ;
356
+ interner :: intern [ raw_t ] ( * ts, mk_raw_ty ( ts, st, cname) ) ;
366
357
}
367
358
368
359
fn gen_ty_full ( & ctxt cx, & sty st, & option:: t[ str] cname ) -> t {
369
360
auto raw_type = mk_raw_ty ( cx. ts , st, cname) ;
370
-
371
- // Is it interned?
372
- alt ( cx. ts . other_structural . find ( raw_type) ) {
373
- case ( some[ t] ( ?typ) ) {
374
- ret typ;
375
- }
376
- case ( none[ t] ) {
377
- // Nope: Insert it and return.
378
- auto type_num = _vec:: len[ raw_t] ( cx. ts . others ) ;
379
- intern_raw_ty ( cx. ts , raw_type) ;
380
- // log_err "added: " + ty_to_str(tystore, raw_type);
381
- ret type_num;
382
- }
383
- }
361
+ ret interner:: intern[ raw_t] ( * cx. ts , raw_type) ;
384
362
}
385
363
386
364
// These are private constructors to this module. External users should always
@@ -484,10 +462,14 @@ fn mk_native(&ctxt cx) -> t { ret idx_native; }
484
462
485
463
486
464
// Returns the one-level-deep type structure of the given type.
487
- fn struct ( & ctxt cx, & t typ ) -> sty { ret cx. ts . others . ( typ) . struct ; }
465
+ fn struct ( & ctxt cx, & t typ ) -> sty {
466
+ ret interner:: get[ raw_t] ( * cx. ts , typ) . struct ;
467
+ }
488
468
489
469
// Returns the canonical name of the given type.
490
- fn cname ( & ctxt cx, & t typ ) -> option:: t [ str ] { ret cx. ts . others . ( typ) . cname ; }
470
+ fn cname ( & ctxt cx, & t typ ) -> option:: t [ str ] {
471
+ ret interner:: get[ raw_t] ( * cx. ts , typ) . cname ;
472
+ }
491
473
492
474
493
475
// Stringification
@@ -1525,19 +1507,19 @@ fn count_ty_params(ctxt cx, t ty) -> uint {
1525
1507
}
1526
1508
1527
1509
fn type_contains_vars ( & ctxt cx, & t typ ) -> bool {
1528
- ret cx. ts . others . ( typ) . has_vars ;
1510
+ ret interner :: get [ raw_t ] ( * cx. ts , typ) . has_vars ;
1529
1511
}
1530
1512
1531
1513
fn type_contains_locals ( & ctxt cx, & t typ ) -> bool {
1532
- ret cx. ts . others . ( typ) . has_locals ;
1514
+ ret interner :: get [ raw_t ] ( * cx. ts , typ) . has_locals ;
1533
1515
}
1534
1516
1535
1517
fn type_contains_params ( & ctxt cx, & t typ ) -> bool {
1536
- ret cx. ts . others . ( typ) . has_params ;
1518
+ ret interner :: get [ raw_t ] ( * cx. ts , typ) . has_params ;
1537
1519
}
1538
1520
1539
1521
fn type_contains_bound_params ( & ctxt cx, & t typ ) -> bool {
1540
- ret cx. ts . others . ( typ) . has_bound_params ;
1522
+ ret interner :: get [ raw_t ] ( * cx. ts , typ) . has_bound_params ;
1541
1523
}
1542
1524
1543
1525
// Type accessors for substructures of types
0 commit comments