Skip to content

Commit

Permalink
Rollup merge of #37688 - eddyb:lazy-8, r=petrochenkov
Browse files Browse the repository at this point in the history
[8/n] rustc: clean up lookup_item_type and remove TypeScheme.

_This is part of a series ([prev](rust-lang/rust#37676) | [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>

* `tcx.tcache` -> `tcx.item_types`
* `TypeScheme` (grouping `Ty` and `ty::Generics`) is removed
* `tcx.item_types` entries no longer duplicated in `tcx.tables.node_types`
* `tcx.lookup_item_type(def_id).ty` -> `tcx.item_type(def_id)`
* `tcx.lookup_item_type(def_id).generics` -> `tcx.item_generics(def_id)`
* `tcx.lookup_generics(def_id)` -> `tcx.item_generics(def_id)`
* `tcx.lookup_{super_,}predicates(def_id)` -> `tcx.item_{super_,}predicates(def_id)`
  • Loading branch information
eddyb committed Nov 12, 2016
2 parents ecbaf3b + 985fe22 commit 84ffdeb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
48 changes: 21 additions & 27 deletions clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn build_external_trait<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tc
did: DefId) -> clean::Trait {
let def = tcx.lookup_trait_def(did);
let trait_items = tcx.associated_items(did).map(|item| item.clean(cx)).collect();
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
let generics = (def.generics, &predicates).clean(cx);
let generics = filter_non_trait_generics(did, generics);
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
Expand All @@ -178,8 +178,8 @@ pub fn build_external_trait<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tc

fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Function {
let t = tcx.lookup_item_type(did);
let (decl, style, abi) = match t.ty.sty {
let ty = tcx.item_type(did);
let (decl, style, abi) = match ty.sty {
ty::TyFnDef(.., ref f) => ((did, &f.sig).clean(cx), f.unsafety, f.abi),
_ => panic!("bad function"),
};
Expand All @@ -190,10 +190,10 @@ fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx
hir::Constness::NotConst
};

let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
clean::Function {
decl: decl,
generics: (t.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
unsafety: style,
constness: constness,
abi: abi,
Expand All @@ -202,20 +202,18 @@ fn build_external_function<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx

fn build_enum<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Enum {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);

clean::Enum {
generics: (t.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
variants_stripped: false,
variants: tcx.lookup_adt_def(did).variants.clean(cx),
}
}

fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Struct {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
let variant = tcx.lookup_adt_def(did).struct_variant();

clean::Struct {
Expand All @@ -224,34 +222,32 @@ fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
CtorKind::Fn => doctree::Tuple,
CtorKind::Const => doctree::Unit,
},
generics: (t.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
fields: variant.fields.clean(cx),
fields_stripped: false,
}
}

fn build_union<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Union {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
let variant = tcx.lookup_adt_def(did).struct_variant();

clean::Union {
struct_type: doctree::Plain,
generics: (t.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
fields: variant.fields.clean(cx),
fields_stripped: false,
}
}

fn build_type_alias<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId) -> clean::Typedef {
let t = tcx.lookup_item_type(did);
let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);

clean::Typedef {
type_: t.ty.clean(cx),
generics: (t.generics, &predicates).clean(cx),
type_: tcx.item_type(did).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
}
}

Expand Down Expand Up @@ -354,8 +350,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
});
}

let ty = tcx.lookup_item_type(did);
let for_ = ty.ty.clean(cx);
let for_ = tcx.item_type(did).clean(cx);

// Only inline impl if the implementing type is
// reachable in rustdoc generated documentation
Expand All @@ -365,11 +360,10 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
}
}

let predicates = tcx.lookup_predicates(did);
let predicates = tcx.item_predicates(did);
let trait_items = tcx.associated_items(did).filter_map(|item| {
match item.kind {
ty::AssociatedKind::Const => {
let type_scheme = tcx.lookup_item_type(item.def_id);
let default = if item.has_value {
Some(pprust::expr_to_string(
lookup_const_by_id(tcx, item.def_id, None).unwrap().0))
Expand All @@ -379,7 +373,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
Some(clean::Item {
name: Some(item.name.clean(cx)),
inner: clean::AssociatedConstItem(
type_scheme.ty.clean(cx),
tcx.item_type(item.def_id).clean(cx),
default,
),
source: clean::Span::empty(),
Expand Down Expand Up @@ -419,7 +413,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
}
ty::AssociatedKind::Type => {
let typedef = clean::Typedef {
type_: tcx.lookup_item_type(item.def_id).ty.clean(cx),
type_: tcx.item_type(item.def_id).clean(cx),
generics: clean::Generics {
lifetimes: vec![],
type_params: vec![],
Expand Down Expand Up @@ -463,7 +457,7 @@ pub fn build_impl<'a, 'tcx>(cx: &DocContext,
provided_trait_methods: provided,
trait_: trait_,
for_: for_,
generics: (ty.generics, &predicates).clean(cx),
generics: (tcx.item_generics(did), &predicates).clean(cx),
items: trait_items,
polarity: Some(polarity.clean(cx)),
}),
Expand Down Expand Up @@ -514,7 +508,7 @@ fn build_const<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
debug!("got snippet {}", sn);

clean::Constant {
type_: ty.map(|t| t.clean(cx)).unwrap_or_else(|| tcx.lookup_item_type(did).ty.clean(cx)),
type_: ty.map(|t| t.clean(cx)).unwrap_or_else(|| tcx.item_type(did).clean(cx)),
expr: sn
}
}
Expand All @@ -523,7 +517,7 @@ fn build_static<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId,
mutable: bool) -> clean::Static {
clean::Static {
type_: tcx.lookup_item_type(did).ty.clean(cx),
type_: tcx.item_type(did).clean(cx),
mutability: if mutable {clean::Mutable} else {clean::Immutable},
expr: "\n\n\n".to_string(), // trigger the "[definition]" links
}
Expand Down
16 changes: 8 additions & 8 deletions clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,13 +1342,13 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
fn clean(&self, cx: &DocContext) -> Item {
let inner = match self.kind {
ty::AssociatedKind::Const => {
let ty = cx.tcx().lookup_item_type(self.def_id).ty;
let ty = cx.tcx().item_type(self.def_id);
AssociatedConstItem(ty.clean(cx), None)
}
ty::AssociatedKind::Method => {
let generics = (cx.tcx().lookup_generics(self.def_id),
&cx.tcx().lookup_predicates(self.def_id)).clean(cx);
let fty = match cx.tcx().lookup_item_type(self.def_id).ty.sty {
let generics = (cx.tcx().item_generics(self.def_id),
&cx.tcx().item_predicates(self.def_id)).clean(cx);
let fty = match cx.tcx().item_type(self.def_id).sty {
ty::TyFnDef(_, _, f) => f,
_ => unreachable!()
};
Expand All @@ -1357,7 +1357,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
if self.method_has_self_argument {
let self_ty = match self.container {
ty::ImplContainer(def_id) => {
cx.tcx().lookup_item_type(def_id).ty
cx.tcx().item_type(def_id)
}
ty::TraitContainer(_) => cx.tcx().mk_self_type()
};
Expand Down Expand Up @@ -1405,7 +1405,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
// 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().lookup_predicates(did);
let predicates = cx.tcx().item_predicates(did);
let generics = (def.generics, &predicates).clean(cx);
generics.where_predicates.iter().filter_map(|pred| {
let (name, self_type, trait_, bounds) = match *pred {
Expand Down Expand Up @@ -1441,7 +1441,7 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
}

let ty = if self.has_value {
Some(cx.tcx().lookup_item_type(self.def_id).ty)
Some(cx.tcx().item_type(self.def_id))
} else {
None
};
Expand Down Expand Up @@ -1901,7 +1901,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
ty::TyAnon(def_id, substs) => {
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// by looking up the projections associated with the def_id.
let item_predicates = cx.tcx().lookup_predicates(def_id);
let item_predicates = cx.tcx().item_predicates(def_id);
let substs = cx.tcx().lift(&substs).unwrap();
let bounds = item_predicates.instantiate(cx.tcx(), substs);
ImplTrait(bounds.predicates.into_iter().filter_map(|predicate| {
Expand Down
2 changes: 1 addition & 1 deletion clean/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext, child: DefId,
if child == trait_ {
return true
}
let predicates = cx.tcx().lookup_super_predicates(child).predicates;
let predicates = cx.tcx().item_super_predicates(child).predicates;
predicates.iter().filter_map(|pred| {
if let ty::Predicate::Trait(ref pred) = *pred {
if pred.0.trait_ref.self_ty().is_self() {
Expand Down

0 comments on commit 84ffdeb

Please sign in to comment.