make bound_symbols private

This commit is contained in:
Folkert 2022-04-20 17:39:19 +02:00
parent c531191e49
commit ab8ac2edad
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 17 additions and 10 deletions

View file

@ -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

View file

@ -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);

View file

@ -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<Symbol>,
bound_symbols: VecSet<Symbol>,
type_lookups: VecSet<Symbol>,
value_lookups: VecSet<Symbol>,
/// 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<Item = &Symbol> {
self.type_lookups.iter()
}
pub fn bound_symbols(&self) -> impl Iterator<Item = &Symbol> {
self.bound_symbols.iter()
}
}