Skip to content

Commit

Permalink
Rollup merge of #40696 - cramertj:remove-unused-adt-def-code, r=petro…
Browse files Browse the repository at this point in the history
…chenkov

Remove unused adt-def insertion by constructor DefIndex

It looks to me like ADT definitions weren't being looked up by constructor id, and a test run supports my theory.

In any case, I'm not sure it would have worked in its current configuration. If I understand correctly, the `adt_def` map entry from constructor id -> adt def would only be present after a successful call to `queries::adt_def::get` with the proper ADT `DefIndex`. Trying to look up an adt_def by the constructor index prior to a successful lookup by ADT index would fail since `item.kind` would be `EntryKind::Fn` (for the constructor function) and so would trigger the `bug!`.

r? @nikomatsakis
  • Loading branch information
frewsxcv authored Mar 23, 2017
2 parents 39e4a27 + 873248d commit 9307418
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
12 changes: 2 additions & 10 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ impl<'a, 'tcx> CrateMetadata {
EntryKind::Union(_, _) => ty::AdtKind::Union,
_ => bug!("get_adt_def called on a non-ADT {:?}", did),
};
let mut ctor_index = None;
let variants = if let ty::AdtKind::Enum = kind {
item.children
.decode(self)
Expand All @@ -570,8 +569,7 @@ impl<'a, 'tcx> CrateMetadata {
})
.collect()
} else {
let (variant, struct_ctor) = self.get_variant(&item, item_id, tcx);
ctor_index = struct_ctor;
let (variant, _struct_ctor) = self.get_variant(&item, item_id, tcx);
vec![variant]
};
let (kind, repr) = match item.kind {
Expand All @@ -581,13 +579,7 @@ impl<'a, 'tcx> CrateMetadata {
_ => bug!("get_adt_def called on a non-ADT {:?}", did),
};

let adt = tcx.alloc_adt_def(did, kind, variants, repr);
if let Some(ctor_index) = ctor_index {
// Make adt definition available through constructor id as well.
tcx.maps.adt_def.borrow_mut().insert(self.local_def_id(ctor_index), adt);
}

adt
tcx.alloc_adt_def(did, kind, variants, repr)
}

pub fn get_predicates(&self,
Expand Down
6 changes: 0 additions & 6 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,6 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
let item = match tcx.hir.get(node_id) {
NodeItem(item) => item,

// Make adt definition available through constructor id as well.
NodeStructCtor(_) => {
return tcx.lookup_adt_def(tcx.hir.get_parent_did(node_id));
}

_ => bug!()
};

Expand Down

0 comments on commit 9307418

Please sign in to comment.