Skip to content

Commit 92b936e

Browse files
authored
refactor: infer.rs 'fn results' (#631)
* No need for `&self` to be mutable * Make control-flow more obvious * Also, in merge_equal_metas(), do if contains ... remove.unwrap in one step No change to semantics.
1 parent 56cb843 commit 92b936e

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/extension/infer.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl UnificationContext {
440440
continue;
441441
}
442442

443-
if let Some(cs) = self.constraints.get(m) {
443+
if let Some(cs) = self.constraints.remove(m) {
444444
for c in cs
445445
.iter()
446446
.filter(|c| !matches!(c, Constraint::Equal(_)))
@@ -450,7 +450,6 @@ impl UnificationContext {
450450
{
451451
self.add_constraint(combined_meta, c.clone());
452452
}
453-
self.constraints.remove(m).unwrap();
454453
merged.insert(*m);
455454
// Record a new meta the first time that we use it; don't
456455
// bother recording a new meta if we don't add any
@@ -538,27 +537,21 @@ impl UnificationContext {
538537
/// available. When there are variables, we should leave the graph as it is,
539538
/// but make sure that no matter what they're instantiated to, the graph
540539
/// still makes sense (should pass the extension validation check)
541-
pub fn results(&mut self) -> Result<ExtensionSolution, InferExtensionError> {
540+
pub fn results(&self) -> Result<ExtensionSolution, InferExtensionError> {
542541
// Check that all of the metavariables associated with nodes of the
543542
// graph are solved
544543
let mut results: ExtensionSolution = HashMap::new();
545544
for (loc, meta) in self.extensions.iter() {
546-
let rs = match self.get_solution(meta) {
547-
Some(rs) => Ok(rs.clone()),
548-
None => {
549-
// If it depends on some other live meta, that's bad news.
550-
// If it only depends on graph variables, then we don't have
551-
// a *solution*, but it's fine
552-
if self.live_var(meta).is_some() {
553-
Err(InferExtensionError::Unsolved { location: *loc })
554-
} else {
555-
continue;
556-
}
545+
if let Some(rs) = self.get_solution(meta) {
546+
if loc.1 == Direction::Incoming {
547+
results.insert(loc.0, rs.clone());
557548
}
558-
}?;
559-
if loc.1 == Direction::Incoming {
560-
results.insert(loc.0, rs);
549+
} else if self.live_var(meta).is_some() {
550+
// If it depends on some other live meta, that's bad news.
551+
return Err(InferExtensionError::Unsolved { location: *loc });
561552
}
553+
// If it only depends on graph variables, then we don't have
554+
// a *solution*, but it's fine
562555
}
563556
debug_assert!(self.live_metas().is_empty());
564557
Ok(results)

0 commit comments

Comments
 (0)