Skip to content

Commit bf332ae

Browse files
committed
Finish removing types on Context
1 parent 3cdc628 commit bf332ae

File tree

21 files changed

+161
-420
lines changed

21 files changed

+161
-420
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chalk-engine/src/context.rs

Lines changed: 36 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ use crate::hh::HhGoal;
99
use crate::{CompleteAnswer, ExClause};
1010
use chalk_base::results::{Fallible, Floundered};
1111
use chalk_ir::interner::Interner;
12-
use chalk_ir::{Canonical, ConstrainedSubst, Constraint, DomainGoal, Environment, GenericArg, Goal, InEnvironment, Substitution, UCanonical};
12+
use chalk_ir::{AnswerSubst, Binders, Canonical, ConstrainedSubst, Constraint, DomainGoal, Environment, GenericArg, Goal, InEnvironment, ProgramClause, ProgramClauses, Substitution, UCanonical, UniverseMap};
1313
use std::fmt::Debug;
14-
use std::hash::Hash;
1514

1615
/// The "context" in which the SLG solver operates. It defines all the
1716
/// types that the SLG solver may need to refer to, as well as a few
@@ -33,57 +32,19 @@ use std::hash::Hash;
3332
/// FIXME: Clone and Debug bounds are just for easy derive, they are
3433
/// not actually necessary. But dang are they convenient.
3534
pub trait Context<I: Interner>: Clone + Debug {
36-
/// A map between universes. These are produced when
37-
/// u-canonicalizing something; they map canonical results back to
38-
/// the universes from the original.
39-
type UniverseMap: Clone + Debug;
40-
41-
/// Extracted from a canonicalized substitution or canonicalized ex clause, this is the type of
42-
/// substitution that is fully normalized with respect to inference variables.
43-
type InferenceNormalizedSubst: Debug;
44-
45-
/// A u-canonicalized `GoalInEnvironment` -- this is one where the
46-
/// free universes are renumbered to consecutive integers starting
47-
/// from U1 (but preserving their relative order).
48-
type UCanonicalGoalInEnvironment: Debug + Clone + Eq + Hash;
49-
5035
/// A final solution that is passed back to the user. This is
5136
/// completely opaque to the SLG solver; it is produced by
5237
/// `make_solution`.
5338
type Solution;
5439

55-
/// Part of an answer: the canonical version of a substitution,
56-
/// region constraints, and delayed literals.
57-
type CanonicalAnswerSubst: Clone + Debug + Eq + Hash;
58-
5940
/// Represents an inference table.
6041
type InferenceTable: InferenceTable<I, Self> + Clone;
6142

62-
/// A "higher-order" goal, quantified over some types and/or
63-
/// lifetimes. When you have a quantification, like `forall<T> { G
64-
/// }` or `exists<T> { G }`, this represents the `<T> { G }` part.
65-
///
66-
/// (In Lambda Prolog, this would be a "lambda predicate", like `T
67-
/// \ Goal`).
68-
type BindersGoal: Debug;
69-
70-
/// A rule like `DomainGoal :- Goal`.
71-
///
72-
/// `resolvent_clause` combines a program-clause and a concrete
73-
/// goal we are trying to solve to produce an ex-clause.
74-
type ProgramClause: Debug;
75-
76-
/// A vector of program clauses.
77-
type ProgramClauses: Debug;
78-
7943
/// How to relate two kinds when unifying: for example in rustc, we
8044
/// may want to unify parameters either for the sub-typing relation or for
8145
/// the equality relation.
8246
type Variance;
8347

84-
/// The type used to store concrete representations of "core types" from chalk-ir.
85-
type Interner;
86-
8748
/// Given an environment and a goal, glue them together to create
8849
/// a `GoalInEnvironment`.
8950
fn goal_in_environment(
@@ -94,24 +55,24 @@ pub trait Context<I: Interner>: Clone + Debug {
9455
/// Extracts the inner normalized substitution from a canonical ex-clause.
9556
fn inference_normalized_subst_from_ex_clause(
9657
canon_ex_clause: &Canonical<ExClause<I>>,
97-
) -> &Self::InferenceNormalizedSubst;
58+
) -> &Substitution<I>;
9859

9960
/// Extracts the inner normalized substitution from a canonical constraint subst.
10061
fn inference_normalized_subst_from_subst(
101-
canon_ex_clause: &Self::CanonicalAnswerSubst,
102-
) -> &Self::InferenceNormalizedSubst;
62+
canon_ex_clause: &Canonical<AnswerSubst<I>>,
63+
) -> &Substitution<I>;
10364

10465
/// True if this solution has no region constraints.
105-
fn empty_constraints(ccs: &Self::CanonicalAnswerSubst) -> bool;
66+
fn empty_constraints(ccs: &Canonical<AnswerSubst<I>>) -> bool;
10667

10768
fn canonical(u_canon: &UCanonical<InEnvironment<Goal<I>>>) -> &Canonical<InEnvironment<Goal<I>>>;
10869

109-
fn has_delayed_subgoals(canonical_subst: &Self::CanonicalAnswerSubst) -> bool;
70+
fn has_delayed_subgoals(canonical_subst: &Canonical<AnswerSubst<I>>) -> bool;
11071

11172
fn num_universes(_: &UCanonical<InEnvironment<Goal<I>>>) -> usize;
11273

11374
fn canonical_constrained_subst_from_canonical_constrained_answer(
114-
canonical_subst: &Self::CanonicalAnswerSubst,
75+
canonical_subst: &Canonical<AnswerSubst<I>>,
11576
) -> Canonical<ConstrainedSubst<I>>;
11677

11778
fn goal_from_goal_in_environment(goal: &InEnvironment<Goal<I>>) -> &Goal<I>;
@@ -137,10 +98,10 @@ pub trait ContextOps<I: Interner, C: Context<I>>: Sized + Clone + Debug + Aggreg
13798
environment: &Environment<I>,
13899
goal: &DomainGoal<I>,
139100
infer: &mut C::InferenceTable,
140-
) -> Result<Vec<C::ProgramClause>, Floundered>;
101+
) -> Result<Vec<ProgramClause<I>>, Floundered>;
141102

142103
// Used by: simplify
143-
fn add_clauses(&self, env: &Environment<I>, clauses: C::ProgramClauses) -> Environment<I>;
104+
fn add_clauses(&self, env: &Environment<I>, clauses: ProgramClauses<I>) -> Environment<I>;
144105

145106
/// Create an inference table for processing a new goal and instantiate that goal
146107
/// in that context, returning "all the pieces".
@@ -169,7 +130,7 @@ pub trait ContextOps<I: Interner, C: Context<I>>: Sized + Clone + Debug + Aggreg
169130
fn instantiate_answer_subst(
170131
&self,
171132
num_universes: usize,
172-
answer: &C::CanonicalAnswerSubst,
133+
answer: &Canonical<AnswerSubst<I>>,
173134
) -> (
174135
C::InferenceTable,
175136
Substitution<I>,
@@ -194,7 +155,7 @@ pub trait ContextOps<I: Interner, C: Context<I>>: Sized + Clone + Debug + Aggreg
194155
/// but for the universes of universally quantified names.
195156
fn map_goal_from_canonical(
196157
&self,
197-
_: &C::UniverseMap,
158+
_: &UniverseMap,
198159
value: &Canonical<InEnvironment<Goal<I>>>,
199160
) -> Canonical<InEnvironment<Goal<I>>>;
200161

@@ -204,19 +165,19 @@ pub trait ContextOps<I: Interner, C: Context<I>>: Sized + Clone + Debug + Aggreg
204165
/// names.
205166
fn map_subst_from_canonical(
206167
&self,
207-
_: &C::UniverseMap,
208-
value: &C::CanonicalAnswerSubst,
209-
) -> C::CanonicalAnswerSubst;
168+
_: &UniverseMap,
169+
value: &Canonical<AnswerSubst<I>>,
170+
) -> Canonical<AnswerSubst<I>>;
210171

211-
fn interner(&self) -> &C::Interner;
172+
fn interner(&self) -> &I;
212173

213174
/// Upcast this domain goal into a more general goal.
214175
fn into_goal(&self, domain_goal: DomainGoal<I>) -> Goal<I>;
215176

216177
fn is_trivial_substitution(
217178
&self,
218179
u_canon: &UCanonical<InEnvironment<Goal<I>>>,
219-
canonical_subst: &C::CanonicalAnswerSubst,
180+
canonical_subst: &Canonical<AnswerSubst<I>>,
220181
) -> bool;
221182

222183
/// Convert the context's goal type into the `HhGoal` type that
@@ -249,59 +210,59 @@ pub trait UnificationOps<I: Interner, C: Context<I>> {
249210
// Used by: simplify
250211
fn instantiate_binders_universally(
251212
&mut self,
252-
interner: &C::Interner,
253-
arg: &C::BindersGoal,
213+
interner: &I,
214+
arg: &Binders<Goal<I>>,
254215
) -> Goal<I>;
255216

256217
// Used by: simplify
257218
fn instantiate_binders_existentially(
258219
&mut self,
259-
interner: &C::Interner,
260-
arg: &C::BindersGoal,
220+
interner: &I,
221+
arg: &Binders<Goal<I>>,
261222
) -> Goal<I>;
262223

263224
// Used by: logic (but for debugging only)
264225
fn debug_ex_clause<'v>(
265226
&mut self,
266-
interner: &C::Interner,
227+
interner: &I,
267228
value: &'v ExClause<I>,
268229
) -> Box<dyn Debug + 'v>;
269230

270231
// Used by: logic
271232
fn fully_canonicalize_goal(
272233
&mut self,
273-
interner: &C::Interner,
234+
interner: &I,
274235
value: &InEnvironment<Goal<I>>,
275-
) -> (UCanonical<InEnvironment<Goal<I>>>, C::UniverseMap);
236+
) -> (UCanonical<InEnvironment<Goal<I>>>, UniverseMap);
276237

277238
// Used by: logic
278239
fn canonicalize_ex_clause(
279240
&mut self,
280-
interner: &C::Interner,
241+
interner: &I,
281242
value: &ExClause<I>,
282243
) -> Canonical<ExClause<I>>;
283244

284245
// Used by: logic
285246
fn canonicalize_constrained_subst(
286247
&mut self,
287-
interner: &C::Interner,
248+
interner: &I,
288249
subst: Substitution<I>,
289250
constraints: Vec<InEnvironment<Constraint<I>>>,
290251
) -> Canonical<ConstrainedSubst<I>>;
291252

292253
// Used by: logic
293254
fn canonicalize_answer_subst(
294255
&mut self,
295-
interner: &C::Interner,
256+
interner: &I,
296257
subst: Substitution<I>,
297258
constraints: Vec<InEnvironment<Constraint<I>>>,
298259
delayed_subgoals: Vec<InEnvironment<Goal<I>>>,
299-
) -> C::CanonicalAnswerSubst;
260+
) -> Canonical<AnswerSubst<I>>;
300261

301262
// Used by: logic
302263
fn invert_goal(
303264
&mut self,
304-
interner: &C::Interner,
265+
interner: &I,
305266
value: &InEnvironment<Goal<I>>,
306267
) -> Option<InEnvironment<Goal<I>>>;
307268

@@ -313,7 +274,7 @@ pub trait UnificationOps<I: Interner, C: Context<I>> {
313274
// Used by: simplify
314275
fn unify_generic_args_into_ex_clause(
315276
&mut self,
316-
interner: &C::Interner,
277+
interner: &I,
317278
environment: &Environment<I>,
318279
variance: C::Variance,
319280
a: &GenericArg<I>,
@@ -338,12 +299,12 @@ pub trait TruncateOps<I: Interner, C: Context<I>> {
338299
/// Check if `subgoal` is too large
339300
fn goal_needs_truncation(
340301
&mut self,
341-
interner: &C::Interner,
302+
interner: &I,
342303
subgoal: &InEnvironment<Goal<I>>,
343304
) -> bool;
344305

345306
/// Check if `subst` is too large
346-
fn answer_needs_truncation(&mut self, interner: &C::Interner, subst: &Substitution<I>) -> bool;
307+
fn answer_needs_truncation(&mut self, interner: &I, subst: &Substitution<I>) -> bool;
347308
}
348309

349310
pub trait ResolventOps<I: Interner, C: Context<I>> {
@@ -354,20 +315,20 @@ pub trait ResolventOps<I: Interner, C: Context<I>> {
354315
/// The bindings in `infer` are unaffected by this operation.
355316
fn resolvent_clause(
356317
&mut self,
357-
interner: &C::Interner,
318+
interner: &I,
358319
environment: &Environment<I>,
359320
goal: &DomainGoal<I>,
360321
subst: &Substitution<I>,
361-
clause: &C::ProgramClause,
322+
clause: &ProgramClause<I>,
362323
) -> Fallible<ExClause<I>>;
363324

364325
fn apply_answer_subst(
365326
&mut self,
366-
interner: &C::Interner,
327+
interner: &I,
367328
ex_clause: &mut ExClause<I>,
368329
selected_goal: &InEnvironment<Goal<I>>,
369330
answer_table_goal: &Canonical<InEnvironment<Goal<I>>>,
370-
canonical_answer_subst: &C::CanonicalAnswerSubst,
331+
canonical_answer_subst: &Canonical<AnswerSubst<I>>,
371332
) -> Fallible<()>;
372333
}
373334

@@ -438,5 +399,5 @@ pub trait AnswerStream<I: Interner, C: Context<I>> {
438399

439400
/// Invokes `test` with each possible future answer, returning true immediately
440401
/// if we find any answer for which `test` returns true.
441-
fn any_future_answer(&self, test: impl Fn(&C::InferenceNormalizedSubst) -> bool) -> bool;
402+
fn any_future_answer(&self, test: impl Fn(&Substitution<I>) -> bool) -> bool;
442403
}

chalk-engine/src/forest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use crate::{TableIndex, TimeStamp};
66
use std::fmt::Display;
77

88
use chalk_ir::interner::Interner;
9-
use chalk_ir::{Canonical, ConstrainedSubst, Goal, InEnvironment, UCanonical};
9+
use chalk_ir::{Canonical, ConstrainedSubst, Goal, InEnvironment, Substitution, UCanonical};
1010

1111
pub struct Forest<I: Interner, C: Context<I>> {
1212
context: C,
13-
pub(crate) tables: Tables<I, C>,
13+
pub(crate) tables: Tables<I>,
1414

1515
/// This is a clock which always increases. It is
1616
/// incremented every time a new subgoal is followed.
@@ -199,7 +199,7 @@ impl<'me, I: Interner, C: Context<I>, CO: ContextOps<I, C>> AnswerStream<I, C> f
199199
answer
200200
}
201201

202-
fn any_future_answer(&self, test: impl Fn(&C::InferenceNormalizedSubst) -> bool) -> bool {
202+
fn any_future_answer(&self, test: impl Fn(&Substitution<I>) -> bool) -> bool {
203203
self.forest.any_future_answer(self.table, self.answer, test)
204204
}
205205
}

chalk-engine/src/hh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use crate::context::Context;
22

33
use chalk_ir::interner::Interner;
4-
use chalk_ir::{DomainGoal, GenericArg, Goal};
4+
use chalk_ir::{Binders, DomainGoal, GenericArg, Goal, ProgramClauses};
55

66
#[derive(Clone, PartialEq, Eq, Hash)]
77
/// A general goal; this is the full range of questions you can pose to Chalk.
88
pub enum HhGoal<I: Interner, C: Context<I>> {
99
/// Introduces a binding at depth 0, shifting other bindings up
1010
/// (deBruijn index).
11-
ForAll(C::BindersGoal),
12-
Exists(C::BindersGoal),
13-
Implies(C::ProgramClauses, Goal<I>),
11+
ForAll(Binders<Goal<I>>),
12+
Exists(Binders<Goal<I>>),
13+
Implies(ProgramClauses<I>, Goal<I>),
1414
All(Vec<Goal<I>>),
1515
Not(Goal<I>),
1616
Unify(C::Variance, GenericArg<I>, GenericArg<I>),

chalk-engine/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@
5656
#[macro_use]
5757
extern crate chalk_base;
5858

59-
use crate::context::Context;
6059
use std::cmp::min;
6160
use std::usize;
6261

6362
use chalk_ir::interner::Interner;
64-
use chalk_ir::{Canonical, Constraint, ConstrainedSubst, Goal, InEnvironment, Substitution};
63+
use chalk_ir::{AnswerSubst, Canonical, Constraint, ConstrainedSubst, Goal, InEnvironment, Substitution};
6564

6665
mod boring_impls;
6766
pub mod context;
@@ -190,12 +189,12 @@ pub struct FlounderedSubgoal<I: Interner> {
190189
/// goal for a particular table (modulo delayed literals). It contains
191190
/// a substitution
192191
#[derive(Clone, Debug)]
193-
pub struct Answer<I: Interner, C: Context<I>> {
192+
pub struct Answer<I: Interner> {
194193
/// Contains values for the unbound inference variables for which
195194
/// the table is true, along with any delayed subgoals (Which must
196195
/// still be proven) and region constrained (which must still be
197196
/// proven, but not by chalk).
198-
pub subst: C::CanonicalAnswerSubst,
197+
pub subst: Canonical<AnswerSubst<I>>,
199198

200199
/// If this flag is set, then the answer could be neither proven
201200
/// nor disproven. This could be the size of the answer exceeded

0 commit comments

Comments
 (0)