Skip to content

Commit d088d8a

Browse files
committed
Revert previous attempt at detecting unsatisfiable predicates
1 parent 4884061 commit d088d8a

File tree

5 files changed

+14
-50
lines changed

5 files changed

+14
-50
lines changed

src/librustc/mir/mono.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::dep_graph::{DepConstructor, DepNode, WorkProduct, WorkProductId};
22
use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
33
use crate::session::config::OptLevel;
4-
use crate::traits::TraitQueryMode;
54
use crate::ty::print::obsolete::DefPathBasedNames;
65
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
76
use rustc_data_structures::base_n;
@@ -168,9 +167,7 @@ impl<'tcx> MonoItem<'tcx> {
168167
MonoItem::GlobalAsm(..) => return true,
169168
};
170169

171-
// We shouldn't encounter any overflow here, so we use TraitQueryMode::Standard\
172-
// to report an error if overflow somehow occurs.
173-
tcx.substitute_normalize_and_test_predicates((def_id, &substs, TraitQueryMode::Standard))
170+
tcx.substitute_normalize_and_test_predicates((def_id, &substs))
174171
}
175172

176173
pub fn to_string(&self, tcx: TyCtxt<'tcx>, debug: bool) -> String {

src/librustc/query/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,11 @@ rustc_queries! {
11481148
desc { "normalizing `{:?}`", goal }
11491149
}
11501150

1151-
query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>, traits::TraitQueryMode)) -> bool {
1151+
query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
11521152
no_force
11531153
desc { |tcx|
1154-
"testing substituted normalized predicates in mode {:?}:`{}`",
1155-
key.2, tcx.def_path_str(key.0)
1154+
"testing substituted normalized predicates:`{}`",
1155+
tcx.def_path_str(key.0)
11561156
}
11571157
}
11581158

src/librustc/traits/fulfill.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use super::CodeSelectionError;
1616
use super::{ConstEvalFailure, Unimplemented};
1717
use super::{FulfillmentError, FulfillmentErrorCode};
1818
use super::{ObligationCause, PredicateObligation};
19-
use crate::traits::TraitQueryMode;
2019

2120
impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> {
2221
type Predicate = ty::Predicate<'tcx>;
@@ -63,9 +62,6 @@ pub struct FulfillmentContext<'tcx> {
6362
// a snapshot (they don't *straddle* a snapshot, so there
6463
// is no trouble there).
6564
usable_in_snapshot: bool,
66-
67-
// The `TraitQueryMode` used when constructing a `SelectionContext`
68-
query_mode: TraitQueryMode,
6965
}
7066

7167
#[derive(Clone, Debug)]
@@ -79,26 +75,12 @@ pub struct PendingPredicateObligation<'tcx> {
7975
static_assert_size!(PendingPredicateObligation<'_>, 136);
8076

8177
impl<'a, 'tcx> FulfillmentContext<'tcx> {
82-
/// Creates a new fulfillment context with `TraitQueryMode::Standard`
83-
/// You almost always want to use this instead of `with_query_mode`
78+
/// Creates a new fulfillment context.
8479
pub fn new() -> FulfillmentContext<'tcx> {
8580
FulfillmentContext {
8681
predicates: ObligationForest::new(),
8782
register_region_obligations: true,
8883
usable_in_snapshot: false,
89-
query_mode: TraitQueryMode::Standard,
90-
}
91-
}
92-
93-
/// Creates a new fulfillment context with the specified query mode.
94-
/// This should only be used when you want to ignore overflow,
95-
/// rather than reporting it as an error.
96-
pub fn with_query_mode(query_mode: TraitQueryMode) -> FulfillmentContext<'tcx> {
97-
FulfillmentContext {
98-
predicates: ObligationForest::new(),
99-
register_region_obligations: true,
100-
usable_in_snapshot: false,
101-
query_mode,
10284
}
10385
}
10486

@@ -107,7 +89,6 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
10789
predicates: ObligationForest::new(),
10890
register_region_obligations: true,
10991
usable_in_snapshot: true,
110-
query_mode: TraitQueryMode::Standard,
11192
}
11293
}
11394

@@ -116,7 +97,6 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
11697
predicates: ObligationForest::new(),
11798
register_region_obligations: false,
11899
usable_in_snapshot: false,
119-
query_mode: TraitQueryMode::Standard,
120100
}
121101
}
122102

@@ -237,7 +217,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
237217
&mut self,
238218
infcx: &InferCtxt<'_, 'tcx>,
239219
) -> Result<(), Vec<FulfillmentError<'tcx>>> {
240-
let mut selcx = SelectionContext::with_query_mode(infcx, self.query_mode);
220+
let mut selcx = SelectionContext::new(infcx);
241221
self.select(&mut selcx)
242222
}
243223

src/librustc/traits/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum IntercrateMode {
9595
}
9696

9797
/// The mode that trait queries run in.
98-
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, HashStable)]
98+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
9999
pub enum TraitQueryMode {
100100
// Standard/un-canonicalized queries get accurate
101101
// spans etc. passed in and hence can do reasonable
@@ -1014,17 +1014,16 @@ where
10141014
/// environment. If this returns false, then either normalize
10151015
/// encountered an error or one of the predicates did not hold. Used
10161016
/// when creating vtables to check for unsatisfiable methods.
1017-
fn normalize_and_test_predicates<'tcx>(
1017+
pub fn normalize_and_test_predicates<'tcx>(
10181018
tcx: TyCtxt<'tcx>,
10191019
predicates: Vec<ty::Predicate<'tcx>>,
1020-
mode: TraitQueryMode,
10211020
) -> bool {
1022-
debug!("normalize_and_test_predicates(predicates={:?}, mode={:?})", predicates, mode);
1021+
debug!("normalize_and_test_predicates(predicates={:?})", predicates);
10231022

10241023
let result = tcx.infer_ctxt().enter(|infcx| {
10251024
let param_env = ty::ParamEnv::reveal_all();
1026-
let mut selcx = SelectionContext::with_query_mode(&infcx, mode);
1027-
let mut fulfill_cx = FulfillmentContext::with_query_mode(mode);
1025+
let mut selcx = SelectionContext::new(&infcx);
1026+
let mut fulfill_cx = FulfillmentContext::new();
10281027
let cause = ObligationCause::dummy();
10291028
let Normalized { value: predicates, obligations } =
10301029
normalize(&mut selcx, param_env, cause.clone(), &predicates);
@@ -1044,12 +1043,12 @@ fn normalize_and_test_predicates<'tcx>(
10441043

10451044
fn substitute_normalize_and_test_predicates<'tcx>(
10461045
tcx: TyCtxt<'tcx>,
1047-
key: (DefId, SubstsRef<'tcx>, TraitQueryMode),
1046+
key: (DefId, SubstsRef<'tcx>),
10481047
) -> bool {
10491048
debug!("substitute_normalize_and_test_predicates(key={:?})", key);
10501049

10511050
let predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates;
1052-
let result = normalize_and_test_predicates(tcx, predicates, key.2);
1051+
let result = normalize_and_test_predicates(tcx, predicates);
10531052

10541053
debug!("substitute_normalize_and_test_predicates(key={:?}) = {:?}", key, result);
10551054
result
@@ -1102,10 +1101,7 @@ fn vtable_methods<'tcx>(
11021101
// Note that this method could then never be called, so we
11031102
// do not want to try and codegen it, in that case (see #23435).
11041103
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
1105-
// We don't expect overflow here, so report an error if it somehow ends
1106-
// up happening.
1107-
if !normalize_and_test_predicates(tcx, predicates.predicates, TraitQueryMode::Standard)
1108-
{
1104+
if !normalize_and_test_predicates(tcx, predicates.predicates) {
11091105
debug!("vtable_methods: predicates do not hold");
11101106
return None;
11111107
}

src/librustc/ty/query/keys.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,6 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
125125
}
126126
}
127127

128-
impl<'tcx> Key for (DefId, SubstsRef<'tcx>, traits::TraitQueryMode) {
129-
fn query_crate(&self) -> CrateNum {
130-
self.0.krate
131-
}
132-
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
133-
self.0.default_span(tcx)
134-
}
135-
}
136-
137128
impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
138129
fn query_crate(&self) -> CrateNum {
139130
self.1.def_id().krate

0 commit comments

Comments
 (0)