Skip to content

Commit 40908db

Browse files
Ariel Ben-Yehudaarielb1
authored andcommitted
---
yaml --- r: 223229 b: refs/heads/auto c: 4816e60 h: refs/heads/master i: 223227: e8950ee v: v3
1 parent b65783f commit 40908db

File tree

8 files changed

+505
-184
lines changed

8 files changed

+505
-184
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 213b6d71f502a8568208cf549050a71cc24b1338
11+
refs/heads/auto: 4816e60667596718682ae70f6c34fed03288e07b
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc/metadata/csearch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ pub fn get_trait_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) -> ty::TraitDe
222222
decoder::get_trait_def(&*cdata, def.node, tcx)
223223
}
224224

225-
pub fn get_adt_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) -> &'tcx ty::ADTDef<'tcx> {
225+
pub fn get_adt_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) -> &'tcx ty::ADTDef_<'tcx, 'tcx> {
226226
let cstore = &tcx.sess.cstore;
227227
let cdata = cstore.get_crate_data(def.krate);
228-
decoder::get_adt_def(&*cdata, def.node, tcx)
228+
decoder::get_adt_def(&cstore.intr, &*cdata, def.node, tcx)
229229
}
230230

231231
pub fn get_predicates<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId)

branches/auto/src/librustc/metadata/decoder.rs

Lines changed: 104 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn lookup_item<'a>(item_id: ast::NodeId, data: &'a [u8]) -> rbml::Doc<'a> {
108108
find_item(item_id, items)
109109
}
110110

111-
#[derive(PartialEq)]
111+
#[derive(Debug, PartialEq)]
112112
enum Family {
113113
ImmStatic, // c
114114
MutStatic, // b
@@ -390,12 +390,111 @@ pub fn get_trait_def<'tcx>(cdata: Cmd,
390390
}
391391
}
392392

393-
pub fn get_adt_def<'tcx>(cdata: Cmd,
393+
pub fn get_adt_def<'tcx>(intr: &IdentInterner,
394+
cdata: Cmd,
394395
item_id: ast::NodeId,
395-
tcx: &ty::ctxt<'tcx>) -> &'tcx ty::ADTDef<'tcx>
396+
tcx: &ty::ctxt<'tcx>) -> &'tcx ty::ADTDef_<'tcx, 'tcx>
396397
{
397-
tcx.intern_adt_def(ast::DefId { krate: cdata.cnum, node: item_id },
398-
ty::ADTKind::Enum)
398+
fn get_enum_variants<'tcx>(intr: &IdentInterner,
399+
cdata: Cmd,
400+
doc: rbml::Doc,
401+
tcx: &ty::ctxt<'tcx>) -> Vec<ty::VariantDef_<'tcx, 'tcx>> {
402+
let mut disr_val = 0;
403+
reader::tagged_docs(doc, tag_items_data_item_variant).map(|p| {
404+
let did = translated_def_id(cdata, p);
405+
let item = lookup_item(did.node, cdata.data());
406+
407+
if let Some(disr) = variant_disr_val(item) {
408+
disr_val = disr;
409+
}
410+
let disr = disr_val;
411+
disr_val = disr_val.wrapping_add(1);
412+
413+
ty::VariantDef_ {
414+
did: did,
415+
name: item_name(intr, item),
416+
fields: get_variant_fields(intr, cdata, item, tcx),
417+
disr_val: disr
418+
}
419+
}).collect()
420+
}
421+
fn get_variant_fields<'tcx>(intr: &IdentInterner,
422+
cdata: Cmd,
423+
doc: rbml::Doc,
424+
tcx: &ty::ctxt<'tcx>) -> Vec<ty::FieldDef_<'tcx, 'tcx>> {
425+
reader::tagged_docs(doc, tag_item_field).map(|f| {
426+
let ff = item_family(f);
427+
match ff {
428+
PublicField | InheritedField => {},
429+
_ => tcx.sess.bug(&format!("expected field, found {:?}", ff))
430+
};
431+
ty::FieldDef_::new(item_def_id(f, cdata),
432+
item_name(intr, f),
433+
struct_field_family_to_visibility(ff))
434+
}).chain(reader::tagged_docs(doc, tag_item_unnamed_field).map(|f| {
435+
let ff = item_family(f);
436+
ty::FieldDef_::new(item_def_id(f, cdata),
437+
special_idents::unnamed_field.name,
438+
struct_field_family_to_visibility(ff))
439+
})).collect()
440+
}
441+
fn get_struct_variant<'tcx>(intr: &IdentInterner,
442+
cdata: Cmd,
443+
doc: rbml::Doc,
444+
did: ast::DefId,
445+
tcx: &ty::ctxt<'tcx>) -> ty::VariantDef_<'tcx, 'tcx> {
446+
ty::VariantDef_ {
447+
did: did,
448+
name: item_name(intr, doc),
449+
fields: get_variant_fields(intr, cdata, doc, tcx),
450+
disr_val: 0
451+
}
452+
}
453+
454+
let doc = lookup_item(item_id, cdata.data());
455+
let did = ast::DefId { krate: cdata.cnum, node: item_id };
456+
let (kind, variants) = match item_family(doc) {
457+
Enum => (ty::ADTKind::Enum,
458+
get_enum_variants(intr, cdata, doc, tcx)),
459+
Struct => (ty::ADTKind::Struct,
460+
vec![get_struct_variant(intr, cdata, doc, did, tcx)]),
461+
_ => tcx.sess.bug("get_adt_def called on a non-ADT")
462+
};
463+
464+
let adt = tcx.intern_adt_def(did, kind, variants);
465+
466+
// this needs to be done *after* the variant is interned,
467+
// to support recursive structures
468+
for variant in &adt.variants {
469+
if variant.kind() == ty::VariantKind::Tuple &&
470+
adt.adt_kind() == ty::ADTKind::Enum {
471+
// tuple-like enum variant fields aren't real items - get the types
472+
// from the ctor.
473+
debug!("evaluating the ctor-type of {:?}",
474+
variant.name);
475+
let ctor_ty = get_type(cdata, variant.did.node, tcx).ty;
476+
debug!("evaluating the ctor-type of {:?}.. {:?}",
477+
variant.name,
478+
ctor_ty);
479+
let field_tys = match ctor_ty.sty {
480+
ty::TyBareFn(_, ref f) => &f.sig.skip_binder().inputs,
481+
_ => tcx.sess.bug("tuple-variant ctor is not an ADT")
482+
};
483+
for (field, &ty) in variant.fields.iter().zip(field_tys.iter()) {
484+
field.fulfill_ty(ty);
485+
}
486+
} else {
487+
for field in &variant.fields {
488+
debug!("evaluating the type of {:?}::{:?}", variant.name, field.name);
489+
let ty = get_type(cdata, field.did.node, tcx).ty;
490+
field.fulfill_ty(ty);
491+
debug!("evaluating the type of {:?}::{:?}: {:?}",
492+
variant.name, field.name, ty);
493+
}
494+
}
495+
}
496+
497+
adt
399498
}
400499

401500
pub fn get_predicates<'tcx>(cdata: Cmd,

branches/auto/src/librustc/metadata/encoder.rs

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use syntax::attr::AttrMetaMethods;
4141
use syntax::diagnostic::SpanHandler;
4242
use syntax::parse::token::special_idents;
4343
use syntax::print::pprust;
44-
use syntax::ptr::P;
4544
use syntax::visit::Visitor;
4645
use syntax::visit;
4746
use syntax;
@@ -266,7 +265,7 @@ fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) {
266265
}
267266

268267
fn encode_struct_fields(rbml_w: &mut Encoder,
269-
fields: &[ty::FieldTy],
268+
fields: &[ty::FieldDef],
270269
origin: DefId) {
271270
for f in fields {
272271
if f.name == special_idents::unnamed_field.name {
@@ -276,7 +275,7 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
276275
encode_name(rbml_w, f.name);
277276
}
278277
encode_struct_field_family(rbml_w, f.vis);
279-
encode_def_id(rbml_w, f.id);
278+
encode_def_id(rbml_w, f.did);
280279
rbml_w.wr_tagged_u64(tag_item_field_origin, def_to_u64(origin));
281280
rbml_w.end_tag();
282281
}
@@ -285,57 +284,56 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
285284
fn encode_enum_variant_info(ecx: &EncodeContext,
286285
rbml_w: &mut Encoder,
287286
id: NodeId,
288-
variants: &[P<ast::Variant>],
287+
vis: ast::Visibility,
289288
index: &mut Vec<entry<i64>>) {
290289
debug!("encode_enum_variant_info(id={})", id);
291290

292291
let mut disr_val = 0;
293-
let mut i = 0;
294-
let vi = ecx.tcx.enum_variants(local_def(id));
295-
for variant in variants {
296-
let def_id = local_def(variant.node.id);
292+
let def = ecx.tcx.lookup_adt_def(local_def(id));
293+
for variant in &def.variants {
294+
let vid = variant.did;
295+
assert!(is_local(vid));
297296
index.push(entry {
298-
val: variant.node.id as i64,
297+
val: vid.node as i64,
299298
pos: rbml_w.mark_stable_position(),
300299
});
301300
rbml_w.start_tag(tag_items_data_item);
302-
encode_def_id(rbml_w, def_id);
303-
match variant.node.kind {
304-
ast::TupleVariantKind(_) => encode_family(rbml_w, 'v'),
305-
ast::StructVariantKind(_) => encode_family(rbml_w, 'V')
306-
}
307-
encode_name(rbml_w, variant.node.name.name);
301+
encode_def_id(rbml_w, vid);
302+
encode_family(rbml_w, match variant.kind() {
303+
ty::VariantKind::Unit | ty::VariantKind::Tuple => 'v',
304+
ty::VariantKind::Dict => 'V'
305+
});
306+
encode_name(rbml_w, variant.name);
308307
encode_parent_item(rbml_w, local_def(id));
309-
encode_visibility(rbml_w, variant.node.vis);
310-
encode_attributes(rbml_w, &variant.node.attrs);
311-
encode_repr_attrs(rbml_w, ecx, &variant.node.attrs);
308+
encode_visibility(rbml_w, vis);
309+
310+
let attrs = ecx.tcx.get_attrs(vid);
311+
encode_attributes(rbml_w, &attrs);
312+
encode_repr_attrs(rbml_w, ecx, &attrs);
312313

313-
let stab = stability::lookup(ecx.tcx, ast_util::local_def(variant.node.id));
314+
let stab = stability::lookup(ecx.tcx, vid);
314315
encode_stability(rbml_w, stab);
315316

316-
match variant.node.kind {
317-
ast::TupleVariantKind(_) => {},
318-
ast::StructVariantKind(_) => {
319-
let fields = ecx.tcx.lookup_struct_fields(def_id);
320-
let idx = encode_info_for_struct(ecx,
321-
rbml_w,
322-
&fields[..],
323-
index);
324-
encode_struct_fields(rbml_w, &fields[..], def_id);
325-
encode_index(rbml_w, idx, write_i64);
326-
}
317+
if let ty::VariantKind::Dict = variant.kind() {
318+
let idx = encode_info_for_struct(ecx,
319+
rbml_w,
320+
&variant.fields,
321+
index);
322+
encode_index(rbml_w, idx, write_i64);
327323
}
328-
let specified_disr_val = vi[i].disr_val;
324+
325+
encode_struct_fields(rbml_w, &variant.fields, vid);
326+
327+
let specified_disr_val = variant.disr_val;
329328
if specified_disr_val != disr_val {
330329
encode_disr_val(ecx, rbml_w, specified_disr_val);
331330
disr_val = specified_disr_val;
332331
}
333-
encode_bounds_and_type_for_item(rbml_w, ecx, def_id.local_id());
332+
encode_bounds_and_type_for_item(rbml_w, ecx, vid.node);
334333

335-
ecx.tcx.map.with_path(variant.node.id, |path| encode_path(rbml_w, path));
334+
ecx.tcx.map.with_path(vid.node, |path| encode_path(rbml_w, path));
336335
rbml_w.end_tag();
337336
disr_val = disr_val.wrapping_add(1);
338-
i += 1;
339337
}
340338
}
341339

@@ -630,19 +628,19 @@ fn encode_provided_source(rbml_w: &mut Encoder,
630628
}
631629

632630
/* Returns an index of items in this class */
633-
fn encode_info_for_struct(ecx: &EncodeContext,
634-
rbml_w: &mut Encoder,
635-
fields: &[ty::FieldTy],
636-
global_index: &mut Vec<entry<i64>>)
637-
-> Vec<entry<i64>> {
631+
fn encode_info_for_struct<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
632+
rbml_w: &mut Encoder,
633+
fields: &[ty::FieldDef<'tcx>],
634+
global_index: &mut Vec<entry<i64>>)
635+
-> Vec<entry<i64>> {
638636
/* Each class has its own index, since different classes
639637
may have fields with the same name */
640638
let mut index = Vec::new();
641639
/* We encode both private and public fields -- need to include
642640
private fields to get the offsets right */
643641
for field in fields {
644642
let nm = field.name;
645-
let id = field.id.node;
643+
let id = field.did.node;
646644

647645
let pos = rbml_w.mark_stable_position();
648646
index.push(entry {val: id as i64, pos: pos});
@@ -658,7 +656,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,
658656
encode_bounds_and_type_for_item(rbml_w, ecx, id);
659657
encode_def_id(rbml_w, local_def(id));
660658

661-
let stab = stability::lookup(ecx.tcx, field.id);
659+
let stab = stability::lookup(ecx.tcx, field.did);
662660
encode_stability(rbml_w, stab);
663661

664662
rbml_w.end_tag();
@@ -1150,20 +1148,18 @@ fn encode_info_for_item(ecx: &EncodeContext,
11501148
encode_enum_variant_info(ecx,
11511149
rbml_w,
11521150
item.id,
1153-
&(*enum_definition).variants,
1151+
vis,
11541152
index);
11551153
}
11561154
ast::ItemStruct(ref struct_def, _) => {
1157-
let fields = tcx.lookup_struct_fields(def_id);
1155+
let def = ecx.tcx.lookup_adt_def(def_id);
1156+
let fields = &def.struct_variant().fields;
11581157

11591158
/* First, encode the fields
11601159
These come first because we need to write them to make
11611160
the index, and the index needs to be in the item for the
11621161
class itself */
1163-
let idx = encode_info_for_struct(ecx,
1164-
rbml_w,
1165-
&fields[..],
1166-
index);
1162+
let idx = encode_info_for_struct(ecx, rbml_w, &fields, index);
11671163

11681164
/* Index the class*/
11691165
add_to_index(item, rbml_w, index);
@@ -1185,7 +1181,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
11851181
/* Encode def_ids for each field and method
11861182
for methods, write all the stuff get_trait_method
11871183
needs to know*/
1188-
encode_struct_fields(rbml_w, &fields[..], def_id);
1184+
encode_struct_fields(rbml_w, &fields, def_id);
11891185

11901186
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
11911187

branches/auto/src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
513513
&Variant(vid) =>
514514
(vid, cx.tcx.enum_variant_with_id(cid.did, vid).arg_names.is_some()),
515515
_ =>
516-
(cid.did, !cid.is_tuple_struct(cx.tcx))
516+
(cid.did, !cid.struct_variant().is_tuple_struct())
517517
};
518518
if is_structure {
519519
let fields = cx.tcx.lookup_struct_fields(vid);

0 commit comments

Comments
 (0)