Skip to content

Commit

Permalink
Rollup merge of rust-lang#59789 - eddyb:typeck-reverts, r=nikomatsakis
Browse files Browse the repository at this point in the history
Revert two unapproved changes to rustc_typeck.

There was a breakdown in process (rust-lang#59004 (comment), rust-lang#58894 (comment)) and two changes were made to `rustc_typeck`'s "collect" queries, for rustdoc, that were neither needed *nor* correct.
I'm reverting them here, and will fix up rustdoc *somehow*, if necessary.

cc @rust-lang/compiler How do we ensure this doesn't happen again?

r? @nikomatsakis or @oli-obk
  • Loading branch information
Centril committed Nov 7, 2019
2 parents 7a76fe7 + d594fc2 commit d7f1406
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -95,8 +95,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
generics_of => {
tcx.arena.alloc(cdata.get_generics(def_id.index, tcx.sess))
}
predicates_of => { cdata.get_predicates(def_id.index, tcx) }
predicates_defined_on => { cdata.get_predicates_defined_on(def_id.index, tcx) }
explicit_predicates_of => { cdata.get_explicit_predicates(def_id.index, tcx) }
inferred_outlives_of => { cdata.get_inferred_outlives(def_id.index, tcx) }
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
trait_def => {
tcx.arena.alloc(cdata.get_trait_def(def_id.index, tcx.sess))
Expand Down
12 changes: 7 additions & 5 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -658,20 +658,22 @@ impl<'a, 'tcx> CrateMetadata {
tcx.alloc_adt_def(did, adt_kind, variants, repr)
}

crate fn get_predicates(
crate fn get_explicit_predicates(
&self,
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> {
self.root.per_def.predicates.get(self, item_id).unwrap().decode((self, tcx))
self.root.per_def.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx))
}

crate fn get_predicates_defined_on(
crate fn get_inferred_outlives(
&self,
item_id: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> {
self.root.per_def.predicates_defined_on.get(self, item_id).unwrap().decode((self, tcx))
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
self.root.per_def.inferred_outlives.get(self, item_id).map(|predicates| {
predicates.decode((self, tcx))
}).unwrap_or_default()
}

crate fn get_super_predicates(
Expand Down
64 changes: 32 additions & 32 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -76,8 +76,8 @@ struct PerDefTables<'tcx> {
inherent_impls: PerDefTable<Lazy<[DefIndex]>>,
variances: PerDefTable<Lazy<[ty::Variance]>>,
generics: PerDefTable<Lazy<ty::Generics>>,
predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
predicates_defined_on: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
explicit_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
inferred_outlives: PerDefTable<Lazy<&'tcx [(ty::Predicate<'tcx>, Span)]>>,
super_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,

mir: PerDefTable<Lazy<mir::Body<'tcx>>>,
Expand Down Expand Up @@ -524,8 +524,8 @@ impl<'tcx> EncodeContext<'tcx> {
inherent_impls: self.per_def.inherent_impls.encode(&mut self.opaque),
variances: self.per_def.variances.encode(&mut self.opaque),
generics: self.per_def.generics.encode(&mut self.opaque),
predicates: self.per_def.predicates.encode(&mut self.opaque),
predicates_defined_on: self.per_def.predicates_defined_on.encode(&mut self.opaque),
explicit_predicates: self.per_def.explicit_predicates.encode(&mut self.opaque),
inferred_outlives: self.per_def.inferred_outlives.encode(&mut self.opaque),
super_predicates: self.per_def.super_predicates.encode(&mut self.opaque),

mir: self.per_def.mir.encode(&mut self.opaque),
Expand Down Expand Up @@ -675,7 +675,8 @@ impl EncodeContext<'tcx> {
self.encode_variances_of(def_id);
}
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id);
}
Expand Down Expand Up @@ -718,7 +719,8 @@ impl EncodeContext<'tcx> {
self.encode_variances_of(def_id);
}
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id);
}
Expand Down Expand Up @@ -776,7 +778,8 @@ impl EncodeContext<'tcx> {
self.encode_deprecation(def_id);
self.encode_item_type(def_id);
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
}

fn encode_struct_ctor(&mut self, adt_def_id: DefId, def_id: DefId) {
Expand Down Expand Up @@ -819,7 +822,8 @@ impl EncodeContext<'tcx> {
self.encode_variances_of(def_id);
}
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id);
}
Expand All @@ -829,15 +833,18 @@ impl EncodeContext<'tcx> {
record!(self.per_def.generics[def_id] <- self.tcx.generics_of(def_id));
}

fn encode_predicates(&mut self, def_id: DefId) {
debug!("EncodeContext::encode_predicates({:?})", def_id);
record!(self.per_def.predicates[def_id] <- self.tcx.predicates_of(def_id));
fn encode_explicit_predicates(&mut self, def_id: DefId) {
debug!("EncodeContext::encode_explicit_predicates({:?})", def_id);
record!(self.per_def.explicit_predicates[def_id] <-
self.tcx.explicit_predicates_of(def_id));
}

fn encode_predicates_defined_on(&mut self, def_id: DefId) {
debug!("EncodeContext::encode_predicates_defined_on({:?})", def_id);
record!(self.per_def.predicates_defined_on[def_id] <-
self.tcx.predicates_defined_on(def_id))
fn encode_inferred_outlives(&mut self, def_id: DefId) {
debug!("EncodeContext::encode_inferred_outlives({:?})", def_id);
let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
if !inferred_outlives.is_empty() {
record!(self.per_def.inferred_outlives[def_id] <- inferred_outlives);
}
}

fn encode_super_predicates(&mut self, def_id: DefId) {
Expand Down Expand Up @@ -919,7 +926,8 @@ impl EncodeContext<'tcx> {
self.encode_variances_of(def_id);
}
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id);
}
Expand Down Expand Up @@ -986,7 +994,8 @@ impl EncodeContext<'tcx> {
self.encode_variances_of(def_id);
}
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
let mir = match ast_item.kind {
hir::ImplItemKind::Const(..) => true,
hir::ImplItemKind::Method(ref sig, _) => {
Expand Down Expand Up @@ -1260,22 +1269,11 @@ impl EncodeContext<'tcx> {
hir::ItemKind::Trait(..) |
hir::ItemKind::TraitAlias(..) => {
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
}
_ => {}
}
// The only time that `predicates_defined_on` is used (on
// an external item) is for traits, during chalk lowering,
// so only encode it in that case as an efficiency
// hack. (No reason not to expand it in the future if
// necessary.)
match item.kind {
hir::ItemKind::Trait(..) |
hir::ItemKind::TraitAlias(..) => {
self.encode_predicates_defined_on(def_id);
}
_ => {} // not *wrong* for other kinds of items, but not needed
}
match item.kind {
hir::ItemKind::Trait(..) |
hir::ItemKind::TraitAlias(..) => {
Expand Down Expand Up @@ -1377,7 +1375,8 @@ impl EncodeContext<'tcx> {
record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id));
self.encode_item_type(def_id);
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
self.encode_optimized_mir(def_id);
self.encode_promoted_mir(def_id);
}
Expand Down Expand Up @@ -1588,7 +1587,8 @@ impl EncodeContext<'tcx> {
self.encode_variances_of(def_id);
}
self.encode_generics(def_id);
self.encode_predicates(def_id);
self.encode_explicit_predicates(def_id);
self.encode_inferred_outlives(def_id);
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/librustc_metadata/schema.rs
Expand Up @@ -244,8 +244,13 @@ crate struct LazyPerDefTables<'tcx> {
pub inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
pub variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
pub generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
pub predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
pub predicates_defined_on: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
pub explicit_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
// doesn't handle shorthands in its own (de)serialization impls,
// as it's an `enum` for which we want to derive (de)serialization,
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
// Also, as an optimization, a missing entry indicates an empty `&[]`.
pub inferred_outlives: Lazy!(PerDefTable<Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>),
pub super_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),

pub mir: Lazy!(PerDefTable<Lazy!(mir::Body<'tcx>)>),
Expand Down
70 changes: 13 additions & 57 deletions src/librustc_typeck/collect.rs
Expand Up @@ -1146,10 +1146,6 @@ fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
);
}

fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
checked_type_of(tcx, def_id, true).unwrap()
}

fn infer_placeholder_type(
tcx: TyCtxt<'_>,
def_id: DefId,
Expand Down Expand Up @@ -1193,26 +1189,14 @@ fn infer_placeholder_type(
ty
}

/// Same as [`type_of`] but returns [`Option`] instead of failing.
///
/// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
/// you'd better just call [`type_of`] directly.
pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<'_>> {
fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
use rustc::hir::*;

let hir_id = match tcx.hir().as_local_hir_id(def_id) {
Some(hir_id) => hir_id,
None => {
if !fail {
return None;
}
bug!("invalid node");
}
};
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();

let icx = ItemCtxt::new(tcx, def_id);

Some(match tcx.hir().get(hir_id) {
match tcx.hir().get(hir_id) {
Node::TraitItem(item) => match item.kind {
TraitItemKind::Method(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
Expand All @@ -1229,9 +1213,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
},
TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty),
TraitItemKind::Type(_, None) => {
if !fail {
return None;
}
span_bug!(item.span, "associated type missing default");
}
},
Expand Down Expand Up @@ -1325,9 +1306,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
| ItemKind::GlobalAsm(..)
| ItemKind::ExternCrate(..)
| ItemKind::Use(..) => {
if !fail {
return None;
}
span_bug!(
item.span,
"compute_type_of_item: unexpected item type: {:?}",
Expand Down Expand Up @@ -1365,7 +1343,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
..
}) => {
if gen.is_some() {
return Some(tcx.typeck_tables_of(def_id).node_type(hir_id));
return tcx.typeck_tables_of(def_id).node_type(hir_id);
}

let substs = InternalSubsts::identity_for_item(tcx, def_id);
Expand Down Expand Up @@ -1440,13 +1418,9 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
.map(|(index, _)| index)
.next()
})
.or_else(|| {
if !fail {
None
} else {
bug!("no arg matching AnonConst in path")
}
})?;
.unwrap_or_else(|| {
bug!("no arg matching AnonConst in path");
});

// We've encountered an `AnonConst` in some path, so we need to
// figure out which generic parameter it corresponds to and return
Expand All @@ -1456,8 +1430,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
tcx.generics_of(tcx.parent(def_id).unwrap())
}
Res::Def(_, def_id) => tcx.generics_of(def_id),
Res::Err => return Some(tcx.types.err),
_ if !fail => return None,
Res::Err => return tcx.types.err,
res => {
tcx.sess.delay_span_bug(
DUMMY_SP,
Expand All @@ -1466,7 +1439,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
res,
),
);
return Some(tcx.types.err);
return tcx.types.err;
}
};

Expand All @@ -1484,24 +1457,18 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
// probably from an extra arg where one is not needed.
.unwrap_or(tcx.types.err)
} else {
if !fail {
return None;
}
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
"unexpected const parent path {:?}",
parent_node,
),
);
return Some(tcx.types.err);
return tcx.types.err;
}
}

x => {
if !fail {
return None;
}
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
Expand Down Expand Up @@ -1551,21 +1518,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
}
ty
}
x => {
if !fail {
return None;
}
bug!("unexpected non-type Node::GenericParam: {:?}", x)
},
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
},

x => {
if !fail {
return None;
}
bug!("unexpected sort of node in type_of_def_id(): {:?}", x);
}
})
}
}

fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
Expand Down Expand Up @@ -2075,10 +2034,7 @@ fn explicit_predicates_of(
}
}

let hir_id = match tcx.hir().as_local_hir_id(def_id) {
Some(hir_id) => hir_id,
None => return tcx.predicates_of(def_id),
};
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let node = tcx.hir().get(hir_id);

let mut is_trait = None;
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_typeck/lib.rs
Expand Up @@ -109,8 +109,6 @@ use util::common::time;
use std::iter;

use astconv::{AstConv, Bounds};
pub use collect::checked_type_of;

pub struct TypeAndSubsts<'tcx> {
substs: SubstsRef<'tcx>,
ty: Ty<'tcx>,
Expand Down

0 comments on commit d7f1406

Please sign in to comment.