@@ -36,7 +36,6 @@ export constr_table;
36
36
export count_ty_params;
37
37
export ctxt;
38
38
export def_has_ty_params;
39
- export eq_ty;
40
39
export expr_has_ty_params;
41
40
export expr_ty;
42
41
export expr_ty_params_and_ty;
@@ -47,7 +46,6 @@ export field_idx;
47
46
export get_field;
48
47
export fm_general;
49
48
export get_element_type;
50
- export hash_ty;
51
49
export idx_nil;
52
50
export is_binopable;
53
51
export is_pred_ty;
@@ -103,6 +101,7 @@ export stmt_node_id;
103
101
export sty;
104
102
export substitute_type_params;
105
103
export t;
104
+ export new_ty_hash;
106
105
export tag_variants;
107
106
export tag_variant_with_id;
108
107
export ty_param_substs_opt_and_ty;
@@ -398,12 +397,16 @@ fn mk_rcache() -> creader_cache {
398
397
ret map:: mk_hashmap ( hash_cache_entry, eq_cache_entries) ;
399
398
}
400
399
400
+ fn new_ty_hash < copy V > ( ) -> map:: hashmap < t , V > { map:: new_uint_hash ( ) }
401
401
402
402
fn mk_ctxt ( s : session:: session , dm : resolve:: def_map , amap : ast_map:: map ,
403
403
freevars : freevars:: freevar_map ) -> ctxt {
404
404
let ntt: node_type_table =
405
405
@smallintmap:: mk :: < ty:: ty_param_substs_opt_and_ty > ( ) ;
406
406
let tcache = new_def_hash :: < ty:: ty_param_kinds_and_ty > ( ) ;
407
+ fn eq_raw_ty ( & & a: @raw_t , & & b: @raw_t ) -> bool {
408
+ ret a. hash == b. hash && a. struct == b. struct ;
409
+ }
407
410
let ts = @interner:: mk :: < @raw_t > ( hash_raw_ty, eq_raw_ty) ;
408
411
let cx =
409
412
@{ ts: ts,
@@ -414,9 +417,9 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
414
417
freevars: freevars,
415
418
tcache: tcache,
416
419
rcache: mk_rcache ( ) ,
417
- short_names_cache: map :: mk_hashmap ( ty :: hash_ty , ty :: eq_ty ) ,
418
- needs_drop_cache: map :: mk_hashmap ( ty :: hash_ty , ty :: eq_ty ) ,
419
- kind_cache: map :: mk_hashmap ( ty :: hash_ty , ty :: eq_ty ) ,
420
+ short_names_cache: new_ty_hash ( ) ,
421
+ needs_drop_cache: new_ty_hash ( ) ,
422
+ kind_cache: new_ty_hash ( ) ,
420
423
ast_ty_to_ty_cache:
421
424
map:: mk_hashmap ( ast_util:: hash_ty, ast_util:: eq_ty) ,
422
425
tag_var_cache: @smallintmap:: mk ( ) } ;
@@ -1233,8 +1236,7 @@ fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t {
1233
1236
ret t1;
1234
1237
}
1235
1238
1236
- // Type hashing. This function is private to this module (and slow); external
1237
- // users should use `hash_ty()` instead.
1239
+ // Type hashing.
1238
1240
fn hash_type_structure ( st : sty ) -> uint {
1239
1241
fn hash_uint ( id : uint , n : uint ) -> uint {
1240
1242
let h = id;
@@ -1249,7 +1251,7 @@ fn hash_type_structure(st: sty) -> uint {
1249
1251
}
1250
1252
fn hash_subty ( id : uint , subty : t ) -> uint {
1251
1253
let h = id;
1252
- h += ( h << 5 u) + hash_ty ( subty) ;
1254
+ h += ( h << 5 u) + subty;
1253
1255
ret h;
1254
1256
}
1255
1257
fn hash_subtys ( id : uint , subtys : [ t ] ) -> uint {
@@ -1284,8 +1286,8 @@ fn hash_type_structure(st: sty) -> uint {
1284
1286
1285
1287
fn hash_fn ( id : uint , args : [ arg ] , rty : t ) -> uint {
1286
1288
let h = id;
1287
- for a: arg in args { h += ( h << 5 u) + hash_ty ( a. ty ) ; }
1288
- h += ( h << 5 u) + hash_ty ( rty) ;
1289
+ for a: arg in args { h += ( h << 5 u) + a. ty ; }
1290
+ h += ( h << 5 u) + rty;
1289
1291
ret h;
1290
1292
}
1291
1293
alt st {
@@ -1308,14 +1310,14 @@ fn hash_type_structure(st: sty) -> uint {
1308
1310
ty_str. { ret 17 u ; }
1309
1311
ty_tag ( did, tys) {
1310
1312
let h = hash_def ( 18 u, did) ;
1311
- for typ: t in tys { h += ( h << 5 u) + hash_ty ( typ) ; }
1313
+ for typ: t in tys { h += ( h << 5 u) + typ; }
1312
1314
ret h;
1313
1315
}
1314
1316
ty_box ( mt) { ret hash_subty( 19 u, mt. ty ) ; }
1315
1317
ty_vec ( mt) { ret hash_subty( 21 u, mt. ty ) ; }
1316
1318
ty_rec ( fields) {
1317
1319
let h = 26 u;
1318
- for f: field in fields { h += ( h << 5 u) + hash_ty ( f. mt . ty ) ; }
1320
+ for f: field in fields { h += ( h << 5 u) + f. mt . ty ; }
1319
1321
ret h;
1320
1322
}
1321
1323
ty_tup ( ts) { ret hash_subtys ( 25 u, ts) ; }
@@ -1354,13 +1356,6 @@ fn hash_type_structure(st: sty) -> uint {
1354
1356
1355
1357
fn hash_raw_ty ( & & rt: @raw_t ) -> uint { ret rt. hash ; }
1356
1358
1357
- fn hash_ty ( & & typ: t ) -> uint { ret typ; }
1358
-
1359
-
1360
- // Type equality. This function is private to this module (and slow); external
1361
- // users should use `eq_ty()` instead.
1362
- fn eq_int ( & & x: uint , & & y: uint ) -> bool { ret x == y; }
1363
-
1364
1359
fn arg_eq < T > ( eq : fn ( T , T ) -> bool , a : @sp_constr_arg < T > , b : @sp_constr_arg < T > )
1365
1360
-> bool {
1366
1361
alt a. node {
@@ -1389,6 +1384,7 @@ fn args_eq<T>(eq: fn(T, T) -> bool, a: [@sp_constr_arg<T>],
1389
1384
}
1390
1385
1391
1386
fn constr_eq( c: @constr, d: @constr) -> bool {
1387
+ fn eq_int( & & x: uint, & & y: uint) -> bool { ret x == y; }
1392
1388
ret path_to_str( c. node. path) == path_to_str( d. node. path) &&
1393
1389
// FIXME: hack
1394
1390
args_eq( eq_int, c. node. args, d. node. args) ;
@@ -1401,16 +1397,6 @@ fn constrs_eq(cs: [@constr], ds: [@constr]) -> bool {
1401
1397
ret true;
1402
1398
}
1403
1399
1404
- // This function is private to this module.
1405
- fn eq_raw_ty ( & & a: @raw_t , & & b: @raw_t ) -> bool {
1406
- ret a. hash == b. hash && a. struct == b. struct ;
1407
- }
1408
-
1409
-
1410
- // This is the equality function the public should use. It works as long as
1411
- // the types are interned.
1412
- fn eq_ty ( & & a: t , & & b: t ) -> bool { a == b }
1413
-
1414
1400
// Type lookups
1415
1401
fn node_id_to_ty_param_substs_opt_and_ty ( cx : ctxt , id : ast:: node_id ) ->
1416
1402
ty_param_substs_opt_and_ty {
@@ -2088,12 +2074,15 @@ mod unify {
2088
2074
2089
2075
fn unify_step ( cx : @ctxt , expected : t , actual : t ,
2090
2076
variance : variance ) -> result {
2091
- // TODO : rewrite this using tuple pattern matching when available, to
2077
+ // FIXME : rewrite this using tuple pattern matching when available, to
2092
2078
// avoid all this rightward drift and spikiness.
2079
+ // NOTE: we have tuple matching now, but that involves copying the
2080
+ // matched elements into a tuple first, which is expensive, since sty
2081
+ // holds vectors, which are currently unique
2093
2082
2094
2083
// Fast path.
2084
+ if expected == actual { ret ures_ok ( expected) ; }
2095
2085
2096
- if eq_ty ( expected, actual) { ret ures_ok ( expected) ; }
2097
2086
// Stage 1: Handle the cases in which one side or another is a type
2098
2087
// variable.
2099
2088
0 commit comments