Skip to content

Commit 6482253

Browse files
author
Ariel Ben-Yehuda
committed
remove struct_fields & enum_variants from the tcx
1 parent eca94c1 commit 6482253

File tree

2 files changed

+12
-40
lines changed

2 files changed

+12
-40
lines changed

src/librustc/middle/ty.rs

-4
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,11 @@ pub struct ctxt<'tcx> {
872872
pub rcache: RefCell<FnvHashMap<CReaderCacheKey, Ty<'tcx>>>,
873873
pub tc_cache: RefCell<FnvHashMap<Ty<'tcx>, TypeContents>>,
874874
pub ast_ty_to_ty_cache: RefCell<NodeMap<Ty<'tcx>>>,
875-
pub enum_var_cache: RefCell<DefIdMap<Rc<Vec<Rc<VariantInfo<'tcx>>>>>>,
876875
pub ty_param_defs: RefCell<NodeMap<TypeParameterDef<'tcx>>>,
877876
pub normalized_cache: RefCell<FnvHashMap<Ty<'tcx>, Ty<'tcx>>>,
878877
pub lang_items: middle::lang_items::LanguageItems,
879878
/// A mapping of fake provided method def_ids to the default implementation
880879
pub provided_method_sources: RefCell<DefIdMap<ast::DefId>>,
881-
pub struct_fields: RefCell<DefIdMap<Rc<Vec<FieldTy>>>>,
882880

883881
/// Maps from def-id of a type or region parameter to its
884882
/// (inferred) variance.
@@ -3817,15 +3815,13 @@ impl<'tcx> ctxt<'tcx> {
38173815
rcache: RefCell::new(FnvHashMap()),
38183816
tc_cache: RefCell::new(FnvHashMap()),
38193817
ast_ty_to_ty_cache: RefCell::new(NodeMap()),
3820-
enum_var_cache: RefCell::new(DefIdMap()),
38213818
impl_or_trait_items: RefCell::new(DefIdMap()),
38223819
trait_item_def_ids: RefCell::new(DefIdMap()),
38233820
trait_items_cache: RefCell::new(DefIdMap()),
38243821
ty_param_defs: RefCell::new(NodeMap()),
38253822
normalized_cache: RefCell::new(FnvHashMap()),
38263823
lang_items: lang_items,
38273824
provided_method_sources: RefCell::new(DefIdMap()),
3828-
struct_fields: RefCell::new(DefIdMap()),
38293825
destructor_for_type: RefCell::new(DefIdMap()),
38303826
destructors: RefCell::new(DefIdSet()),
38313827
inherent_impls: RefCell::new(DefIdMap()),

src/librustc_typeck/collect.rs

+12-36
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,7 @@ fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
620620
struct_generics: &ty::Generics<'tcx>,
621621
struct_predicates: &ty::GenericPredicates<'tcx>,
622622
v: &ast::StructField,
623-
ty_f: &'tcx ty::FieldDef_<'tcx, 'tcx>,
624-
origin: ast::DefId)
625-
-> ty::FieldTy
623+
ty_f: &'tcx ty::FieldDef_<'tcx, 'tcx>)
626624
{
627625
let tt = ccx.icx(struct_predicates).to_ty(&ExplicitRscope, &*v.node.ty);
628626
ty_f.fulfill_ty(tt);
@@ -636,25 +634,6 @@ fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
636634
});
637635
ccx.tcx.predicates.borrow_mut().insert(local_def(v.node.id),
638636
struct_predicates.clone());
639-
640-
match v.node.kind {
641-
ast::NamedField(ident, visibility) => {
642-
ty::FieldTy {
643-
name: ident.name,
644-
id: local_def(v.node.id),
645-
vis: visibility,
646-
origin: origin,
647-
}
648-
}
649-
ast::UnnamedField(visibility) => {
650-
ty::FieldTy {
651-
name: special_idents::unnamed_field.name,
652-
id: local_def(v.node.id),
653-
vis: visibility,
654-
origin: origin,
655-
}
656-
}
657-
}
658637
}
659638

660639
fn convert_associated_const<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
@@ -1018,7 +997,11 @@ fn convert_item(ccx: &CrateCtxt, it: &ast::Item) {
1018997
write_ty_to_tcx(tcx, it.id, scheme.ty);
1019998

1020999
let variant = tcx.lookup_adt_def(local_def(it.id)).struct_variant();
1021-
convert_struct_variant_types(ccx, &struct_def, variant, &scheme, &predicates);
1000+
1001+
for (f, ty_f) in struct_def.fields.iter().zip(variant.fields.iter()) {
1002+
convert_field(ccx, &scheme.generics, &predicates, f, ty_f)
1003+
}
1004+
10221005
if let Some(ctor_id) = struct_def.ctor_id {
10231006
convert_variant_ctor(tcx, ctor_id, variant, scheme, predicates);
10241007
}
@@ -1065,17 +1048,6 @@ fn convert_variant_ctor<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
10651048
});
10661049
}
10671050

1068-
fn convert_struct_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
1069-
def: &ast::StructDef,
1070-
variant: &'tcx ty::VariantDef_<'tcx, 'tcx>,
1071-
scheme: &ty::TypeScheme<'tcx>,
1072-
predicates: &ty::GenericPredicates<'tcx>) {
1073-
let field_tys = def.fields.iter().zip(variant.fields.iter()).map(|(f, ty_f)| {
1074-
convert_field(ccx, &scheme.generics, &predicates, f, ty_f, variant.did)
1075-
}).collect();
1076-
ccx.tcx.struct_fields.borrow_mut().insert(variant.did, Rc::new(field_tys));
1077-
}
1078-
10791051
fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
10801052
def: &'tcx ty::ADTDef_<'tcx, 'tcx>,
10811053
scheme: ty::TypeScheme<'tcx>,
@@ -1084,7 +1056,7 @@ fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
10841056
let tcx = ccx.tcx;
10851057
let icx = ccx.icx(&predicates);
10861058

1087-
// Create a set of parameter types shared among all the variants.
1059+
// fill the field types
10881060
for (variant, ty_variant) in variants.iter().zip(def.variants.iter()) {
10891061
match variant.node.kind {
10901062
ast::TupleVariantKind(ref args) => {
@@ -1096,10 +1068,14 @@ fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
10961068
}
10971069

10981070
ast::StructVariantKind(ref struct_def) => {
1099-
convert_struct_variant_types(ccx, &struct_def, ty_variant, &scheme, &predicates);
1071+
for (f, ty_f) in struct_def.fields.iter().zip(ty_variant.fields.iter()) {
1072+
convert_field(ccx, &scheme.generics, &predicates, f, ty_f)
1073+
}
11001074
}
11011075
};
11021076

1077+
// Convert the ctor, if any. This also registers the variant as
1078+
// an item.
11031079
convert_variant_ctor(
11041080
tcx,
11051081
variant.node.id,

0 commit comments

Comments
 (0)