Skip to content

Commit aee6b48

Browse files
committed
perf: Re-use scratch allocations for try_evaluate_obligations
1 parent 87536b0 commit aee6b48

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crates/hir-ty/src/next_solver/fulfill.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct FulfillmentCtxt<'db> {
4848
/// use the context in exactly this snapshot.
4949
#[expect(unused)]
5050
usable_in_snapshot: usize,
51+
try_evaluate_obligations_scratch: PendingObligations<'db>,
5152
}
5253

5354
#[derive(Default, Debug, Clone)]
@@ -115,6 +116,7 @@ impl<'db> FulfillmentCtxt<'db> {
115116
FulfillmentCtxt {
116117
obligations: Default::default(),
117118
usable_in_snapshot: infcx.num_open_snapshots(),
119+
try_evaluate_obligations_scratch: Default::default(),
118120
}
119121
}
120122
}
@@ -162,12 +164,12 @@ impl<'db> FulfillmentCtxt<'db> {
162164
// and select. They should use a different `ObligationCtxt` instead. Then we'll be also able
163165
// to not put the obligations queue in `InferenceTable`'s snapshots.
164166
// assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots());
167+
self.try_evaluate_obligations_scratch.clear();
165168
let mut errors = Vec::new();
166-
let mut obligations = Vec::new();
167169
loop {
168170
let mut any_changed = false;
169-
obligations.extend(self.obligations.drain_pending(|_| true));
170-
for (mut obligation, stalled_on) in obligations.drain(..) {
171+
self.try_evaluate_obligations_scratch.extend(self.obligations.drain_pending(|_| true));
172+
for (mut obligation, stalled_on) in self.try_evaluate_obligations_scratch.drain(..) {
171173
if obligation.recursion_depth >= infcx.interner.recursion_limit() {
172174
self.obligations.on_fulfillment_overflow(infcx);
173175
// Only return true errors that we have accumulated while processing.

0 commit comments

Comments
 (0)