diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index f808787a8c..282d981050 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -639,8 +639,7 @@ pub fn canonicalize_expr<'a>( loc_pattern.region, ); - bound_by_argument_patterns - .extend(new_output.references.bound_symbols.iter().copied()); + bound_by_argument_patterns.extend(new_output.references.bound_symbols().copied()); output.union(new_output); @@ -662,7 +661,7 @@ pub fn canonicalize_expr<'a>( captured_symbols.remove(&symbol); // symbols bound either in this pattern or deeper down are not captured! - captured_symbols.retain(|s| !new_output.references.bound_symbols.contains(s)); + captured_symbols.retain(|s| !new_output.references.bound_symbols().any(|x| x == s)); captured_symbols.retain(|s| !bound_by_argument_patterns.contains(s)); // filter out top-level symbols diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index f6885c15d0..dc8a11a5b0 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -172,7 +172,7 @@ pub fn canonicalize_def_header_pattern<'a>( region, ) { Ok((symbol, shadowing_ability_member)) => { - output.references.bound_symbols.insert(symbol); + output.references.insert_bound(symbol); let can_pattern = match shadowing_ability_member { // A fresh identifier. None => Pattern::Identifier(symbol), @@ -190,7 +190,7 @@ pub fn canonicalize_def_header_pattern<'a>( shadow: shadow.clone(), kind: ShadowKind::Variable, })); - output.references.bound_symbols.insert(new_symbol); + output.references.insert_bound(new_symbol); let can_pattern = Pattern::Shadowed(original_region, shadow, new_symbol); (output, Loc::at(region, can_pattern)) @@ -220,7 +220,7 @@ pub fn canonicalize_pattern<'a>( region, ) { Ok(symbol) => { - output.references.bound_symbols.insert(symbol); + output.references.insert_bound(symbol); Pattern::Identifier(symbol) } @@ -230,7 +230,7 @@ pub fn canonicalize_pattern<'a>( shadow: shadow.clone(), kind: ShadowKind::Variable, })); - output.references.bound_symbols.insert(new_symbol); + output.references.insert_bound(new_symbol); Pattern::Shadowed(original_region, shadow, new_symbol) } @@ -460,7 +460,7 @@ pub fn canonicalize_pattern<'a>( region, ) { Ok(symbol) => { - output.references.bound_symbols.insert(symbol); + output.references.insert_bound(symbol); destructs.push(Loc { region: loc_pattern.region, @@ -531,7 +531,7 @@ pub fn canonicalize_pattern<'a>( ); // an optional field binds the symbol! - output.references.bound_symbols.insert(symbol); + output.references.insert_bound(symbol); output.union(expr_output); diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 24028dab08..04a5efdb99 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -44,7 +44,7 @@ impl Procedure { /// so it's important that building the same code gives the same order every time! #[derive(Clone, Debug, Default, PartialEq)] pub struct References { - pub bound_symbols: VecSet, + bound_symbols: VecSet, type_lookups: VecSet, value_lookups: VecSet, /// Aliases or opaque types referenced @@ -84,6 +84,10 @@ impl References { self.value_lookups.insert(symbol); } + pub fn insert_bound(&mut self, symbol: Symbol) { + self.bound_symbols.insert(symbol); + } + pub fn remove_value_lookup(&mut self, symbol: &Symbol) { self.value_lookups.remove(symbol); } @@ -100,4 +104,8 @@ impl References { pub fn type_lookups(&self) -> impl Iterator { self.type_lookups.iter() } + + pub fn bound_symbols(&self) -> impl Iterator { + self.bound_symbols.iter() + } }