@@ -26,6 +26,14 @@ export get_crate_attributes;
26
26
export list_crate_metadata;
27
27
export crate_dep;
28
28
export get_crate_deps;
29
+ export external_resolver;
30
+
31
+ // A function that takes a def_id relative to the crate being searched and
32
+ // returns a def_id relative to the compilation environment, i.e. if we hit a
33
+ // def_id for an item defined in another crate, somebody needs to figure out
34
+ // what crate that's in and give us a def_id that makes sense for the current
35
+ // build.
36
+ type external_resolver = fn ( & ast:: def_id def_id) -> ast:: def_id ;
29
37
30
38
fn lookup_hash( & ebml:: doc d, fn ( vec[ u8 ] ) -> bool eq_fn , uint hash) ->
31
39
vec[ ebml:: doc ] {
@@ -85,8 +93,10 @@ fn variant_tag_id(&ebml::doc d) -> ast::def_id {
85
93
}
86
94
87
95
fn item_type( & ebml:: doc item, ast:: crate_num this_cnum,
88
- ty:: ctxt tcx) -> ty:: t {
89
- fn parse_external_def_id( ast:: crate_num this_cnum, str s) -> ast:: def_id {
96
+ ty:: ctxt tcx, & external_resolver extres) -> ty:: t {
97
+ fn parse_external_def_id( ast:: crate_num this_cnum,
98
+ & external_resolver extres,
99
+ str s) -> ast:: def_id {
90
100
auto buf = str:: bytes( s) ;
91
101
auto external_def_id = parse_def_id( buf) ;
92
102
@@ -95,17 +105,13 @@ fn item_type(&ebml::doc item, ast::crate_num this_cnum,
95
105
if ( external_def_id. _0 == ast:: local_crate) {
96
106
ret tup( this_cnum, external_def_id. _1) ;
97
107
} else {
98
- // FIXME: This is completely wrong when linking against a crate
99
- // that, in turn, links against another crate. We need a mapping
100
- // from crate ID to crate "meta" attributes as part of the crate
101
- // metadata:
102
- fail "trying to load type info from a crate that is \
103
- defined in a different crate";
108
+ ret extres( external_def_id) ;
104
109
}
105
110
}
106
111
auto tp = ebml:: get_doc( item, tag_items_data_item_type) ;
112
+ auto def_parser = bind parse_external_def_id( this_cnum, extres, _) ;
107
113
ret parse_ty_data( item. data, this_cnum, tp. start, tp. end - tp. start,
108
- bind parse_external_def_id ( this_cnum , _ ) , tcx) ;
114
+ def_parser , tcx) ;
109
115
}
110
116
111
117
fn item_ty_param_count( & ebml:: doc item) -> uint {
@@ -180,12 +186,12 @@ fn lookup_def(ast::crate_num cnum, vec[u8] data,
180
186
ret def;
181
187
}
182
188
183
- fn get_type( & vec[ u8] data, ast:: def_id def,
184
- & ty :: ctxt tcx ) -> ty:: ty_param_count_and_ty {
189
+ fn get_type( & vec[ u8] data, ast:: def_id def, & ty :: ctxt tcx ,
190
+ & external_resolver extres ) -> ty:: ty_param_count_and_ty {
185
191
auto this_cnum = def. _0;
186
192
auto node_id = def. _1;
187
193
auto item = lookup_item( node_id, data) ;
188
- auto t = item_type( item, this_cnum, tcx) ;
194
+ auto t = item_type( item, this_cnum, tcx, extres ) ;
189
195
auto tp_count;
190
196
auto kind_ch = item_kind( item) ;
191
197
auto has_ty_params = kind_has_type_params( kind_ch) ;
@@ -204,7 +210,8 @@ fn get_symbol(&vec[u8] data, ast::node_id id) -> str {
204
210
}
205
211
206
212
fn get_tag_variants( & vec[ u8] data, ast:: def_id def,
207
- & ty:: ctxt tcx) -> ty:: variant_info[ ] {
213
+ & ty:: ctxt tcx,
214
+ & external_resolver extres) -> ty:: variant_info[ ] {
208
215
auto external_crate_id = def. _0;
209
216
auto data = cstore:: get_crate_data( tcx. sess. get_cstore( ) ,
210
217
external_crate_id) . data;
@@ -214,7 +221,7 @@ fn get_tag_variants(&vec[u8] data, ast::def_id def,
214
221
auto variant_ids = tag_variant_ids( item, external_crate_id) ;
215
222
for ( ast:: def_id did in variant_ids) {
216
223
auto item = find_item( did. _1, items) ;
217
- auto ctor_ty = item_type( item, external_crate_id, tcx) ;
224
+ auto ctor_ty = item_type( item, external_crate_id, tcx, extres ) ;
218
225
let ty:: t[ ] arg_tys = ~[ ] ;
219
226
alt ( ty:: struct( tcx, ctor_ty) ) {
220
227
case ( ty:: ty_fn( _, ?args, _, _, _) ) {
0 commit comments