mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
make bound_symbols private
This commit is contained in:
parent
c531191e49
commit
ab8ac2edad
3 changed files with 17 additions and 10 deletions
|
@ -639,8 +639,7 @@ pub fn canonicalize_expr<'a>(
|
||||||
loc_pattern.region,
|
loc_pattern.region,
|
||||||
);
|
);
|
||||||
|
|
||||||
bound_by_argument_patterns
|
bound_by_argument_patterns.extend(new_output.references.bound_symbols().copied());
|
||||||
.extend(new_output.references.bound_symbols.iter().copied());
|
|
||||||
|
|
||||||
output.union(new_output);
|
output.union(new_output);
|
||||||
|
|
||||||
|
@ -662,7 +661,7 @@ pub fn canonicalize_expr<'a>(
|
||||||
captured_symbols.remove(&symbol);
|
captured_symbols.remove(&symbol);
|
||||||
|
|
||||||
// symbols bound either in this pattern or deeper down are not captured!
|
// 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));
|
captured_symbols.retain(|s| !bound_by_argument_patterns.contains(s));
|
||||||
|
|
||||||
// filter out top-level symbols
|
// filter out top-level symbols
|
||||||
|
|
|
@ -172,7 +172,7 @@ pub fn canonicalize_def_header_pattern<'a>(
|
||||||
region,
|
region,
|
||||||
) {
|
) {
|
||||||
Ok((symbol, shadowing_ability_member)) => {
|
Ok((symbol, shadowing_ability_member)) => {
|
||||||
output.references.bound_symbols.insert(symbol);
|
output.references.insert_bound(symbol);
|
||||||
let can_pattern = match shadowing_ability_member {
|
let can_pattern = match shadowing_ability_member {
|
||||||
// A fresh identifier.
|
// A fresh identifier.
|
||||||
None => Pattern::Identifier(symbol),
|
None => Pattern::Identifier(symbol),
|
||||||
|
@ -190,7 +190,7 @@ pub fn canonicalize_def_header_pattern<'a>(
|
||||||
shadow: shadow.clone(),
|
shadow: shadow.clone(),
|
||||||
kind: ShadowKind::Variable,
|
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);
|
let can_pattern = Pattern::Shadowed(original_region, shadow, new_symbol);
|
||||||
(output, Loc::at(region, can_pattern))
|
(output, Loc::at(region, can_pattern))
|
||||||
|
@ -220,7 +220,7 @@ pub fn canonicalize_pattern<'a>(
|
||||||
region,
|
region,
|
||||||
) {
|
) {
|
||||||
Ok(symbol) => {
|
Ok(symbol) => {
|
||||||
output.references.bound_symbols.insert(symbol);
|
output.references.insert_bound(symbol);
|
||||||
|
|
||||||
Pattern::Identifier(symbol)
|
Pattern::Identifier(symbol)
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ pub fn canonicalize_pattern<'a>(
|
||||||
shadow: shadow.clone(),
|
shadow: shadow.clone(),
|
||||||
kind: ShadowKind::Variable,
|
kind: ShadowKind::Variable,
|
||||||
}));
|
}));
|
||||||
output.references.bound_symbols.insert(new_symbol);
|
output.references.insert_bound(new_symbol);
|
||||||
|
|
||||||
Pattern::Shadowed(original_region, shadow, new_symbol)
|
Pattern::Shadowed(original_region, shadow, new_symbol)
|
||||||
}
|
}
|
||||||
|
@ -460,7 +460,7 @@ pub fn canonicalize_pattern<'a>(
|
||||||
region,
|
region,
|
||||||
) {
|
) {
|
||||||
Ok(symbol) => {
|
Ok(symbol) => {
|
||||||
output.references.bound_symbols.insert(symbol);
|
output.references.insert_bound(symbol);
|
||||||
|
|
||||||
destructs.push(Loc {
|
destructs.push(Loc {
|
||||||
region: loc_pattern.region,
|
region: loc_pattern.region,
|
||||||
|
@ -531,7 +531,7 @@ pub fn canonicalize_pattern<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
// an optional field binds the symbol!
|
// an optional field binds the symbol!
|
||||||
output.references.bound_symbols.insert(symbol);
|
output.references.insert_bound(symbol);
|
||||||
|
|
||||||
output.union(expr_output);
|
output.union(expr_output);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl Procedure {
|
||||||
/// so it's important that building the same code gives the same order every time!
|
/// so it's important that building the same code gives the same order every time!
|
||||||
#[derive(Clone, Debug, Default, PartialEq)]
|
#[derive(Clone, Debug, Default, PartialEq)]
|
||||||
pub struct References {
|
pub struct References {
|
||||||
pub bound_symbols: VecSet<Symbol>,
|
bound_symbols: VecSet<Symbol>,
|
||||||
type_lookups: VecSet<Symbol>,
|
type_lookups: VecSet<Symbol>,
|
||||||
value_lookups: VecSet<Symbol>,
|
value_lookups: VecSet<Symbol>,
|
||||||
/// Aliases or opaque types referenced
|
/// Aliases or opaque types referenced
|
||||||
|
@ -84,6 +84,10 @@ impl References {
|
||||||
self.value_lookups.insert(symbol);
|
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) {
|
pub fn remove_value_lookup(&mut self, symbol: &Symbol) {
|
||||||
self.value_lookups.remove(symbol);
|
self.value_lookups.remove(symbol);
|
||||||
}
|
}
|
||||||
|
@ -100,4 +104,8 @@ impl References {
|
||||||
pub fn type_lookups(&self) -> impl Iterator<Item = &Symbol> {
|
pub fn type_lookups(&self) -> impl Iterator<Item = &Symbol> {
|
||||||
self.type_lookups.iter()
|
self.type_lookups.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bound_symbols(&self) -> impl Iterator<Item = &Symbol> {
|
||||||
|
self.bound_symbols.iter()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue