Skip to content

Commit

Permalink
Auto merge of #38053 - eddyb:lazy-9, r=nikomatsakis
Browse files Browse the repository at this point in the history
[9/n] rustc: move type information out of AdtDef and TraitDef.

_This is part of a series ([prev](rust-lang/rust#37688) | [next]()) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well.
If any motivation is unclear, please ask for additional PR description clarifications or code comments._

<hr>

Both `AdtDef` and `TraitDef` contained type information (field types, generics and predicates) which was required to create them, preventing their use before that type information exists, or in the case of field types, *mutation* was required, leading to a variance-magicking implementation of `ivar`s.

This PR takes that information out and the resulting cleaner setup could even eventually end up merged with HIR, because, just like `AssociatedItem` before it, there's no dependency on types anymore.
(With one exception, variant discriminants should probably be moved into their own map later.)
  • Loading branch information
bors committed Dec 2, 2016
2 parents 20b37f7 + c30f149 commit e7b44d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,13 @@ pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) {
}

pub fn build_external_trait(cx: &DocContext, did: DefId) -> clean::Trait {
let def = cx.tcx.lookup_trait_def(did);
let trait_items = cx.tcx.associated_items(did).map(|item| item.clean(cx)).collect();
let predicates = cx.tcx.item_predicates(did);
let generics = (def.generics, &predicates).clean(cx);
let generics = (cx.tcx.item_generics(did), &predicates).clean(cx);
let generics = filter_non_trait_generics(did, generics);
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
clean::Trait {
unsafety: def.unsafety,
unsafety: cx.tcx.lookup_trait_def(did).unsafety,
generics: generics,
items: trait_items,
bounds: supertrait_bounds,
Expand Down
13 changes: 6 additions & 7 deletions clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,9 +1395,8 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
// are actually located on the trait/impl itself, so we need to load
// all of the generics from there and then look for bounds that are
// applied to this associated type in question.
let def = cx.tcx.lookup_trait_def(did);
let predicates = cx.tcx.item_predicates(did);
let generics = (def.generics, &predicates).clean(cx);
let generics = (cx.tcx.item_generics(did), &predicates).clean(cx);
generics.where_predicates.iter().filter_map(|pred| {
let (name, self_type, trait_, bounds) = match *pred {
WherePredicate::BoundPredicate {
Expand Down Expand Up @@ -1927,7 +1926,7 @@ impl Clean<Item> for hir::StructField {
}
}

impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
impl<'tcx> Clean<Item> for ty::FieldDef {
fn clean(&self, cx: &DocContext) -> Item {
Item {
name: Some(self.name).clean(cx),
Expand All @@ -1937,7 +1936,7 @@ impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
stability: get_stability(cx, self.did),
deprecation: get_deprecation(cx, self.did),
def_id: self.did,
inner: StructFieldItem(self.unsubst_ty().clean(cx)),
inner: StructFieldItem(cx.tcx.item_type(self.did).clean(cx)),
}
}
}
Expand Down Expand Up @@ -2084,13 +2083,13 @@ impl Clean<Item> for doctree::Variant {
}
}

impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
impl<'tcx> Clean<Item> for ty::VariantDef {
fn clean(&self, cx: &DocContext) -> Item {
let kind = match self.ctor_kind {
CtorKind::Const => VariantKind::CLike,
CtorKind::Fn => {
VariantKind::Tuple(
self.fields.iter().map(|f| f.unsubst_ty().clean(cx)).collect()
self.fields.iter().map(|f| cx.tcx.item_type(f.did).clean(cx)).collect()
)
}
CtorKind::Fictive => {
Expand All @@ -2106,7 +2105,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
def_id: field.did,
stability: get_stability(cx, field.did),
deprecation: get_deprecation(cx, field.did),
inner: StructFieldItem(field.unsubst_ty().clean(cx))
inner: StructFieldItem(cx.tcx.item_type(field.did).clean(cx))
}
}).collect()
})
Expand Down

0 comments on commit e7b44d8

Please sign in to comment.