Skip to content

Commit 25ded9a

Browse files
committed
---
yaml --- r: 6951 b: refs/heads/master c: 38e796b h: refs/heads/master i: 6949: cfe5be2 6947: bfd50bd 6943: 459982d v: v3
1 parent 4dcf95c commit 25ded9a

23 files changed

+294
-391
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 9236fdf39f2cf38b9642768214c39ea1c9543628
2+
refs/heads/master: 38e796b943bddcbc3f4dfb664632b778451751f2

trunk/src/comp/metadata/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const tag_items_data_item: uint = 0x09u;
2222

2323
const tag_items_data_item_family: uint = 0x0au;
2424

25-
const tag_items_data_item_ty_param_bounds: uint = 0x0bu;
25+
const tag_items_data_item_ty_param_kinds: uint = 0x0bu;
2626

2727
const tag_items_data_item_type: uint = 0x0cu;
2828

trunk/src/comp/metadata/csearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn get_impl_methods(cstore: cstore::cstore, def: ast::def_id)
8686
decoder::lookup_impl_methods(cdata, def.node, def.crate)
8787
}
8888

89-
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
89+
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_kinds_and_ty {
9090
let cstore = tcx.sess.get_cstore();
9191
let cnum = def.crate;
9292
let cdata = cstore::get_crate_data(cstore, cnum).data;

trunk/src/comp/metadata/decoder.rs

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export get_symbol;
1414
export get_tag_variants;
1515
export get_type;
1616
export get_type_param_count;
17+
export get_type_param_kinds;
1718
export lookup_def;
1819
export lookup_item_name;
1920
export resolve_path;
@@ -89,22 +90,21 @@ fn variant_tag_id(d: ebml::doc) -> ast::def_id {
8990
ret parse_def_id(ebml::doc_data(tagdoc));
9091
}
9192

92-
fn parse_external_def_id(this_cnum: ast::crate_num,
93-
extres: external_resolver, s: str) ->
94-
ast::def_id {
95-
let buf = str::bytes(s);
96-
let external_def_id = parse_def_id(buf);
97-
98-
99-
// This item was defined in the crate we're searching if it's has the
100-
// local crate number, otherwise we need to search a different crate
101-
if external_def_id.crate == ast::local_crate {
102-
ret {crate: this_cnum, node: external_def_id.node};
103-
} else { ret extres(external_def_id); }
104-
}
105-
10693
fn item_type(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
10794
extres: external_resolver) -> ty::t {
95+
fn parse_external_def_id(this_cnum: ast::crate_num,
96+
extres: external_resolver, s: str) ->
97+
ast::def_id {
98+
let buf = str::bytes(s);
99+
let external_def_id = parse_def_id(buf);
100+
101+
102+
// This item was defined in the crate we're searching if it's has the
103+
// local crate number, otherwise we need to search a different crate
104+
if external_def_id.crate == ast::local_crate {
105+
ret {crate: this_cnum, node: external_def_id.node};
106+
} else { ret extres(external_def_id); }
107+
}
108108
let tp = ebml::get_doc(item, tag_items_data_item_type);
109109
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
110110
let t = parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
@@ -115,24 +115,32 @@ fn item_type(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
115115
t
116116
}
117117

118-
fn item_ty_param_bounds(item: ebml::doc, this_cnum: ast::crate_num,
119-
tcx: ty::ctxt, extres: external_resolver)
120-
-> [@[ty::param_bound]] {
121-
let bounds = [];
122-
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
123-
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)];
126-
}
127-
bounds
118+
fn item_ty_param_kinds(item: ebml::doc) -> [ast::kind] {
119+
let ks: [ast::kind] = [];
120+
let tp = tag_items_data_item_ty_param_kinds;
121+
ebml::tagged_docs(item, tp) {|p|
122+
let dat: [u8] = ebml::doc_data(p);
123+
let vi = ebml::vint_at(dat, 0u);
124+
let i = 0u;
125+
while i < vi.val {
126+
let k =
127+
alt dat[vi.next + i] as char {
128+
's' { ast::kind_sendable }
129+
'c' { ast::kind_copyable }
130+
'a' { ast::kind_noncopyable }
131+
};
132+
ks += [k];
133+
i += 1u;
134+
}
135+
};
136+
ret ks;
128137
}
129138

130139
fn item_ty_param_count(item: ebml::doc) -> uint {
131140
let n = 0u;
132-
ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds) {|p|
133-
for byte in ebml::doc_data(p) {
134-
if byte as char == '.' { n += 1u; }
135-
}
141+
let tp = tag_items_data_item_ty_param_kinds;
142+
ebml::tagged_docs(item, tp) {|p|
143+
n += ebml::vint_at(ebml::doc_data(p), 0u).val;
136144
}
137145
n
138146
}
@@ -205,21 +213,28 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
205213
}
206214

207215
fn get_type(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
208-
extres: external_resolver) -> ty::ty_param_bounds_and_ty {
216+
extres: external_resolver) -> ty::ty_param_kinds_and_ty {
209217
let this_cnum = def.crate;
210218
let node_id = def.node;
211219
let item = lookup_item(node_id, data);
212220
let t = item_type(item, this_cnum, tcx, extres);
213-
let tp_bounds = if family_has_type_params(item_family(item)) {
214-
item_ty_param_bounds(item, this_cnum, tcx, extres)
215-
} else { [] };
216-
ret {bounds: tp_bounds, ty: t};
221+
let tp_kinds: [ast::kind];
222+
let fam_ch = item_family(item);
223+
let has_ty_params = family_has_type_params(fam_ch);
224+
if has_ty_params {
225+
tp_kinds = item_ty_param_kinds(item);
226+
} else { tp_kinds = []; }
227+
ret {kinds: tp_kinds, ty: t};
217228
}
218229

219230
fn get_type_param_count(data: @[u8], id: ast::node_id) -> uint {
220231
item_ty_param_count(lookup_item(id, data))
221232
}
222233

234+
fn get_type_param_kinds(data: @[u8], id: ast::node_id) -> [ast::kind] {
235+
ret item_ty_param_kinds(lookup_item(id, data));
236+
}
237+
223238
fn get_symbol(data: @[u8], id: ast::node_id) -> str {
224239
ret item_symbol(lookup_item(id, data));
225240
}

trunk/src/comp/metadata/encoder.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,18 @@ fn encode_family(ebml_w: ebml::writer, c: u8) {
183183

184184
fn def_to_str(did: def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; }
185185

186-
fn encode_type_param_bounds(ebml_w: ebml::writer, ecx: @encode_ctxt,
187-
params: [ty_param]) {
188-
let ty_str_ctxt = @{ds: def_to_str,
189-
tcx: ecx.ccx.tcx,
190-
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
191-
for param in params {
192-
ebml::start_tag(ebml_w, tag_items_data_item_ty_param_bounds);
193-
let bs = ecx.ccx.tcx.ty_param_bounds.get(local_def(param.id));
194-
tyencode::enc_bounds(io::new_writer(ebml_w.writer), ty_str_ctxt, bs);
195-
ebml::end_tag(ebml_w);
186+
fn encode_type_param_kinds(ebml_w: ebml::writer, tps: [ty_param]) {
187+
ebml::start_tag(ebml_w, tag_items_data_item_ty_param_kinds);
188+
ebml::write_vint(ebml_w.writer, vec::len::<ty_param>(tps));
189+
for tp: ty_param in tps {
190+
let c = alt ast_util::ty_param_kind(tp) {
191+
kind_sendable. { 's' }
192+
kind_copyable. { 'c' }
193+
kind_noncopyable. { 'a' }
194+
};
195+
ebml_w.writer.write([c as u8]);
196196
}
197+
ebml::end_tag(ebml_w);
197198
}
198199

199200
fn encode_variant_id(ebml_w: ebml::writer, vid: def_id) {
@@ -204,8 +205,9 @@ fn encode_variant_id(ebml_w: ebml::writer, vid: def_id) {
204205

205206
fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
206207
ebml::start_tag(ebml_w, tag_items_data_item_type);
208+
let f = def_to_str;
207209
let ty_str_ctxt =
208-
@{ds: def_to_str,
210+
@{ds: f,
209211
tcx: ecx.ccx.tcx,
210212
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
211213
tyencode::enc_ty(io::new_writer(ebml_w.writer), ty_str_ctxt, typ);
@@ -245,7 +247,7 @@ fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
245247
encode_symbol(ecx, ebml_w, variant.node.id);
246248
}
247249
encode_discriminant(ecx, ebml_w, variant.node.id);
248-
encode_type_param_bounds(ebml_w, ecx, ty_params);
250+
encode_type_param_kinds(ebml_w, ty_params);
249251
ebml::end_tag(ebml_w);
250252
}
251253
}
@@ -291,7 +293,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
291293
pure_fn. { 'p' }
292294
impure_fn. { 'f' }
293295
} as u8);
294-
encode_type_param_bounds(ebml_w, ecx, tps);
296+
encode_type_param_kinds(ebml_w, tps);
295297
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
296298
encode_symbol(ecx, ebml_w, item.id);
297299
ebml::end_tag(ebml_w);
@@ -310,7 +312,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
310312
ebml::start_tag(ebml_w, tag_items_data_item);
311313
encode_def_id(ebml_w, local_def(item.id));
312314
encode_family(ebml_w, 'y' as u8);
313-
encode_type_param_bounds(ebml_w, ecx, tps);
315+
encode_type_param_kinds(ebml_w, tps);
314316
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
315317
encode_name(ebml_w, item.ident);
316318
ebml::end_tag(ebml_w);
@@ -319,7 +321,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
319321
ebml::start_tag(ebml_w, tag_items_data_item);
320322
encode_def_id(ebml_w, local_def(item.id));
321323
encode_family(ebml_w, 't' as u8);
322-
encode_type_param_bounds(ebml_w, ecx, tps);
324+
encode_type_param_kinds(ebml_w, tps);
323325
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
324326
encode_name(ebml_w, item.ident);
325327
for v: variant in variants {
@@ -334,7 +336,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
334336
ebml::start_tag(ebml_w, tag_items_data_item);
335337
encode_def_id(ebml_w, local_def(ctor_id));
336338
encode_family(ebml_w, 'y' as u8);
337-
encode_type_param_bounds(ebml_w, ecx, tps);
339+
encode_type_param_kinds(ebml_w, tps);
338340
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
339341
encode_name(ebml_w, item.ident);
340342
encode_symbol(ecx, ebml_w, item.id);
@@ -344,7 +346,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
344346
ebml::start_tag(ebml_w, tag_items_data_item);
345347
encode_def_id(ebml_w, local_def(ctor_id));
346348
encode_family(ebml_w, 'f' as u8);
347-
encode_type_param_bounds(ebml_w, ecx, tps);
349+
encode_type_param_kinds(ebml_w, tps);
348350
encode_type(ecx, ebml_w, fn_ty);
349351
encode_symbol(ecx, ebml_w, ctor_id);
350352
ebml::end_tag(ebml_w);
@@ -355,7 +357,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
355357
ebml::start_tag(ebml_w, tag_items_data_item);
356358
encode_def_id(ebml_w, local_def(item.id));
357359
encode_family(ebml_w, 'y' as u8);
358-
encode_type_param_bounds(ebml_w, ecx, tps);
360+
encode_type_param_kinds(ebml_w, tps);
359361
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
360362
encode_name(ebml_w, item.ident);
361363
ebml::end_tag(ebml_w);
@@ -364,7 +366,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
364366
ebml::start_tag(ebml_w, tag_items_data_item);
365367
encode_def_id(ebml_w, local_def(ctor_id));
366368
encode_family(ebml_w, 'f' as u8);
367-
encode_type_param_bounds(ebml_w, ecx, tps);
369+
encode_type_param_kinds(ebml_w, tps);
368370
encode_type(ecx, ebml_w, fn_ty);
369371
encode_symbol(ecx, ebml_w, ctor_id);
370372
ebml::end_tag(ebml_w);
@@ -373,7 +375,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
373375
ebml::start_tag(ebml_w, tag_items_data_item);
374376
encode_def_id(ebml_w, local_def(item.id));
375377
encode_family(ebml_w, 'i' as u8);
376-
encode_type_param_bounds(ebml_w, ecx, tps);
378+
encode_type_param_kinds(ebml_w, tps);
377379
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
378380
encode_name(ebml_w, item.ident);
379381
for m in methods {
@@ -388,7 +390,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
388390
ebml::start_tag(ebml_w, tag_items_data_item);
389391
encode_def_id(ebml_w, local_def(m.id));
390392
encode_family(ebml_w, 'f' as u8);
391-
encode_type_param_bounds(ebml_w, ecx, tps + m.tps);
393+
encode_type_param_kinds(ebml_w, tps + m.tps);
392394
encode_type(ecx, ebml_w,
393395
node_id_to_monotype(ecx.ccx.tcx, m.id));
394396
encode_name(ebml_w, m.ident);
@@ -419,7 +421,7 @@ fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
419421
} as u8;
420422
encode_def_id(ebml_w, local_def(nitem.id));
421423
encode_family(ebml_w, letter);
422-
encode_type_param_bounds(ebml_w, ecx, tps);
424+
encode_type_param_kinds(ebml_w, tps);
423425
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, nitem.id));
424426
encode_symbol(ecx, ebml_w, nitem.id);
425427
}

trunk/src/comp/metadata/tydecode.rs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import middle::ty;
1010

1111
export parse_def_id;
1212
export parse_ty_data;
13-
export parse_bounds_data;
1413

1514
// Compact string representation for ty::t values. API ty_str &
1615
// parse_from_str. Extra parameters are for converting to/from def_ids in the
@@ -22,9 +21,7 @@ type str_def = fn@(str) -> ast::def_id;
2221
type pstate =
2322
{data: @[u8], crate: int, mutable pos: uint, len: uint, tcx: ty::ctxt};
2423

25-
fn peek(st: @pstate) -> u8 {
26-
if st.pos < vec::len(*st.data) { st.data[st.pos] } else { 0u8 }
27-
}
24+
fn peek(st: @pstate) -> u8 { ret st.data[st.pos]; }
2825

2926
fn next(st: @pstate) -> u8 {
3027
let ch = st.data[st.pos];
@@ -51,7 +48,8 @@ fn parse_ty_data(data: @[u8], crate_num: int, pos: uint, len: uint,
5148
sd: str_def, tcx: ty::ctxt) -> ty::t {
5249
let st =
5350
@{data: data, crate: crate_num, mutable pos: pos, len: len, tcx: tcx};
54-
parse_ty(st, sd)
51+
let result = parse_ty(st, sd);
52+
ret result;
5553
}
5654

5755
fn parse_ret_ty(st: @pstate, sd: str_def) -> (ast::ret_style, ty::t) {
@@ -203,8 +201,18 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
203201
ret ty::mk_tag(st.tcx, def, params);
204202
}
205203
'p' {
206-
let bounds = parse_bounds(st, sd);
207-
ret ty::mk_param(st.tcx, parse_int(st) as uint, bounds);
204+
let k =
205+
alt next(st) as char {
206+
's' { kind_sendable }
207+
'c' { kind_copyable }
208+
'a' { kind_noncopyable }
209+
c {
210+
#error("unexpected char in encoded type param: ");
211+
log(error, c);
212+
fail
213+
}
214+
};
215+
ret ty::mk_param(st.tcx, parse_int(st) as uint, k);
208216
}
209217
'@' { ret ty::mk_box(st.tcx, parse_mt(st, sd)); }
210218
'~' { ret ty::mk_uniq(st.tcx, parse_mt(st, sd)); }
@@ -392,26 +400,6 @@ fn parse_def_id(buf: [u8]) -> ast::def_id {
392400
ret {crate: crate_num, node: def_num};
393401
}
394402

395-
fn parse_bounds_data(data: @[u8], crate_num: int, sd: str_def, tcx: ty::ctxt)
396-
-> @[ty::param_bound] {
397-
let st = @{data: data, crate: crate_num, mutable pos: 0u,
398-
len: vec::len(*data), tcx: tcx};
399-
parse_bounds(st, sd)
400-
}
401-
402-
fn parse_bounds(st: @pstate, sd: str_def) -> @[ty::param_bound] {
403-
let bounds = [];
404-
while peek(st) as char == '.' {
405-
next(st);
406-
bounds += [alt next(st) as char {
407-
'S' { ty::bound_send }
408-
'C' { ty::bound_copy }
409-
'I' { ty::bound_iface(parse_ty(st, sd)) }
410-
}];
411-
}
412-
@bounds
413-
}
414-
415403
//
416404
// Local Variables:
417405
// mode: rust

0 commit comments

Comments
 (0)