Skip to content

Commit 40369a2

Browse files
committed
Pass interner to IntoBindersAndValue trait associated fn.
1 parent 1d1be29 commit 40369a2

File tree

5 files changed

+27
-31
lines changed

5 files changed

+27
-31
lines changed

chalk-solve/src/ext.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,12 @@ impl<I: Interner> GoalExt<I> for Goal<I> {
7070
let InEnvironment { environment, goal } = env_goal;
7171
match goal.data(interner) {
7272
GoalData::Quantified(QuantifierKind::ForAll, subgoal) => {
73-
let subgoal =
74-
infer.instantiate_binders_universally(interner, (subgoal, interner));
73+
let subgoal = infer.instantiate_binders_universally(interner, subgoal);
7574
env_goal = InEnvironment::new(&environment, subgoal);
7675
}
7776

7877
GoalData::Quantified(QuantifierKind::Exists, subgoal) => {
79-
let subgoal =
80-
infer.instantiate_binders_existentially(interner, (subgoal, interner));
78+
let subgoal = infer.instantiate_binders_existentially(interner, subgoal);
8179
env_goal = InEnvironment::new(&environment, subgoal);
8280
}
8381

chalk-solve/src/infer/instantiate.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,28 @@ impl<I: Interner> InferenceTable<I> {
6262
}
6363

6464
/// Variant on `instantiate_in` that takes a `Binders<T>`.
65-
pub(crate) fn instantiate_binders_existentially<T>(
65+
pub(crate) fn instantiate_binders_existentially<'a, T>(
6666
&mut self,
67-
interner: &I,
68-
arg: impl IntoBindersAndValue<Value = T>,
67+
interner: &'a I,
68+
arg: impl IntoBindersAndValue<'a, I, Value = T>,
6969
) -> T::Result
7070
where
7171
T: Fold<I>,
7272
{
73-
let (binders, value) = arg.into_binders_and_value();
73+
let (binders, value) = arg.into_binders_and_value(interner);
7474
let max_universe = self.max_universe;
7575
self.instantiate_in(interner, max_universe, binders, &value)
7676
}
7777

78-
pub(crate) fn instantiate_binders_universally<T>(
78+
pub(crate) fn instantiate_binders_universally<'a, T>(
7979
&mut self,
80-
interner: &I,
81-
arg: impl IntoBindersAndValue<Value = T>,
80+
interner: &'a I,
81+
arg: impl IntoBindersAndValue<'a, I, Value = T>,
8282
) -> T::Result
8383
where
8484
T: Fold<I>,
8585
{
86-
let (binders, value) = arg.into_binders_and_value();
86+
let (binders, value) = arg.into_binders_and_value(interner);
8787
let ui = self.new_universe();
8888
let parameters: Vec<_> = binders
8989
.into_iter()
@@ -103,34 +103,34 @@ impl<I: Interner> InferenceTable<I> {
103103
}
104104
}
105105

106-
pub(crate) trait IntoBindersAndValue {
106+
pub(crate) trait IntoBindersAndValue<'a, I: Interner> {
107107
type Binders: IntoIterator<Item = ParameterKind<()>>;
108108
type Value;
109109

110-
fn into_binders_and_value(self) -> (Self::Binders, Self::Value);
110+
fn into_binders_and_value(self, interner: &'a I) -> (Self::Binders, Self::Value);
111111
}
112112

113-
impl<'a, I, T> IntoBindersAndValue for (&'a Binders<T>, &'a I)
113+
impl<'a, I, T> IntoBindersAndValue<'a, I> for &'a Binders<T>
114114
where
115115
I: Interner,
116116
T: HasInterner<Interner = I>,
117117
{
118118
type Binders = std::iter::Cloned<std::slice::Iter<'a, ParameterKind<()>>>;
119119
type Value = &'a T;
120120

121-
fn into_binders_and_value(self) -> (Self::Binders, Self::Value) {
122-
(self.0.binders.iter(self.1).cloned(), self.0.skip_binders())
121+
fn into_binders_and_value(self, interner: &'a I) -> (Self::Binders, Self::Value) {
122+
(self.binders.iter(interner).cloned(), self.skip_binders())
123123
}
124124
}
125125

126-
impl<'a, I> IntoBindersAndValue for &'a Fn<I>
126+
impl<'a, I> IntoBindersAndValue<'a, I> for &'a Fn<I>
127127
where
128128
I: Interner,
129129
{
130130
type Binders = std::iter::Map<std::ops::Range<usize>, fn(usize) -> chalk_ir::ParameterKind<()>>;
131131
type Value = &'a Substitution<I>;
132132

133-
fn into_binders_and_value(self) -> (Self::Binders, Self::Value) {
133+
fn into_binders_and_value(self, _interner: &'a I) -> (Self::Binders, Self::Value) {
134134
fn make_lifetime(_: usize) -> ParameterKind<()> {
135135
ParameterKind::Lifetime(())
136136
}
@@ -140,11 +140,11 @@ where
140140
}
141141
}
142142

143-
impl<'a, T> IntoBindersAndValue for (&'a Vec<ParameterKind<()>>, &'a T) {
143+
impl<'a, T, I: Interner> IntoBindersAndValue<'a, I> for (&'a Vec<ParameterKind<()>>, &'a T) {
144144
type Binders = std::iter::Cloned<std::slice::Iter<'a, ParameterKind<()>>>;
145145
type Value = &'a T;
146146

147-
fn into_binders_and_value(self) -> (Self::Binders, Self::Value) {
147+
fn into_binders_and_value(self, _interner: &'a I) -> (Self::Binders, Self::Value) {
148148
(self.0.iter().cloned(), &self.1)
149149
}
150150
}

chalk-solve/src/infer/unify.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,15 @@ impl<'t, I: Interner> Unifier<'t, I> {
185185
}
186186
}
187187

188-
fn unify_binders<T, R>(
188+
fn unify_binders<'a, T, R>(
189189
&mut self,
190-
a: impl IntoBindersAndValue<Value = T> + Copy + Debug,
191-
b: impl IntoBindersAndValue<Value = T> + Copy + Debug,
190+
a: impl IntoBindersAndValue<'a, I, Value = T> + Copy + Debug,
191+
b: impl IntoBindersAndValue<'a, I, Value = T> + Copy + Debug,
192192
) -> Fallible<()>
193193
where
194194
T: Fold<I, Result = R>,
195195
R: Zip<I> + Fold<I, Result = R>,
196+
't: 'a,
196197
{
197198
// for<'a...> T == for<'b...> U
198199
//
@@ -354,7 +355,6 @@ impl<'i, I: Interner> Zipper<'i, I> for Unifier<'i, I> {
354355
where
355356
T: HasInterner<Interner = I> + Zip<I> + Fold<I, Result = T>,
356357
{
357-
let interner = self.interner();
358358
// The binders that appear in types (apart from quantified types, which are
359359
// handled in `unify_ty`) appear as part of `dyn Trait` and `impl Trait` types.
360360
//
@@ -366,7 +366,7 @@ impl<'i, I: Interner> Zipper<'i, I> for Unifier<'i, I> {
366366
//
367367
// In both cases we can use the same `unify_binders` routine.
368368

369-
self.unify_binders((a, interner), (b, interner))
369+
self.unify_binders(a, b)
370370
}
371371

372372
fn interner(&self) -> &'i I {

chalk-solve/src/solve/slg.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,15 @@ impl<I: Interner> context::InferenceTable<SlgContext<I>> for TruncatingInference
323323

324324
impl<I: Interner> context::UnificationOps<SlgContext<I>> for TruncatingInferenceTable<I> {
325325
fn instantiate_binders_universally(&mut self, interner: &I, arg: &Binders<Goal<I>>) -> Goal<I> {
326-
self.infer
327-
.instantiate_binders_universally(interner, (arg, interner))
326+
self.infer.instantiate_binders_universally(interner, arg)
328327
}
329328

330329
fn instantiate_binders_existentially(
331330
&mut self,
332331
interner: &I,
333332
arg: &Binders<Goal<I>>,
334333
) -> Goal<I> {
335-
self.infer
336-
.instantiate_binders_existentially(interner, (arg, interner))
334+
self.infer.instantiate_binders_existentially(interner, arg)
337335
}
338336

339337
fn debug_ex_clause<'v>(

chalk-solve/src/solve/slg/resolvent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<I: Interner> context::ResolventOps<SlgContext<I>> for TruncatingInferenceTa
8888
ProgramClauseData::Implies(implication) => implication.clone(),
8989
ProgramClauseData::ForAll(implication) => self
9090
.infer
91-
.instantiate_binders_existentially(interner, (implication, interner)),
91+
.instantiate_binders_existentially(interner, implication),
9292
};
9393
debug!("consequence = {:?}", consequence);
9494
debug!("conditions = {:?}", conditions);

0 commit comments

Comments
 (0)