Skip to content

Commit 494ad4e

Browse files
committed
Merge branch 'master' into kmath
2 parents a16acc0 + 3a20dda commit 494ad4e

30 files changed

+586
-399
lines changed

src/comp/metadata/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ const tag_crate_hash: uint = 0x28u;
6666

6767
const tag_mod_impl: uint = 0x30u;
6868

69-
const tag_impl_method: uint = 0x31u;
69+
const tag_item_method: uint = 0x31u;
70+
const tag_impl_iface: uint = 0x32u;
71+
const tag_impl_iface_did: uint = 0x33u;
7072

7173
// djb's cdb hashes.
7274
fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }

src/comp/metadata/csearch.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export get_type_param_count;
1010
export lookup_defs;
1111
export get_tag_variants;
1212
export get_impls_for_mod;
13-
export get_impl_methods;
13+
export get_iface_methods;
1414
export get_type;
1515
export get_item_name;
16+
export get_impl_iface;
1617

1718
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
1819
let cdata = cstore::get_crate_data(cstore, def.crate).data;
@@ -65,33 +66,23 @@ fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
6566

6667
fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,
6768
name: option::t<ast::ident>)
68-
-> [@middle::resolve::_impl] {
69+
-> @[@middle::resolve::_impl] {
6970
let cdata = cstore::get_crate_data(cstore, def.crate).data;
70-
let result = [];
71-
for did in decoder::get_impls_for_mod(cdata, def.node, def.crate) {
72-
let nm = decoder::lookup_item_name(cdata, did.node);
73-
if alt name { some(n) { n == nm } none. { true } } {
74-
result += [@{did: did,
75-
iface_did: none::<ast::def_id>, // FIXME[impl]
76-
ident: nm,
77-
methods: decoder::lookup_impl_methods(
78-
cdata, did.node, did.crate)}];
79-
}
80-
}
81-
result
71+
let resolver = bind translate_def_id(cstore, def.crate, _);
72+
decoder::get_impls_for_mod(cdata, def, name, resolver)
8273
}
8374

84-
fn get_impl_methods(cstore: cstore::cstore, def: ast::def_id)
85-
-> [@middle::resolve::method_info] {
75+
fn get_iface_methods(tcx: ty::ctxt, def: ast::def_id) -> @[ty::method] {
76+
let cstore = tcx.sess.get_cstore();
8677
let cdata = cstore::get_crate_data(cstore, def.crate).data;
87-
decoder::lookup_impl_methods(cdata, def.node, def.crate)
78+
let resolver = bind translate_def_id(cstore, def.crate, _);
79+
decoder::get_iface_methods(cdata, def, tcx, resolver)
8880
}
8981

9082
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
9183
let cstore = tcx.sess.get_cstore();
92-
let cnum = def.crate;
93-
let cdata = cstore::get_crate_data(cstore, cnum).data;
94-
let resolver = bind translate_def_id(cstore, cnum, _);
84+
let cdata = cstore::get_crate_data(cstore, def.crate).data;
85+
let resolver = bind translate_def_id(cstore, def.crate, _);
9586
decoder::get_type(cdata, def, tcx, resolver)
9687
}
9788

@@ -100,6 +91,14 @@ fn get_item_name(cstore: cstore::cstore, cnum: int, id: int) -> ast::ident {
10091
ret decoder::lookup_item_name(cdata, id);
10192
}
10293

94+
fn get_impl_iface(tcx: ty::ctxt, def: ast::def_id)
95+
-> option::t<ty::t> {
96+
let cstore = tcx.sess.get_cstore();
97+
let cdata = cstore::get_crate_data(cstore, def.crate).data;
98+
let resolver = bind translate_def_id(cstore, def.crate, _);
99+
decoder::get_impl_iface(cdata, def, tcx, resolver)
100+
}
101+
103102
// Translates a def_id from an external crate to a def_id for the current
104103
// compilation environment. We use this when trying to load types from
105104
// external crates - if those types further refer to types in other crates

src/comp/metadata/decoder.rs

Lines changed: 87 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ export get_symbol;
1414
export get_tag_variants;
1515
export get_type;
1616
export get_type_param_count;
17+
export get_impl_iface;
1718
export lookup_def;
1819
export lookup_item_name;
20+
export get_impl_iface;
1921
export resolve_path;
2022
export get_crate_attributes;
2123
export list_crate_metadata;
@@ -24,7 +26,7 @@ export get_crate_deps;
2426
export get_crate_hash;
2527
export external_resolver;
2628
export get_impls_for_mod;
27-
export lookup_impl_methods;
29+
export get_iface_methods;
2830
// A function that takes a def_id relative to the crate being searched and
2931
// returns a def_id relative to the compilation environment, i.e. if we hit a
3032
// def_id for an item defined in another crate, somebody needs to figure out
@@ -103,16 +105,42 @@ fn parse_external_def_id(this_cnum: ast::crate_num,
103105
} else { ret extres(external_def_id); }
104106
}
105107

108+
fn doc_type(doc: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
109+
extres: external_resolver) -> ty::t {
110+
let tp = ebml::get_doc(doc, tag_items_data_item_type);
111+
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
112+
parse_ty_data(tp.data, this_cnum, tp.start, def_parser, tcx)
113+
}
114+
106115
fn item_type(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
107116
extres: external_resolver) -> ty::t {
108-
let tp = ebml::get_doc(item, tag_items_data_item_type);
109-
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
110-
let t = parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
111-
def_parser, tcx);
117+
let t = doc_type(item, this_cnum, tcx, extres);
112118
if family_names_type(item_family(item)) {
113-
t = ty::mk_named(tcx, t, @item_name(item));
119+
ty::mk_named(tcx, t, @item_name(item))
120+
} else { t }
121+
}
122+
123+
fn item_impl_iface(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
124+
extres: external_resolver) -> option::t<ty::t> {
125+
let result = none;
126+
ebml::tagged_docs(item, tag_impl_iface) {|ity|
127+
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
128+
let t = parse_ty_data(ity.data, this_cnum, ity.start, def_parser,
129+
tcx);
130+
result = some(t);
131+
}
132+
result
133+
}
134+
135+
fn item_impl_iface_did(item: ebml::doc, this_cnum: ast::crate_num,
136+
extres: external_resolver)
137+
-> option::t<ast::def_id> {
138+
let result = none;
139+
ebml::tagged_docs(item, tag_impl_iface_did) {|doc|
140+
let s = str::unsafe_from_bytes(ebml::doc_data(doc));
141+
result = some(parse_external_def_id(this_cnum, extres, s));
114142
}
115-
t
143+
result
116144
}
117145

118146
fn item_ty_param_bounds(item: ebml::doc, this_cnum: ast::crate_num,
@@ -121,8 +149,8 @@ fn item_ty_param_bounds(item: ebml::doc, this_cnum: ast::crate_num,
121149
let bounds = [];
122150
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
123151
ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds) {|p|
124-
bounds += [tydecode::parse_bounds_data(@ebml::doc_data(p), this_cnum,
125-
def_parser, tcx)];
152+
bounds += [tydecode::parse_bounds_data(p.data, p.start,
153+
this_cnum, def_parser, tcx)];
126154
}
127155
@bounds
128156
}
@@ -197,18 +225,17 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
197225
tid = {crate: cnum, node: tid.node};
198226
ast::def_variant(tid, did)
199227
}
228+
'I' { ast::def_ty(did) }
200229
};
201230
ret def;
202231
}
203232

204233
fn get_type(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
205234
extres: external_resolver) -> ty::ty_param_bounds_and_ty {
206-
let this_cnum = def.crate;
207-
let node_id = def.node;
208-
let item = lookup_item(node_id, data);
209-
let t = item_type(item, this_cnum, tcx, extres);
235+
let item = lookup_item(def.node, data);
236+
let t = item_type(item, def.crate, tcx, extres);
210237
let tp_bounds = if family_has_type_params(item_family(item)) {
211-
item_ty_param_bounds(item, this_cnum, tcx, extres)
238+
item_ty_param_bounds(item, def.crate, tcx, extres)
212239
} else { @[] };
213240
ret {bounds: tp_bounds, ty: t};
214241
}
@@ -217,6 +244,11 @@ fn get_type_param_count(data: @[u8], id: ast::node_id) -> uint {
217244
item_ty_param_count(lookup_item(id, data))
218245
}
219246

247+
fn get_impl_iface(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
248+
extres: external_resolver) -> option::t<ty::t> {
249+
item_impl_iface(lookup_item(def.node, data), def.crate, tcx, extres)
250+
}
251+
220252
fn get_symbol(data: @[u8], id: ast::node_id) -> str {
221253
ret item_symbol(lookup_item(id, data));
222254
}
@@ -245,52 +277,59 @@ fn get_tag_variants(_data: @[u8], def: ast::def_id, tcx: ty::ctxt,
245277
ret infos;
246278
}
247279

248-
fn get_impls_for_mod(data: @[u8], node: ast::node_id, cnum: ast::crate_num)
249-
-> [ast::def_id] {
250-
let mod_item = lookup_item(node, data), result = [];
251-
ebml::tagged_docs(mod_item, tag_mod_impl) {|doc|
252-
let did = parse_def_id(ebml::doc_data(doc));
253-
result += [{crate: cnum with did}];
254-
}
255-
result
256-
}
257-
258-
fn lookup_impl_methods(data: @[u8], node: ast::node_id, cnum: ast::crate_num)
280+
fn item_impl_methods(data: @[u8], item: ebml::doc, base_tps: uint)
259281
-> [@middle::resolve::method_info] {
260-
let impl_item = lookup_item(node, data), rslt = [];
261-
let base_tps = item_ty_param_count(impl_item);
262-
ebml::tagged_docs(impl_item, tag_impl_method) {|doc|
282+
let rslt = [];
283+
ebml::tagged_docs(item, tag_item_method) {|doc|
263284
let m_did = parse_def_id(ebml::doc_data(doc));
264285
let mth_item = lookup_item(m_did.node, data);
265-
rslt += [@{did: {crate: cnum, node: m_did.node},
286+
rslt += [@{did: m_did,
266287
n_tps: item_ty_param_count(mth_item) - base_tps,
267288
ident: item_name(mth_item)}];
268289
}
269290
rslt
270291
}
271292

293+
fn get_impls_for_mod(data: @[u8], m_def: ast::def_id,
294+
name: option::t<ast::ident>, extres: external_resolver)
295+
-> @[@middle::resolve::_impl] {
296+
let mod_item = lookup_item(m_def.node, data), result = [];
297+
ebml::tagged_docs(mod_item, tag_mod_impl) {|doc|
298+
let did = parse_external_def_id(
299+
m_def.crate, extres, str::unsafe_from_bytes(ebml::doc_data(doc)));
300+
let item = lookup_item(did.node, data), nm = item_name(item);
301+
if alt name { some(n) { n == nm } none. { true } } {
302+
let base_tps = item_ty_param_count(doc);
303+
let i_did = item_impl_iface_did(item, m_def.crate, extres);
304+
result += [@{did: did, iface_did: i_did, ident: nm,
305+
methods: item_impl_methods(data, doc, base_tps)}];
306+
}
307+
}
308+
@result
309+
}
310+
311+
fn get_iface_methods(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
312+
extres: external_resolver) -> @[ty::method] {
313+
let item = lookup_item(def.node, data), result = [];
314+
ebml::tagged_docs(item, tag_item_method) {|mth|
315+
let bounds = item_ty_param_bounds(mth, def.crate, tcx, extres);
316+
let name = item_name(mth);
317+
let ty = doc_type(mth, def.crate, tcx, extres);
318+
let fty = alt ty::struct(tcx, ty) { ty::ty_fn(f) { f } };
319+
result += [{ident: name, tps: bounds, fty: fty}];
320+
}
321+
@result
322+
}
272323

273324
fn family_has_type_params(fam_ch: u8) -> bool {
274-
ret alt fam_ch as char {
275-
'c' { false }
276-
'f' { true }
277-
'u' { true }
278-
'p' { true }
279-
'F' { true }
280-
'U' { true }
281-
'P' { true }
282-
'y' { true }
283-
't' { true }
284-
'T' { false }
285-
'm' { false }
286-
'n' { false }
287-
'v' { true }
288-
'i' { true }
289-
};
325+
alt fam_ch as char {
326+
'c' | 'T' | 'm' | 'n' { false }
327+
'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' { true }
328+
}
290329
}
291330

292331
fn family_names_type(fam_ch: u8) -> bool {
293-
alt fam_ch as char { 'y' | 't' { true } _ { false } }
332+
alt fam_ch as char { 'y' | 't' | 'I' { true } _ { false } }
294333
}
295334

296335
fn read_path(d: ebml::doc) -> {path: str, pos: uint} {
@@ -321,6 +360,8 @@ fn item_family_to_str(fam: u8) -> str {
321360
'm' { ret "mod"; }
322361
'n' { ret "native mod"; }
323362
'v' { ret "tag"; }
363+
'i' { ret "impl"; }
364+
'I' { ret "iface"; }
324365
}
325366
}
326367

0 commit comments

Comments
 (0)