Skip to content

Commit d7f1406

Browse files
authored
Rollup merge of rust-lang#59789 - eddyb:typeck-reverts, r=nikomatsakis
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
2 parents 7a76fe7 + d594fc2 commit d7f1406

File tree

7 files changed

+71
-109
lines changed

7 files changed

+71
-109
lines changed

Diff for: src/librustc_metadata/cstore_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
9595
generics_of => {
9696
tcx.arena.alloc(cdata.get_generics(def_id.index, tcx.sess))
9797
}
98-
predicates_of => { cdata.get_predicates(def_id.index, tcx) }
99-
predicates_defined_on => { cdata.get_predicates_defined_on(def_id.index, tcx) }
98+
explicit_predicates_of => { cdata.get_explicit_predicates(def_id.index, tcx) }
99+
inferred_outlives_of => { cdata.get_inferred_outlives(def_id.index, tcx) }
100100
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
101101
trait_def => {
102102
tcx.arena.alloc(cdata.get_trait_def(def_id.index, tcx.sess))

Diff for: src/librustc_metadata/decoder.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -658,20 +658,22 @@ impl<'a, 'tcx> CrateMetadata {
658658
tcx.alloc_adt_def(did, adt_kind, variants, repr)
659659
}
660660

661-
crate fn get_predicates(
661+
crate fn get_explicit_predicates(
662662
&self,
663663
item_id: DefIndex,
664664
tcx: TyCtxt<'tcx>,
665665
) -> ty::GenericPredicates<'tcx> {
666-
self.root.per_def.predicates.get(self, item_id).unwrap().decode((self, tcx))
666+
self.root.per_def.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx))
667667
}
668668

669-
crate fn get_predicates_defined_on(
669+
crate fn get_inferred_outlives(
670670
&self,
671671
item_id: DefIndex,
672672
tcx: TyCtxt<'tcx>,
673-
) -> ty::GenericPredicates<'tcx> {
674-
self.root.per_def.predicates_defined_on.get(self, item_id).unwrap().decode((self, tcx))
673+
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
674+
self.root.per_def.inferred_outlives.get(self, item_id).map(|predicates| {
675+
predicates.decode((self, tcx))
676+
}).unwrap_or_default()
675677
}
676678

677679
crate fn get_super_predicates(

Diff for: src/librustc_metadata/encoder.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ struct PerDefTables<'tcx> {
7676
inherent_impls: PerDefTable<Lazy<[DefIndex]>>,
7777
variances: PerDefTable<Lazy<[ty::Variance]>>,
7878
generics: PerDefTable<Lazy<ty::Generics>>,
79-
predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
80-
predicates_defined_on: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
79+
explicit_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
80+
inferred_outlives: PerDefTable<Lazy<&'tcx [(ty::Predicate<'tcx>, Span)]>>,
8181
super_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
8282

8383
mir: PerDefTable<Lazy<mir::Body<'tcx>>>,
@@ -524,8 +524,8 @@ impl<'tcx> EncodeContext<'tcx> {
524524
inherent_impls: self.per_def.inherent_impls.encode(&mut self.opaque),
525525
variances: self.per_def.variances.encode(&mut self.opaque),
526526
generics: self.per_def.generics.encode(&mut self.opaque),
527-
predicates: self.per_def.predicates.encode(&mut self.opaque),
528-
predicates_defined_on: self.per_def.predicates_defined_on.encode(&mut self.opaque),
527+
explicit_predicates: self.per_def.explicit_predicates.encode(&mut self.opaque),
528+
inferred_outlives: self.per_def.inferred_outlives.encode(&mut self.opaque),
529529
super_predicates: self.per_def.super_predicates.encode(&mut self.opaque),
530530

531531
mir: self.per_def.mir.encode(&mut self.opaque),
@@ -675,7 +675,8 @@ impl EncodeContext<'tcx> {
675675
self.encode_variances_of(def_id);
676676
}
677677
self.encode_generics(def_id);
678-
self.encode_predicates(def_id);
678+
self.encode_explicit_predicates(def_id);
679+
self.encode_inferred_outlives(def_id);
679680
self.encode_optimized_mir(def_id);
680681
self.encode_promoted_mir(def_id);
681682
}
@@ -718,7 +719,8 @@ impl EncodeContext<'tcx> {
718719
self.encode_variances_of(def_id);
719720
}
720721
self.encode_generics(def_id);
721-
self.encode_predicates(def_id);
722+
self.encode_explicit_predicates(def_id);
723+
self.encode_inferred_outlives(def_id);
722724
self.encode_optimized_mir(def_id);
723725
self.encode_promoted_mir(def_id);
724726
}
@@ -776,7 +778,8 @@ impl EncodeContext<'tcx> {
776778
self.encode_deprecation(def_id);
777779
self.encode_item_type(def_id);
778780
self.encode_generics(def_id);
779-
self.encode_predicates(def_id);
781+
self.encode_explicit_predicates(def_id);
782+
self.encode_inferred_outlives(def_id);
780783
}
781784

782785
fn encode_struct_ctor(&mut self, adt_def_id: DefId, def_id: DefId) {
@@ -819,7 +822,8 @@ impl EncodeContext<'tcx> {
819822
self.encode_variances_of(def_id);
820823
}
821824
self.encode_generics(def_id);
822-
self.encode_predicates(def_id);
825+
self.encode_explicit_predicates(def_id);
826+
self.encode_inferred_outlives(def_id);
823827
self.encode_optimized_mir(def_id);
824828
self.encode_promoted_mir(def_id);
825829
}
@@ -829,15 +833,18 @@ impl EncodeContext<'tcx> {
829833
record!(self.per_def.generics[def_id] <- self.tcx.generics_of(def_id));
830834
}
831835

832-
fn encode_predicates(&mut self, def_id: DefId) {
833-
debug!("EncodeContext::encode_predicates({:?})", def_id);
834-
record!(self.per_def.predicates[def_id] <- self.tcx.predicates_of(def_id));
836+
fn encode_explicit_predicates(&mut self, def_id: DefId) {
837+
debug!("EncodeContext::encode_explicit_predicates({:?})", def_id);
838+
record!(self.per_def.explicit_predicates[def_id] <-
839+
self.tcx.explicit_predicates_of(def_id));
835840
}
836841

837-
fn encode_predicates_defined_on(&mut self, def_id: DefId) {
838-
debug!("EncodeContext::encode_predicates_defined_on({:?})", def_id);
839-
record!(self.per_def.predicates_defined_on[def_id] <-
840-
self.tcx.predicates_defined_on(def_id))
842+
fn encode_inferred_outlives(&mut self, def_id: DefId) {
843+
debug!("EncodeContext::encode_inferred_outlives({:?})", def_id);
844+
let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
845+
if !inferred_outlives.is_empty() {
846+
record!(self.per_def.inferred_outlives[def_id] <- inferred_outlives);
847+
}
841848
}
842849

843850
fn encode_super_predicates(&mut self, def_id: DefId) {
@@ -919,7 +926,8 @@ impl EncodeContext<'tcx> {
919926
self.encode_variances_of(def_id);
920927
}
921928
self.encode_generics(def_id);
922-
self.encode_predicates(def_id);
929+
self.encode_explicit_predicates(def_id);
930+
self.encode_inferred_outlives(def_id);
923931
self.encode_optimized_mir(def_id);
924932
self.encode_promoted_mir(def_id);
925933
}
@@ -986,7 +994,8 @@ impl EncodeContext<'tcx> {
986994
self.encode_variances_of(def_id);
987995
}
988996
self.encode_generics(def_id);
989-
self.encode_predicates(def_id);
997+
self.encode_explicit_predicates(def_id);
998+
self.encode_inferred_outlives(def_id);
990999
let mir = match ast_item.kind {
9911000
hir::ImplItemKind::Const(..) => true,
9921001
hir::ImplItemKind::Method(ref sig, _) => {
@@ -1260,22 +1269,11 @@ impl EncodeContext<'tcx> {
12601269
hir::ItemKind::Trait(..) |
12611270
hir::ItemKind::TraitAlias(..) => {
12621271
self.encode_generics(def_id);
1263-
self.encode_predicates(def_id);
1272+
self.encode_explicit_predicates(def_id);
1273+
self.encode_inferred_outlives(def_id);
12641274
}
12651275
_ => {}
12661276
}
1267-
// The only time that `predicates_defined_on` is used (on
1268-
// an external item) is for traits, during chalk lowering,
1269-
// so only encode it in that case as an efficiency
1270-
// hack. (No reason not to expand it in the future if
1271-
// necessary.)
1272-
match item.kind {
1273-
hir::ItemKind::Trait(..) |
1274-
hir::ItemKind::TraitAlias(..) => {
1275-
self.encode_predicates_defined_on(def_id);
1276-
}
1277-
_ => {} // not *wrong* for other kinds of items, but not needed
1278-
}
12791277
match item.kind {
12801278
hir::ItemKind::Trait(..) |
12811279
hir::ItemKind::TraitAlias(..) => {
@@ -1377,7 +1375,8 @@ impl EncodeContext<'tcx> {
13771375
record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id));
13781376
self.encode_item_type(def_id);
13791377
self.encode_generics(def_id);
1380-
self.encode_predicates(def_id);
1378+
self.encode_explicit_predicates(def_id);
1379+
self.encode_inferred_outlives(def_id);
13811380
self.encode_optimized_mir(def_id);
13821381
self.encode_promoted_mir(def_id);
13831382
}
@@ -1588,7 +1587,8 @@ impl EncodeContext<'tcx> {
15881587
self.encode_variances_of(def_id);
15891588
}
15901589
self.encode_generics(def_id);
1591-
self.encode_predicates(def_id);
1590+
self.encode_explicit_predicates(def_id);
1591+
self.encode_inferred_outlives(def_id);
15921592
}
15931593
}
15941594

Diff for: src/librustc_metadata/schema.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,13 @@ crate struct LazyPerDefTables<'tcx> {
244244
pub inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
245245
pub variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
246246
pub generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
247-
pub predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
248-
pub predicates_defined_on: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
247+
pub explicit_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
248+
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
249+
// doesn't handle shorthands in its own (de)serialization impls,
250+
// as it's an `enum` for which we want to derive (de)serialization,
251+
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
252+
// Also, as an optimization, a missing entry indicates an empty `&[]`.
253+
pub inferred_outlives: Lazy!(PerDefTable<Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>),
249254
pub super_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
250255

251256
pub mir: Lazy!(PerDefTable<Lazy!(mir::Body<'tcx>)>),

Diff for: src/librustc_typeck/collect.rs

+13-57
Original file line numberDiff line numberDiff line change
@@ -1146,10 +1146,6 @@ fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
11461146
);
11471147
}
11481148

1149-
fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1150-
checked_type_of(tcx, def_id, true).unwrap()
1151-
}
1152-
11531149
fn infer_placeholder_type(
11541150
tcx: TyCtxt<'_>,
11551151
def_id: DefId,
@@ -1193,26 +1189,14 @@ fn infer_placeholder_type(
11931189
ty
11941190
}
11951191

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

1203-
let hir_id = match tcx.hir().as_local_hir_id(def_id) {
1204-
Some(hir_id) => hir_id,
1205-
None => {
1206-
if !fail {
1207-
return None;
1208-
}
1209-
bug!("invalid node");
1210-
}
1211-
};
1195+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
12121196

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

1215-
Some(match tcx.hir().get(hir_id) {
1199+
match tcx.hir().get(hir_id) {
12161200
Node::TraitItem(item) => match item.kind {
12171201
TraitItemKind::Method(..) => {
12181202
let substs = InternalSubsts::identity_for_item(tcx, def_id);
@@ -1229,9 +1213,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
12291213
},
12301214
TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty),
12311215
TraitItemKind::Type(_, None) => {
1232-
if !fail {
1233-
return None;
1234-
}
12351216
span_bug!(item.span, "associated type missing default");
12361217
}
12371218
},
@@ -1325,9 +1306,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
13251306
| ItemKind::GlobalAsm(..)
13261307
| ItemKind::ExternCrate(..)
13271308
| ItemKind::Use(..) => {
1328-
if !fail {
1329-
return None;
1330-
}
13311309
span_bug!(
13321310
item.span,
13331311
"compute_type_of_item: unexpected item type: {:?}",
@@ -1365,7 +1343,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
13651343
..
13661344
}) => {
13671345
if gen.is_some() {
1368-
return Some(tcx.typeck_tables_of(def_id).node_type(hir_id));
1346+
return tcx.typeck_tables_of(def_id).node_type(hir_id);
13691347
}
13701348

13711349
let substs = InternalSubsts::identity_for_item(tcx, def_id);
@@ -1440,13 +1418,9 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
14401418
.map(|(index, _)| index)
14411419
.next()
14421420
})
1443-
.or_else(|| {
1444-
if !fail {
1445-
None
1446-
} else {
1447-
bug!("no arg matching AnonConst in path")
1448-
}
1449-
})?;
1421+
.unwrap_or_else(|| {
1422+
bug!("no arg matching AnonConst in path");
1423+
});
14501424

14511425
// We've encountered an `AnonConst` in some path, so we need to
14521426
// figure out which generic parameter it corresponds to and return
@@ -1456,8 +1430,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
14561430
tcx.generics_of(tcx.parent(def_id).unwrap())
14571431
}
14581432
Res::Def(_, def_id) => tcx.generics_of(def_id),
1459-
Res::Err => return Some(tcx.types.err),
1460-
_ if !fail => return None,
1433+
Res::Err => return tcx.types.err,
14611434
res => {
14621435
tcx.sess.delay_span_bug(
14631436
DUMMY_SP,
@@ -1466,7 +1439,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
14661439
res,
14671440
),
14681441
);
1469-
return Some(tcx.types.err);
1442+
return tcx.types.err;
14701443
}
14711444
};
14721445

@@ -1484,24 +1457,18 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
14841457
// probably from an extra arg where one is not needed.
14851458
.unwrap_or(tcx.types.err)
14861459
} else {
1487-
if !fail {
1488-
return None;
1489-
}
14901460
tcx.sess.delay_span_bug(
14911461
DUMMY_SP,
14921462
&format!(
14931463
"unexpected const parent path {:?}",
14941464
parent_node,
14951465
),
14961466
);
1497-
return Some(tcx.types.err);
1467+
return tcx.types.err;
14981468
}
14991469
}
15001470

15011471
x => {
1502-
if !fail {
1503-
return None;
1504-
}
15051472
tcx.sess.delay_span_bug(
15061473
DUMMY_SP,
15071474
&format!(
@@ -1551,21 +1518,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
15511518
}
15521519
ty
15531520
}
1554-
x => {
1555-
if !fail {
1556-
return None;
1557-
}
1558-
bug!("unexpected non-type Node::GenericParam: {:?}", x)
1559-
},
1521+
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
15601522
},
15611523

15621524
x => {
1563-
if !fail {
1564-
return None;
1565-
}
15661525
bug!("unexpected sort of node in type_of_def_id(): {:?}", x);
15671526
}
1568-
})
1527+
}
15691528
}
15701529

15711530
fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
@@ -2075,10 +2034,7 @@ fn explicit_predicates_of(
20752034
}
20762035
}
20772036

2078-
let hir_id = match tcx.hir().as_local_hir_id(def_id) {
2079-
Some(hir_id) => hir_id,
2080-
None => return tcx.predicates_of(def_id),
2081-
};
2037+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
20822038
let node = tcx.hir().get(hir_id);
20832039

20842040
let mut is_trait = None;

Diff for: src/librustc_typeck/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ use util::common::time;
109109
use std::iter;
110110

111111
use astconv::{AstConv, Bounds};
112-
pub use collect::checked_type_of;
113-
114112
pub struct TypeAndSubsts<'tcx> {
115113
substs: SubstsRef<'tcx>,
116114
ty: Ty<'tcx>,

0 commit comments

Comments
 (0)