Skip to content

Commit 70b2fdb

Browse files
committed
Revert "extend SLG solver with a similar optimization"
This reverts commit 502d989.
1 parent 502d989 commit 70b2fdb

File tree

4 files changed

+8
-35
lines changed

4 files changed

+8
-35
lines changed

chalk-engine/src/slg/aggregate.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,8 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
4646
}
4747
};
4848

49-
// If the answer is trivially true and thus subsumes all others, then that's a unique-enough answer for us :)
50-
if subst.value.is_identity_subst_with_no_constraints(interner) {
51-
return Some(Solution::Unique(subst));
52-
}
53-
54-
tracing::debug!("subst = {:?}", subst);
55-
5649
// Exactly 1 unconditional answer?
5750
let next_answer = answers.peek_answer(&should_continue);
58-
tracing::debug!("next_answer = {:?}", next_answer);
5951
if next_answer.is_quantum_exceeded() {
6052
if subst.value.subst.is_identity_subst(interner) {
6153
return Some(Solution::Ambig(Guidance::Unknown));
@@ -91,11 +83,9 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
9183
break Guidance::Unknown;
9284
}
9385

94-
// FIXME: This may cause us to miss some "trivially true" answers maybe? Haven't investigated very deeply.
9586
if !answers
9687
.any_future_answer(|ref mut new_subst| new_subst.may_invalidate(interner, &subst))
9788
{
98-
tracing::debug!("any_future_answer: false");
9989
break Guidance::Definite(subst);
10090
}
10191

@@ -106,17 +96,7 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
10696
}
10797

10898
let new_subst = match answers.next_answer(&should_continue) {
109-
AnswerResult::Answer(answer1) => {
110-
if answer1
111-
.subst
112-
.value
113-
.is_identity_subst_with_no_constraints(interner)
114-
{
115-
// If the answer is trivially true and thus subsumes all others, then that's a unique-enough answer for us :)
116-
return Some(Solution::Unique(answer1.subst));
117-
}
118-
answer1.subst
119-
}
99+
AnswerResult::Answer(answer1) => answer1.subst,
120100
AnswerResult::Floundered => {
121101
// FIXME: this doesn't trigger for any current tests
122102
self.identity_constrained_subst(root_goal)
@@ -128,7 +108,6 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
128108
break Guidance::Suggested(subst);
129109
}
130110
};
131-
tracing::debug!("new_subst = {:?}", new_subst);
132111
subst = merge_into_guidance(interner, &root_goal.canonical, subst, &new_subst);
133112
num_answers += 1;
134113
};

chalk-ir/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,15 +3048,6 @@ pub struct ConstrainedSubst<I: Interner> {
30483048
pub constraints: Constraints<I>,
30493049
}
30503050

3051-
impl<I: Interner> ConstrainedSubst<I> {
3052-
/// True if this is an identity subst (it maps variable 0 to variable 0 etc)
3053-
/// and has no constraints. This represents an "unconditionally true" answer which
3054-
/// is a convenient thing to recognize.
3055-
pub fn is_identity_subst_with_no_constraints(&self, interner: I) -> bool {
3056-
self.subst.is_identity_subst(interner) && self.constraints.is_empty(interner)
3057-
}
3058-
}
3059-
30603051
/// The resulting substitution after solving a goal.
30613052
#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, Visit, HasInterner)]
30623053
pub struct AnswerSubst<I: Interner> {

chalk-solve/src/solve.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ impl<I: Interner> Solution<I> {
103103

104104
pub fn is_trivial_and_always_true(&self, interner: I) -> bool {
105105
match self {
106-
Solution::Unique(constrained_subst) => constrained_subst
107-
.value
108-
.is_identity_subst_with_no_constraints(interner),
106+
Solution::Unique(constrained_subst) => {
107+
constrained_subst.value.subst.is_identity_subst(interner)
108+
&& constrained_subst.value.constraints.is_empty(interner)
109+
}
109110
Solution::Ambig(_) => false,
110111
}
111112
}

tests/test/misc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,9 @@ fn env_bound_vars() {
812812
WellFormed(&'a ())
813813
}
814814
}
815-
} yields {
815+
} yields[SolverChoice::slg_default()] {
816+
expect![["Ambiguous; definite substitution for<?U0> { [?0 := '^0.0] }"]]
817+
} yields[SolverChoice::recursive_default()] {
816818
expect![[r#"Unique; for<?U0> { substitution [?0 := '^0.0] }"#]]
817819
}
818820
goal {

0 commit comments

Comments
 (0)