@@ -53,8 +53,7 @@ type fn_ctxt = rec(@ty.t ret_ty,
53
53
@crate_ctxt ccx ) ;
54
54
55
55
// Used for ast_ty_to_ty() below.
56
- type ty_and_params = rec ( vec[ ast. ty_param] params , @ty. t ty ) ;
57
- type ty_getter = fn ( ast. def_id ) -> ty_and_params ;
56
+ type ty_getter = fn ( ast. def_id ) -> ty. ty_params_and_ty ;
58
57
59
58
// Replaces parameter types inside a type with type variables.
60
59
fn generalize_ty ( @crate_ctxt cx , @ty. t t ) -> @ty. t {
@@ -128,6 +127,23 @@ fn substitute_ty_params(&@crate_ctxt ccx,
128
127
ret ty. fold_ty ( substituter, typ) ;
129
128
}
130
129
130
+
131
+ // Looks up the type of the given item in an external crate.
132
+ fn lookup_item_type_if_necessary ( @crate_ctxt ccx , ast. def_id did ) {
133
+ if ( did. _0 == ccx. sess . get_targ_crate_num ( ) ) {
134
+ ret; // Nothing to do; it should already be in the tables.
135
+ }
136
+
137
+ if ( ccx. item_types . contains_key ( did) ) {
138
+ ret; // Nothing to do; we already looked up this item's type.
139
+ }
140
+
141
+ auto tyt = creader. get_type ( ccx. sess , did) ;
142
+ ccx. item_types . insert ( did, tyt. _1 ) ;
143
+ ccx. item_ty_params . insert ( did, tyt. _0 ) ;
144
+ }
145
+
146
+
131
147
type ty_params_opt_and_ty = tup ( option. t[ vec[ ast. def_id ] ] , @ty. t ) ;
132
148
133
149
// Returns the type parameters and the type for the given definition.
@@ -151,20 +167,25 @@ fn ty_params_and_ty_for_def(@fn_ctxt fcx, &ast.def defn)
151
167
ret tup( none[ vec[ ast. def_id ] ] , fcx. locals . get ( id) ) ;
152
168
}
153
169
case ( ast. def_fn ( ?id) ) {
170
+ lookup_item_type_if_necessary ( fcx. ccx , id) ;
154
171
check ( fcx. ccx . item_types . contains_key ( id) ) ;
155
172
ret tup( some ( fcx. ccx . item_ty_params . get ( id) ) ,
156
173
fcx. ccx . item_types . get ( id) ) ;
157
174
}
158
175
case ( ast. def_native_fn ( ?id) ) {
176
+ lookup_item_type_if_necessary ( fcx. ccx , id) ;
159
177
check ( fcx. ccx . item_types . contains_key ( id) ) ;
160
178
ret tup( some ( fcx. ccx . item_ty_params . get ( id) ) ,
161
179
fcx. ccx . item_types . get ( id) ) ;
162
180
}
163
181
case ( ast. def_const ( ?id) ) {
182
+ lookup_item_type_if_necessary ( fcx. ccx , id) ;
164
183
check ( fcx. ccx . item_types . contains_key ( id) ) ;
165
184
ret tup( none[ vec[ ast. def_id ] ] , fcx. ccx . item_types . get ( id) ) ;
166
185
}
167
186
case ( ast. def_variant ( ?tag_id, ?variant_id) ) {
187
+ lookup_item_type_if_necessary ( fcx. ccx , tag_id) ;
188
+ lookup_item_type_if_necessary ( fcx. ccx , variant_id) ;
168
189
check ( fcx. ccx . item_types . contains_key ( variant_id) ) ;
169
190
ret tup( some ( fcx. ccx . item_ty_params . get ( tag_id) ) ,
170
191
fcx. ccx . item_types . get ( variant_id) ) ;
@@ -174,6 +195,7 @@ fn ty_params_and_ty_for_def(@fn_ctxt fcx, &ast.def defn)
174
195
ret tup( none[ vec[ ast. def_id ] ] , fcx. locals . get ( id) ) ;
175
196
}
176
197
case ( ast. def_obj ( ?id) ) {
198
+ lookup_item_type_if_necessary ( fcx. ccx , id) ;
177
199
check ( fcx. ccx . item_types . contains_key ( id) ) ;
178
200
ret tup( some ( fcx. ccx . item_ty_params . get ( id) ) ,
179
201
fcx. ccx . item_types . get ( id) ) ;
@@ -291,17 +313,17 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
291
313
// TODO: maybe record cname chains so we can do
292
314
// "foo = int" like OCaml?
293
315
auto ty_and_params = getter ( id) ;
294
- auto params = ty_and_params. params ;
316
+ auto params = ty_and_params. _0 ;
295
317
auto num_type_args = _vec. len [ @ast. ty ] ( args) ;
296
- check ( num_type_args == _vec. len [ ast. ty_param ] ( params) ) ;
318
+ check ( num_type_args == _vec. len [ ast. def_id ] ( params) ) ;
297
319
298
320
auto param_map = common. new_def_hash [ @ty. t] ( ) ;
299
321
for each ( uint i in _uint. range( 0 u, num_type_args) ) {
300
322
auto arg = args. ( i) ;
301
323
auto param = params. ( i) ;
302
- param_map. insert( param. id , ast_ty_to_ty( getter, arg) ) ;
324
+ param_map. insert( param, ast_ty_to_ty( getter, arg) ) ;
303
325
}
304
- ret ty. replace_type_params( ty_and_params. ty , param_map) ;
326
+ ret ty. replace_type_params( ty_and_params. _1 , param_map) ;
305
327
}
306
328
307
329
auto mut = ast. imm;
@@ -404,7 +426,7 @@ fn actual_type(@ty.t t, @ast.item item) -> @ty.t {
404
426
// A convenience function to use a crate_ctxt to resolve names for
405
427
// ast_ty_to_ty.
406
428
fn ast_ty_to_ty_crate( @crate_ctxt ccx, & @ast. ty ast_ty) -> @ty. t {
407
- fn getter( @crate_ctxt ccx, ast. def_id id) -> ty_and_params {
429
+ fn getter( @crate_ctxt ccx, ast. def_id id) -> ty . ty_params_and_ty {
408
430
409
431
if ( id. _0 != ccx. sess. get_targ_crate_num( ) ) {
410
432
// This is a type we need to load in from the crate reader.
@@ -426,7 +448,12 @@ fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast.ty ast_ty) -> @ty.t {
426
448
}
427
449
}
428
450
429
- ret rec( params = params, ty = ty) ;
451
+ let vec[ ast. def_id] param_ids = vec( ) ;
452
+ for ( ast. ty_param tp in params) {
453
+ param_ids += vec( tp. id) ;
454
+ }
455
+
456
+ ret tup( param_ids, ty) ;
430
457
}
431
458
auto f = bind getter( ccx, _) ;
432
459
ret ast_ty_to_ty( f, ast_ty) ;
@@ -510,7 +537,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
510
537
fn getter( session. session sess,
511
538
@ty_item_table id_to_ty_item,
512
539
@ty_table item_to_ty,
513
- ast. def_id id) -> ty_and_params {
540
+ ast. def_id id) -> ty . ty_params_and_ty {
514
541
515
542
if ( id. _0 != sess. get_targ_crate_num( ) ) {
516
543
// This is a type we need to load in from the crate reader.
@@ -535,7 +562,12 @@ fn collect_item_types(session.session sess, @ast.crate crate)
535
562
}
536
563
}
537
564
538
- ret rec( params = params, ty = ty) ;
565
+ let vec[ ast. def_id] param_ids = vec( ) ;
566
+ for ( ast. ty_param tp in params) {
567
+ param_ids += vec( tp. id) ;
568
+ }
569
+
570
+ ret tup( param_ids, ty) ;
539
571
}
540
572
541
573
fn ty_of_arg( session. session sess,
0 commit comments