Skip to content

Commit 62038e0

Browse files
authored
Merge pull request #152 from leodasvacas/a-bit-more-privacy
Give the chalk solver more privacy
2 parents ba6202a + 86e7f1b commit 62038e0

File tree

12 files changed

+29
-33
lines changed

12 files changed

+29
-33
lines changed

src/ir/lowering/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn goal_quantifiers() {
161161
let program = Arc::new(
162162
parse_and_lower_program(
163163
"trait Foo<A, B> { }",
164-
SolverChoice::slg()
164+
SolverChoice::default()
165165
).unwrap()
166166
);
167167
let goal = parse_and_lower_goal(
@@ -193,7 +193,7 @@ fn atc_accounting() {
193193
194194
struct Iter<'a, T> { }
195195
",
196-
SolverChoice::slg()
196+
SolverChoice::default()
197197
).unwrap(),
198198
);
199199
tls::set_current_program(&program, || {

src/solve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,17 @@ impl SolverChoice {
8888
env: &Arc<ProgramEnvironment>,
8989
canonical_goal: &UCanonical<InEnvironment<Goal>>,
9090
) -> ::errors::Result<Option<Solution>> {
91-
use self::slg::implementation::SlgContext;
91+
use self::slg::implementation::solve_goal_in_program;
9292

9393
match self {
9494
SolverChoice::SLG { max_size } => {
95-
Ok(SlgContext::new(env, max_size).solve_root_goal(&canonical_goal))
95+
Ok(solve_goal_in_program(canonical_goal, env, max_size))
9696
}
9797
}
9898
}
9999

100100
/// Returns the default SLG parameters.
101-
pub fn slg() -> Self {
101+
fn slg() -> Self {
102102
SolverChoice::SLG { max_size: 10 }
103103
}
104104
}

src/solve/infer.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ mod test;
1616
use self::var::*;
1717

1818
#[derive(Clone)]
19-
pub struct InferenceTable {
20-
// FIXME pub b/c of trait impl for SLG
19+
crate struct InferenceTable {
2120
unify: ena::UnificationTable<InferenceVariable>,
2221
vars: Vec<InferenceVariable>,
2322
max_universe: UniverseIndex,
@@ -29,7 +28,7 @@ crate struct InferenceSnapshot {
2928
vars: Vec<InferenceVariable>,
3029
}
3130

32-
crate type ParameterInferenceVariable = ParameterKind<InferenceVariable>;
31+
pub(in solve) type ParameterInferenceVariable = ParameterKind<InferenceVariable>;
3332

3433
impl InferenceTable {
3534
/// Create an empty inference table with no variables.
@@ -101,7 +100,7 @@ impl InferenceTable {
101100
/// Creates a new inference variable and returns its index. The
102101
/// kind of the variable should be known by the caller, but is not
103102
/// tracked directly by the inference table.
104-
crate fn new_variable(&mut self, ui: UniverseIndex) -> InferenceVariable {
103+
pub(in solve) fn new_variable(&mut self, ui: UniverseIndex) -> InferenceVariable {
105104
let var = self.unify.new_key(InferenceValue::Unbound(ui));
106105
self.vars.push(var);
107106
debug!("new_variable: var={:?} ui={:?}", var, ui);

src/solve/infer/canonicalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ crate struct Canonicalized<T> {
5353
crate quantified: Canonical<T>,
5454

5555
/// The free existential variables, along with the universes they inhabit.
56-
crate free_vars: Vec<ParameterInferenceVariable>,
56+
pub(in solve) free_vars: Vec<ParameterInferenceVariable>,
5757

5858
/// The maximum universe of any universally quantified variables
5959
/// encountered.
60-
crate max_universe: UniverseIndex,
60+
max_universe: UniverseIndex,
6161
}
6262

6363
struct Canonicalizer<'q> {

src/solve/infer/invert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl InferenceTable {
7676
{
7777
let Canonicalized {
7878
free_vars,
79-
max_universe: _,
8079
quantified,
80+
..
8181
} = self.canonicalize(&value);
8282

8383
// If the original contains free existential variables, give up.

src/solve/infer/ucanonicalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ crate struct UCanonicalized<T> {
5757
crate quantified: UCanonical<T>,
5858

5959
/// A map between the universes in `quantified` and the original universes
60-
crate universes: UniverseMap,
60+
pub(in solve) universes: UniverseMap,
6161
}
6262

6363
/// Maps the universes found in the `u_canonicalize` result (the
@@ -66,7 +66,7 @@ crate struct UCanonicalized<T> {
6666
/// outside this module -- converts from "canonical" universes to the
6767
/// original (but see the `UMapToCanonical` folder).
6868
#[derive(Clone, Debug)]
69-
pub struct UniverseMap { // FIXME pub b/c of trait impl for SLG
69+
pub(in solve) struct UniverseMap {
7070
/// A reverse map -- for each universe Ux that appears in
7171
/// `quantified`, the corresponding universe in the original was
7272
/// `universes[x]`.

src/solve/infer/unify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct Unifier<'t> {
4545
}
4646

4747
#[derive(Debug)]
48-
pub struct UnificationResult { // FIXME pub b/c of trait impl for SLG
48+
crate struct UnificationResult {
4949
crate goals: Vec<InEnvironment<DomainGoal>>,
5050
crate constraints: Vec<InEnvironment<Constraint>>,
5151
}

src/solve/infer/var.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::u32;
3131
/// "downcast" the resulting variable using
3232
/// e.g. `value.ty().unwrap()`.
3333
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
34-
pub struct InferenceVariable { // FIXME pub b/c of trait impl for SLG
34+
pub(in solve) struct InferenceVariable {
3535
index: u32,
3636
}
3737

@@ -85,7 +85,7 @@ impl UnifyKey for InferenceVariable {
8585
/// universe index; when the inference variable is assigned a value, it becomes
8686
/// bound and records that value. See `InferenceVariable` for more details.
8787
#[derive(Clone, Debug, PartialEq, Eq)]
88-
pub enum InferenceValue { // FIXME pub b/c of trait impl for SLG
88+
pub(in solve) enum InferenceValue {
8989
Unbound(UniverseIndex),
9090
Bound(Parameter),
9191
}

src/solve/slg/implementation.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ use std::sync::Arc;
1919
mod aggregate;
2020
mod resolvent;
2121

22+
/// Entry point for the chalk solver implementation.
23+
/// Solve a canonical goal `root_goal` in the given `program` environment.
24+
pub fn solve_goal_in_program(root_goal: &UCanonical<InEnvironment<Goal>>, program: &Arc<ProgramEnvironment>, max_size: usize) -> Option<Solution> {
25+
Forest::new(SlgContext::new(program, max_size)).solve(root_goal)
26+
}
27+
2228
#[derive(Clone, Debug)]
23-
pub struct SlgContext {
29+
pub(super) struct SlgContext {
2430
program: Arc<ProgramEnvironment>,
2531
max_size: usize,
2632
}
2733

28-
pub struct TruncatingInferenceTable {
34+
pub(super) struct TruncatingInferenceTable {
2935
program: Arc<ProgramEnvironment>,
3036
max_size: usize,
3137
infer: InferenceTable,
@@ -38,15 +44,6 @@ impl SlgContext {
3844
max_size,
3945
}
4046
}
41-
42-
/// Convenience fn for solving a root goal.
43-
crate fn solve_root_goal(
44-
self,
45-
root_goal: &UCanonical<InEnvironment<Goal>>,
46-
) -> Option<Solution> {
47-
let mut forest = Forest::new(self);
48-
forest.solve(root_goal)
49-
}
5047
}
5148

5249
impl context::Context for SlgContext {

src/solve/slg/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn solve_goal(program_text: &str, goals: Vec<(usize, usize, &str, &str)>) {
2828
let program = &Arc::new(
2929
parse_and_lower_program(
3030
&program_text[1..program_text.len() - 1],
31-
SolverChoice::slg()
31+
SolverChoice::default()
3232
).unwrap()
3333
);
3434
let env = &Arc::new(program.environment());
@@ -55,7 +55,7 @@ fn solve_goal_fixed_num_answers(program_text: &str, goals: Vec<(usize, usize, &s
5555
let program = &Arc::new(
5656
parse_and_lower_program(
5757
&program_text[1..program_text.len() - 1],
58-
SolverChoice::slg()
58+
SolverChoice::default()
5959
).unwrap()
6060
);
6161
let env = &Arc::new(program.environment());

src/solve/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ macro_rules! test {
4747
test!(@program[$program]
4848
@parsed_goals[
4949
$($parsed_goals)*
50-
(stringify!($goal), SolverChoice::slg(), $expected)
50+
(stringify!($goal), SolverChoice::default(), $expected)
5151
]
5252
@unparsed_goals[$($unparsed_goals)*])
5353
};

src/test_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ macro_rules! lowering_success {
2424
assert!(program_text.ends_with("}"));
2525
let result = parse_and_lower_program(
2626
&program_text[1..program_text.len()-1],
27-
$crate::solve::SolverChoice::slg()
27+
$crate::solve::SolverChoice::default()
2828
);
2929
if let Err(ref e) = result {
3030
println!("lowering error: {}", e);
@@ -42,7 +42,7 @@ macro_rules! lowering_error {
4242
assert!(program_text.ends_with("}"));
4343
let error = parse_and_lower_program(
4444
&program_text[1..program_text.len()-1],
45-
$crate::solve::SolverChoice::slg()
45+
$crate::solve::SolverChoice::default()
4646
).unwrap_err();
4747
let expected = $crate::errors::Error::from($expected);
4848
assert_eq!(

0 commit comments

Comments
 (0)