Skip to content

Commit ca57c48

Browse files
committed
Eliminated mutable reference requirement and substitution clones.
1 parent 5a90d4e commit ca57c48

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

chalk-engine/src/context/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ pub trait Environment<C: Context, I: InferenceContext<C>>: Debug + Clone {
291291

292292
pub trait CanonicalExClause<C: Context>: Debug {
293293
/// Extracts the inner normalized substitution.
294-
fn inference_normalized_subst(&self) -> C::InferenceNormalizedSubst;
294+
fn inference_normalized_subst(&self) -> &C::InferenceNormalizedSubst;
295295
}
296296

297297
pub trait CanonicalConstrainedSubst<C: Context>: Clone + Debug + Eq + Hash + Ord {
298298
/// True if this solution has no region constraints.
299299
fn empty_constraints(&self) -> bool;
300300

301301
/// Extracts the inner normalized substitution.
302-
fn inference_normalized_subst(&self) -> C::InferenceNormalizedSubst;
302+
fn inference_normalized_subst(&self) -> &C::InferenceNormalizedSubst;
303303
}
304304

305305
pub trait DomainGoal<C: Context, I: InferenceContext<C>>: Debug {
@@ -358,6 +358,6 @@ pub trait AnswerStream<C: Context> {
358358
/// if we find any answer for which `test` returns true.
359359
fn any_future_answer(
360360
&mut self,
361-
test: impl FnMut(&mut C::InferenceNormalizedSubst) -> bool,
361+
test: impl FnMut(&C::InferenceNormalizedSubst) -> bool,
362362
) -> bool;
363363
}

chalk-engine/src/forest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ where
174174

175175
fn any_future_answer(
176176
&mut self,
177-
test: impl FnMut(&mut C::InferenceNormalizedSubst) -> bool,
177+
test: impl FnMut(&C::InferenceNormalizedSubst) -> bool,
178178
) -> bool {
179179
self.forest.any_future_answer(self.table, self.answer, test)
180180
}

chalk-engine/src/logic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ impl<C: Context> Forest<C> {
107107
&mut self,
108108
table: TableIndex,
109109
answer: AnswerIndex,
110-
mut test: impl FnMut(&mut C::InferenceNormalizedSubst) -> bool,
110+
mut test: impl FnMut(&C::InferenceNormalizedSubst) -> bool,
111111
) -> bool {
112112
if let Some(answer) = self.tables[table].answer(answer) {
113113
info!("answer cached = {:?}", answer);
114-
return test(&mut answer.subst.inference_normalized_subst());
114+
return test(answer.subst.inference_normalized_subst());
115115
}
116116

117117
self.tables[table].strands_mut().any(|strand| {
118-
test(&mut strand.canonical_ex_clause.inference_normalized_subst())
118+
test(strand.canonical_ex_clause.inference_normalized_subst())
119119
})
120120
}
121121

src/solve/slg/implementation/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl context::Environment<SlgContext, SlgContext> for Arc<Environment> {
240240
}
241241

242242
impl Substitution {
243-
fn may_invalidate(&mut self, subst: &Canonical<Substitution>) -> bool {
243+
fn may_invalidate(&self, subst: &Canonical<Substitution>) -> bool {
244244
self.parameters
245245
.iter()
246246
.zip(&subst.value.parameters)
@@ -413,8 +413,8 @@ impl context::DomainGoal<SlgContext, SlgContext> for DomainGoal {
413413
}
414414

415415
impl context::CanonicalExClause<SlgContext> for Canonical<ExClause<SlgContext, SlgContext>> {
416-
fn inference_normalized_subst(&self) -> Substitution {
417-
self.value.subst.clone()
416+
fn inference_normalized_subst(&self) -> &Substitution {
417+
&self.value.subst
418418
}
419419
}
420420

@@ -423,8 +423,8 @@ impl context::CanonicalConstrainedSubst<SlgContext> for Canonical<ConstrainedSub
423423
self.value.constraints.is_empty()
424424
}
425425

426-
fn inference_normalized_subst(&self) -> Substitution {
427-
self.value.subst.clone()
426+
fn inference_normalized_subst(&self) -> &Substitution {
427+
&self.value.subst
428428
}
429429
}
430430

0 commit comments

Comments
 (0)