Skip to content

Commit b5040c2

Browse files
committed
move things out of map_ref call and comment
1 parent d208e4e commit b5040c2

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

chalk-solve/src/goal_builder.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,32 @@ impl<'i, I: Interner> GoalBuilder<'i, I> {
131131
G: CastTo<Goal<I>>,
132132
{
133133
let interner = self.interner();
134+
135+
// Make an identity mapping `[0 => ^0.0, 1 => ^0.1, ..]`
136+
// and so forth. This substitution is mapping from the `<P0..Pn>` variables
137+
// in `binders` to the corresponding `P0..Pn` variables we're about to
138+
// introduce in the form of a `forall<P0..Pn>` goal. Of course, it's
139+
// actually an identity mapping, since this `forall` will be the innermost
140+
// debruijn binder and so forth, so there's no actual reason to
141+
// *do* the substitution, since it would effectively just be a clone.
142+
let substitution: Substitution<I> = Substitution::from(
143+
interner,
144+
binders
145+
.binders
146+
.iter()
147+
.zip(0..)
148+
.map(|p| p.to_parameter(interner)),
149+
);
150+
151+
// Shift passthru into one level of binder, to account for the `forall<P0..Pn>`
152+
// we are about to introduce.
153+
let passthru_shifted = passthru.shifted_in(self.interner());
154+
155+
// Invoke `body` function, which returns a goal, and wrap that goal in the binders
156+
// from `binders`, and finally a `forall` or `exists` goal.
134157
let bound_goal = binders.map_ref(|bound_value| {
135-
let substitution: Substitution<I> = Substitution::from(
136-
interner,
137-
binders
138-
.binders
139-
.iter()
140-
.zip(0..)
141-
.map(|p| p.to_parameter(interner)),
142-
);
143-
let passthru_shifted = passthru.shifted_in(self.interner());
144-
let result = body(self, substitution, bound_value, passthru_shifted);
145-
result.cast(self.interner())
158+
body(self, substitution, bound_value, passthru_shifted).cast(interner)
146159
});
147-
GoalData::Quantified(quantifier_kind, bound_goal).intern(self.interner())
160+
GoalData::Quantified(quantifier_kind, bound_goal).intern(interner)
148161
}
149162
}

0 commit comments

Comments
 (0)