Skip to content

Commit 1444a69

Browse files
committed
Address most review nits and questions
1 parent 3bd7bf4 commit 1444a69

File tree

5 files changed

+181
-109
lines changed

5 files changed

+181
-109
lines changed

src/bin/repl.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ fn goal(text: &str, prog: &Program) -> Result<()> {
120120
let goal = chalk_parse::parse_goal(text)?.lower(&*prog.ir)?;
121121
let overflow_depth = 10;
122122
let mut solver = Solver::new(&prog.env, overflow_depth);
123-
match solver.solve_goal(*goal) {
123+
let goal = ir::Canonical {
124+
value: ir::InEnvironment::new(&ir::Environment::new(), *goal),
125+
binders: vec![],
126+
};
127+
match solver.solve_goal(goal) {
124128
Ok(v) => println!("{}\n", v),
125129
Err(e) => println!("No possible solution: {}\n", e),
126130
}

src/ir/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct ProgramEnvironment {
4848
/// For each trait (used for debugging):
4949
pub trait_data: HashMap<ItemId, TraitDatum>,
5050

51-
/// For each trait (used for debugging):
51+
/// For each associated type (used for debugging):
5252
pub associated_ty_data: HashMap<ItemId, AssociatedTyDatum>,
5353

5454
/// Compiled forms of the above:
@@ -97,7 +97,11 @@ impl Environment {
9797
}
9898

9999
/// Generate the full set of clauses that are "syntactically implied" by the
100-
/// clauses in this environment.
100+
/// clauses in this environment. Currently this consists of two kinds of expansions:
101+
///
102+
/// - Supertraits are added, so `T: Ord` would expand to `T: Ord, T: PartialOrd`
103+
/// - Projections imply that a trait is implemented, to `T: Iterator<Item=Foo>` expands to
104+
/// `T: Iterator, T: Iterator<Item=Foo>`
101105
pub fn elaborated_clauses(&self, program: &ProgramEnvironment) -> impl Iterator<Item = DomainGoal> {
102106
let mut set = HashSet::new();
103107
set.extend(self.clauses.iter().cloned());
@@ -391,10 +395,10 @@ pub struct TraitRef {
391395
pub parameters: Vec<Parameter>,
392396
}
393397

394-
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
395398
/// A "domain goal" is a goal that is directly about Rust, rather than a pure
396399
/// logical statement. As much as possible, the Chalk solver should avoid
397400
/// decomposing this enum, and instead treat its values opaquely.
401+
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
398402
pub enum DomainGoal {
399403
Implemented(TraitRef),
400404
/// Is the projection something we know definitively from impls?
@@ -547,21 +551,21 @@ pub enum QuantifierKind {
547551
ForAll, Exists
548552
}
549553

550-
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
551554
/// A constraint on lifetimes.
552555
///
553556
/// When we search for solutions within the trait system, we essentially ignore
554557
/// lifetime constraints, instead gathering them up to return with our solution
555558
/// for later checking. This allows for decoupling between type and region
556559
/// checking in the compiler.
560+
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
557561
pub enum Constraint {
558562
LifetimeEq(Lifetime, Lifetime),
559563
}
560564

561565
/// A mapping of inference variables to instantiations thereof.
562-
// Uses BTreeMap for extracting in order (mostly for debugging/testing)
563566
#[derive(Clone, Debug, PartialEq, Eq)]
564567
pub struct Substitution {
568+
// Use BTreeMap for extracting in order (mostly for debugging/testing)
565569
pub tys: BTreeMap<TyInferenceVariable, Ty>,
566570
pub lifetimes: BTreeMap<LifetimeInferenceVariable, Lifetime>,
567571
}

0 commit comments

Comments
 (0)