Skip to content

Commit 7e0b48c

Browse files
committedMar 20, 2024
Remove EvaluatedToErrStackDependent
1 parent 9adee3e commit 7e0b48c

File tree

4 files changed

+9
-90
lines changed

4 files changed

+9
-90
lines changed
 

‎compiler/rustc_middle/src/traits/select.rs

+4-48
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ pub enum SelectionCandidate<'tcx> {
193193
/// The evaluation results are ordered:
194194
/// - `EvaluatedToOk` implies `EvaluatedToOkModuloRegions`
195195
/// implies `EvaluatedToAmbig` implies `EvaluatedToAmbigStackDependent`
196-
/// - `EvaluatedToErr` implies `EvaluatedToErrStackDependent`
197196
/// - the "union" of evaluation results is equal to their maximum -
198197
/// all the "potential success" candidates can potentially succeed,
199198
/// so they are noops when unioned with a definite error, and within
@@ -219,52 +218,9 @@ pub enum EvaluationResult {
219218
/// variables. We are somewhat imprecise there, so we don't actually
220219
/// know the real result.
221220
///
222-
/// This can't be trivially cached for the same reason as `EvaluatedToErrStackDependent`.
221+
/// This can't be trivially cached because the result depends on the
222+
/// stack results.
223223
EvaluatedToAmbigStackDependent,
224-
/// Evaluation failed because we encountered an obligation we are already
225-
/// trying to prove on this branch.
226-
///
227-
/// We know this branch can't be a part of a minimal proof-tree for
228-
/// the "root" of our cycle, because then we could cut out the recursion
229-
/// and maintain a valid proof tree. However, this does not mean
230-
/// that all the obligations on this branch do not hold -- it's possible
231-
/// that we entered this branch "speculatively", and that there
232-
/// might be some other way to prove this obligation that does not
233-
/// go through this cycle -- so we can't cache this as a failure.
234-
///
235-
/// For example, suppose we have this:
236-
///
237-
/// ```rust,ignore (pseudo-Rust)
238-
/// pub trait Trait { fn xyz(); }
239-
/// // This impl is "useless", but we can still have
240-
/// // an `impl Trait for SomeUnsizedType` somewhere.
241-
/// impl<T: Trait + Sized> Trait for T { fn xyz() {} }
242-
///
243-
/// pub fn foo<T: Trait + ?Sized>() {
244-
/// <T as Trait>::xyz();
245-
/// }
246-
/// ```
247-
///
248-
/// When checking `foo`, we have to prove `T: Trait`. This basically
249-
/// translates into this:
250-
///
251-
/// ```plain,ignore
252-
/// (T: Trait + Sized →_\impl T: Trait), T: Trait ⊢ T: Trait
253-
/// ```
254-
///
255-
/// When we try to prove it, we first go the first option, which
256-
/// recurses. This shows us that the impl is "useless" -- it won't
257-
/// tell us that `T: Trait` unless it already implemented `Trait`
258-
/// by some other means. However, that does not prevent `T: Trait`
259-
/// does not hold, because of the bound (which can indeed be satisfied
260-
/// by `SomeUnsizedType` from another crate).
261-
//
262-
// FIXME: when an `EvaluatedToErrStackDependent` goes past its parent root, we
263-
// ought to convert it to an `EvaluatedToErr`, because we know
264-
// there definitely isn't a proof tree for that obligation. Not
265-
// doing so is still sound -- there isn't any proof tree, so the
266-
// branch still can't be a part of a minimal one -- but does not re-enable caching.
267-
EvaluatedToErrStackDependent,
268224
/// Evaluation failed.
269225
EvaluatedToErr,
270226
}
@@ -290,13 +246,13 @@ impl EvaluationResult {
290246
| EvaluatedToAmbig
291247
| EvaluatedToAmbigStackDependent => true,
292248

293-
EvaluatedToErr | EvaluatedToErrStackDependent => false,
249+
EvaluatedToErr => false,
294250
}
295251
}
296252

297253
pub fn is_stack_dependent(self) -> bool {
298254
match self {
299-
EvaluatedToAmbigStackDependent | EvaluatedToErrStackDependent => true,
255+
EvaluatedToAmbigStackDependent => true,
300256

301257
EvaluatedToOkModuloOpaqueTypes
302258
| EvaluatedToOk

‎compiler/rustc_trait_selection/src/infer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ impl<'tcx> InferCtxt<'tcx> {
4949
/// - the parameter environment
5050
///
5151
/// Invokes `evaluate_obligation`, so in the event that evaluating
52-
/// `Ty: Trait` causes overflow, EvaluatedToErrStackDependent
53-
/// (or EvaluatedToAmbigStackDependent) will be returned.
52+
/// `Ty: Trait` causes overflow, EvaluatedToAmbigStackDependent will be returned.
5453
#[instrument(level = "debug", skip(self, params), ret)]
5554
fn type_implements_trait(
5655
&self,

‎compiler/rustc_trait_selection/src/traits/coherence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn overlap<'tcx>(
210210
.intercrate(true)
211211
.with_next_trait_solver(tcx.next_trait_solver_in_coherence())
212212
.build();
213-
let selcx = &mut SelectionContext::with_treat_inductive_cycle_as_ambig(&infcx);
213+
let selcx = &mut SelectionContext::new(&infcx);
214214
if track_ambiguity_causes.is_yes() {
215215
selcx.enable_tracking_intercrate_ambiguity_causes();
216216
}

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-39
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ pub struct SelectionContext<'cx, 'tcx> {
126126
/// policy. In essence, canonicalized queries need their errors propagated
127127
/// rather than immediately reported because we do not have accurate spans.
128128
query_mode: TraitQueryMode,
129-
130-
treat_inductive_cycle: TreatInductiveCycleAs,
131129
}
132130

133131
// A stack that walks back up the stack frame.
@@ -208,47 +206,13 @@ enum BuiltinImplConditions<'tcx> {
208206
Ambiguous,
209207
}
210208

211-
#[derive(Copy, Clone)]
212-
pub enum TreatInductiveCycleAs {
213-
/// This is the previous behavior, where `Recur` represents an inductive
214-
/// cycle that is known not to hold. This is not forwards-compatible with
215-
/// coinduction, and will be deprecated. This is the default behavior
216-
/// of the old trait solver due to back-compat reasons.
217-
Recur,
218-
/// This is the behavior of the new trait solver, where inductive cycles
219-
/// are treated as ambiguous and possibly holding.
220-
Ambig,
221-
}
222-
223-
impl From<TreatInductiveCycleAs> for EvaluationResult {
224-
fn from(treat: TreatInductiveCycleAs) -> EvaluationResult {
225-
match treat {
226-
TreatInductiveCycleAs::Ambig => EvaluatedToAmbigStackDependent,
227-
TreatInductiveCycleAs::Recur => EvaluatedToErrStackDependent,
228-
}
229-
}
230-
}
231-
232209
impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
233210
pub fn new(infcx: &'cx InferCtxt<'tcx>) -> SelectionContext<'cx, 'tcx> {
234211
SelectionContext {
235212
infcx,
236213
freshener: infcx.freshener(),
237214
intercrate_ambiguity_causes: None,
238215
query_mode: TraitQueryMode::Standard,
239-
treat_inductive_cycle: TreatInductiveCycleAs::Ambig,
240-
}
241-
}
242-
243-
pub fn with_treat_inductive_cycle_as_ambig(
244-
infcx: &'cx InferCtxt<'tcx>,
245-
) -> SelectionContext<'cx, 'tcx> {
246-
// Should be executed in a context where caching is disabled,
247-
// otherwise the cache is poisoned with the temporary result.
248-
assert!(infcx.intercrate);
249-
SelectionContext {
250-
treat_inductive_cycle: TreatInductiveCycleAs::Ambig,
251-
..SelectionContext::new(infcx)
252216
}
253217
}
254218

@@ -756,7 +720,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
756720
stack.update_reached_depth(stack_arg.1);
757721
return Ok(EvaluatedToOk);
758722
} else {
759-
return Ok(self.treat_inductive_cycle.into());
723+
return Ok(EvaluatedToAmbigStackDependent);
760724
}
761725
}
762726
return Ok(EvaluatedToOk);
@@ -875,7 +839,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
875839
}
876840
}
877841
ProjectAndUnifyResult::FailedNormalization => Ok(EvaluatedToAmbig),
878-
ProjectAndUnifyResult::Recursive => Ok(self.treat_inductive_cycle.into()),
842+
ProjectAndUnifyResult::Recursive => Ok(EvaluatedToAmbigStackDependent),
879843
ProjectAndUnifyResult::MismatchedProjectionTypes(_) => Ok(EvaluatedToErr),
880844
}
881845
}
@@ -1180,7 +1144,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11801144
Some(EvaluatedToOk)
11811145
} else {
11821146
debug!("evaluate_stack --> recursive, inductive");
1183-
Some(self.treat_inductive_cycle.into())
1147+
Some(EvaluatedToAmbigStackDependent)
11841148
}
11851149
} else {
11861150
None

0 commit comments

Comments
 (0)