From 21479749d5fcb9deb43ea5d835278f9e8cb26ae4 Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Mon, 30 Oct 2023 14:38:00 +0000 Subject: [PATCH 1/2] infer.rs: main_loop: combine self.constraints.(get.remove) --- src/extension/infer.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/extension/infer.rs b/src/extension/infer.rs index 84f2b5686..46cfcae91 100644 --- a/src/extension/infer.rs +++ b/src/extension/infer.rs @@ -440,7 +440,7 @@ impl UnificationContext { continue; } - if let Some(cs) = self.constraints.get(m) { + if let Some(cs) = self.constraints.remove(m) { for c in cs .iter() .filter(|c| !matches!(c, Constraint::Equal(_))) @@ -450,7 +450,6 @@ impl UnificationContext { { self.add_constraint(combined_meta, c.clone()); } - self.constraints.remove(m).unwrap(); merged.insert(*m); // Record a new meta the first time that we use it; don't // bother recording a new meta if we don't add any From fb2eaab54c2ea5dc2c64f01d02f62420763acdf9 Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Mon, 30 Oct 2023 14:48:18 +0000 Subject: [PATCH 2/2] Refactor results (and, immutable &self) --- src/extension/infer.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/extension/infer.rs b/src/extension/infer.rs index 46cfcae91..22344492b 100644 --- a/src/extension/infer.rs +++ b/src/extension/infer.rs @@ -537,27 +537,21 @@ impl UnificationContext { /// available. When there are variables, we should leave the graph as it is, /// but make sure that no matter what they're instantiated to, the graph /// still makes sense (should pass the extension validation check) - pub fn results(&mut self) -> Result { + pub fn results(&self) -> Result { // Check that all of the metavariables associated with nodes of the // graph are solved let mut results: ExtensionSolution = HashMap::new(); for (loc, meta) in self.extensions.iter() { - let rs = match self.get_solution(meta) { - Some(rs) => Ok(rs.clone()), - None => { - // If it depends on some other live meta, that's bad news. - // If it only depends on graph variables, then we don't have - // a *solution*, but it's fine - if self.live_var(meta).is_some() { - Err(InferExtensionError::Unsolved { location: *loc }) - } else { - continue; - } + if let Some(rs) = self.get_solution(meta) { + if loc.1 == Direction::Incoming { + results.insert(loc.0, rs.clone()); } - }?; - if loc.1 == Direction::Incoming { - results.insert(loc.0, rs); + } else if self.live_var(meta).is_some() { + // If it depends on some other live meta, that's bad news. + return Err(InferExtensionError::Unsolved { location: *loc }); } + // If it only depends on graph variables, then we don't have + // a *solution*, but it's fine } debug_assert!(self.live_metas().is_empty()); Ok(results)