Skip to content

Commit ea15431

Browse files
committed
Run tests with both solvers by default
1 parent 3a074e4 commit ea15431

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

chalk-solve/src/solve.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,19 @@ pub enum SolverChoice {
196196
}
197197

198198
impl SolverChoice {
199-
/// Returns the default SLG parameters.
199+
/// Returns specific SLG parameters.
200200
pub fn slg(max_size: usize, expected_answers: Option<usize>) -> Self {
201201
SolverChoice::SLG {
202202
max_size,
203203
expected_answers,
204204
}
205205
}
206206

207+
/// Returns the default SLG parameters.
208+
pub fn slg_default() -> Self {
209+
SolverChoice::slg(10, None)
210+
}
211+
207212
/// Returns the default recursive solver setup.
208213
pub fn recursive() -> Self {
209214
SolverChoice::Recursive {
@@ -234,8 +239,8 @@ impl SolverChoice {
234239

235240
impl Default for SolverChoice {
236241
fn default() -> Self {
237-
SolverChoice::recursive()
238-
// SolverChoice::slg(10, None)
242+
// SolverChoice::recursive()
243+
SolverChoice::slg(10, None)
239244
}
240245
}
241246

tests/test/cycle.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,15 @@ fn overflow() {
163163
// Will try to prove S<G<Z>>: Q then S<G<G<Z>>>: Q etc ad infinitum
164164
goal {
165165
S<Z>: Q
166-
} yields {
166+
} yields[SolverChoice::slg(10, None)] {
167167
"Ambiguous; no inference guidance"
168168
}
169+
170+
goal {
171+
S<Z>: Q
172+
} yields[SolverChoice::recursive()] {
173+
"No possible solution"
174+
}
169175
}
170176
}
171177

tests/test/mod.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,29 @@ macro_rules! test {
7171
test!(@program[$program]
7272
@parsed_goals[
7373
$($parsed_goals)*
74-
(stringify!($goal), SolverChoice::default(), TestGoal::Aggregated($expected))
74+
(stringify!($goal), SolverChoice::slg_default(), TestGoal::Aggregated($expected))
75+
(stringify!($goal), SolverChoice::recursive(), TestGoal::Aggregated($expected))
7576
]
7677
@unparsed_goals[$($unparsed_goals)*])
7778
};
7879

79-
// goal { G } yields_all { "Y1", "Y2", ... , "YN" } -- test both solvers gets exactly N same answers in
80-
// the same order
80+
// goal { G } yields_all { "Y1", "Y2", ... , "YN" } -- test that the SLG
81+
// solver gets exactly N answers in this order (the recursive solver can't
82+
// return multiple answers)
8183
(@program[$program:tt] @parsed_goals[$($parsed_goals:tt)*] @unparsed_goals[
8284
goal $goal:tt yields_all { $($expected:expr),* }
8385
$($unparsed_goals:tt)*
8486
]) => {
8587
test!(@program[$program]
8688
@parsed_goals[
8789
$($parsed_goals)*
88-
(stringify!($goal), SolverChoice::default(), TestGoal::All(vec![$($expected),*]))
90+
(stringify!($goal), SolverChoice::slg_default(), TestGoal::All(vec![$($expected),*]))
8991
]
9092
@unparsed_goals[$($unparsed_goals)*])
9193
};
9294

93-
// goal { G } yields_first { "Y1", "Y2", ... , "YN" } -- test both solvers gets at least N same first answers
95+
// goal { G } yields_first { "Y1", "Y2", ... , "YN" } -- test that the SLG
96+
// solver gets at least N same first answers
9497
(@program[$program:tt] @parsed_goals[$($parsed_goals:tt)*] @unparsed_goals[
9598
goal $goal:tt yields_first { $($expected:expr),* }
9699
$($unparsed_goals:tt)*
@@ -122,6 +125,20 @@ macro_rules! test {
122125
@unparsed_goals[goal $($unparsed_goals)*])
123126
};
124127

128+
// same as above, but there are multiple yields clauses => duplicate the goal
129+
(@program[$program:tt] @parsed_goals[$($parsed_goals:tt)*] @unparsed_goals[
130+
goal $goal:tt
131+
yields[$C:expr] { $expected:expr }
132+
yields $($unparsed_tail:tt)*
133+
]) => {
134+
test!(@program[$program]
135+
@parsed_goals[
136+
$($parsed_goals)*
137+
(stringify!($goal), $C, TestGoal::Aggregated($expected))
138+
]
139+
@unparsed_goals[goal $goal yields $($unparsed_tail)*])
140+
};
141+
125142
// same as above, but for the final goal in the list.
126143
(@program[$program:tt] @parsed_goals[$($parsed_goals:tt)*] @unparsed_goals[
127144
goal $goal:tt yields[$C:expr] { $expected:expr }

tests/test/projection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn projection_equality() {
142142
exists<U> {
143143
S: Trait2<U>
144144
}
145-
} yields {
145+
} yields[SolverChoice::recursive()] {
146146
"Unique; substitution [?0 := u32]"
147147
}
148148
}

tests/test/unify.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,17 @@ fn unify_quantified_lifetimes() {
108108
}
109109
}
110110
}
111-
} yields {
111+
} yields[SolverChoice::slg(10, None)] {
112112
"Unique; for<?U0> { \
113113
substitution [?0 := '^0.0, ?1 := '!1_0], \
114114
lifetime constraints [InEnvironment { environment: Env([]), goal: '^0.0 == '!1_0 }] \
115115
}"
116+
} yields[SolverChoice::recursive()] {
117+
// only difference is in the value of ?1, which is equivalent
118+
"Unique; for<?U0> { \
119+
substitution [?0 := '^0.0, ?1 := '^0.0], \
120+
lifetime constraints [InEnvironment { environment: Env([]), goal: '^0.0 == '!1_0 }] \
121+
}"
116122
}
117123
}
118124
}

0 commit comments

Comments
 (0)