Split process_obligation
in two.
Because it really has two halves: - A read-only part that checks if further work is needed. - The further work part, which is much less hot. This makes things a bit clearer and nicer.
This commit is contained in:
parent
281229a6d3
commit
32741d5d16
3 changed files with 44 additions and 46 deletions
|
@ -96,6 +96,8 @@ pub trait ObligationProcessor {
|
|||
type Obligation: ForestObligation;
|
||||
type Error: Debug;
|
||||
|
||||
fn needs_process_obligation(&self, obligation: &Self::Obligation) -> bool;
|
||||
|
||||
fn process_obligation(
|
||||
&mut self,
|
||||
obligation: &mut Self::Obligation,
|
||||
|
@ -143,7 +145,7 @@ pub struct ObligationForest<O: ForestObligation> {
|
|||
|
||||
/// A cache of the nodes in `nodes`, indexed by predicate. Unfortunately,
|
||||
/// its contents are not guaranteed to match those of `nodes`. See the
|
||||
/// comments in [`Self::process_obligation` for details.
|
||||
/// comments in `Self::process_obligation` for details.
|
||||
active_cache: FxHashMap<O::CacheKey, usize>,
|
||||
|
||||
/// A vector reused in [Self::compress()] and [Self::find_cycles_from_node()],
|
||||
|
@ -417,15 +419,18 @@ impl<O: ForestObligation> ObligationForest<O> {
|
|||
// nodes. Therefore we use a `while` loop.
|
||||
let mut index = 0;
|
||||
while let Some(node) = self.nodes.get_mut(index) {
|
||||
if node.state.get() != NodeState::Pending
|
||||
|| !processor.needs_process_obligation(&node.obligation)
|
||||
{
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// `processor.process_obligation` can modify the predicate within
|
||||
// `node.obligation`, and that predicate is the key used for
|
||||
// `self.active_cache`. This means that `self.active_cache` can get
|
||||
// out of sync with `nodes`. It's not very common, but it does
|
||||
// happen, and code in `compress` has to allow for it.
|
||||
if node.state.get() != NodeState::Pending {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
match processor.process_obligation(&mut node.obligation) {
|
||||
ProcessResult::Unchanged => {
|
||||
|
|
|
@ -65,6 +65,10 @@ where
|
|||
type Obligation = O;
|
||||
type Error = E;
|
||||
|
||||
fn needs_process_obligation(&self, _obligation: &Self::Obligation) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn process_obligation(
|
||||
&mut self,
|
||||
obligation: &mut Self::Obligation,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue