From b92c28b237e5d77f838224ac15523f2d146ee989 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 20 Apr 2022 17:43:18 +0200 Subject: [PATCH] make calls private --- compiler/can/src/def.rs | 4 ++-- compiler/can/src/expr.rs | 8 ++++---- compiler/can/src/module.rs | 4 ++-- compiler/can/src/procedure.rs | 10 +++++++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 231ecabc1f..2b99f698d7 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1642,7 +1642,7 @@ fn closure_recursivity(symbol: Symbol, closures: &MutMap) -> let mut stack = Vec::new(); if let Some(references) = closures.get(&symbol) { - for v in references.calls.iter() { + for v in references.calls() { stack.push(*v); } @@ -1658,7 +1658,7 @@ fn closure_recursivity(symbol: Symbol, closures: &MutMap) -> // if it calls any functions if let Some(nested_references) = closures.get(&nested_symbol) { // add its called to the stack - for v in nested_references.calls.iter() { + for v in nested_references.calls() { stack.push(*v); } } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 282d981050..e8db25e794 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -517,7 +517,7 @@ pub fn canonicalize_expr<'a>( let expr = match fn_expr.value { Var(symbol) => { - output.references.calls.insert(symbol); + output.references.insert_call(symbol); // we're tail-calling a symbol by name, check if it's the tail-callable symbol output.tail_call = match &env.tailcallable_symbol { @@ -1102,7 +1102,7 @@ pub fn local_successors_with_duplicates<'a>( ) -> Vec { let mut answer: Vec<_> = references.value_lookups().copied().collect(); - let mut stack: Vec<_> = references.calls.iter().copied().collect(); + let mut stack: Vec<_> = references.calls().copied().collect(); let mut seen = Vec::new(); while let Some(symbol) = stack.pop() { @@ -1112,7 +1112,7 @@ pub fn local_successors_with_duplicates<'a>( if let Some(references) = closures.get(&symbol) { answer.extend(references.value_lookups().copied()); - stack.extend(references.calls.iter().copied()); + stack.extend(references.calls().copied()); seen.push(symbol); } @@ -1720,7 +1720,7 @@ fn flatten_str_lines<'a>( Interpolated(loc_expr) => { if is_valid_interpolation(loc_expr.value) { // Interpolations desugar to Str.concat calls - output.references.calls.insert(Symbol::STR_CONCAT); + output.references.insert_call(Symbol::STR_CONCAT); if !buf.is_empty() { segments.push(StrSegment::Plaintext(buf.into())); diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index 4445fa6486..fa901a6cec 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -333,7 +333,7 @@ pub fn canonicalize_module_defs<'a>( referenced_types.extend(output.references.type_lookups().copied()); // Gather up all the symbols that were referenced across all the defs' calls. - referenced_values.extend(output.references.calls); + referenced_values.extend(output.references.calls().copied()); // Gather up all the symbols that were referenced from other modules. referenced_values.extend(env.qualified_value_lookups.iter().copied()); @@ -532,7 +532,7 @@ pub fn canonicalize_module_defs<'a>( referenced_types.extend(output.references.type_lookups().copied()); // Incorporate any remaining output.calls entries into references. - referenced_values.extend(output.references.calls); + referenced_values.extend(output.references.calls().copied()); // Gather up all the symbols that were referenced from other modules. referenced_values.extend(env.qualified_value_lookups.iter().copied()); diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index 04a5efdb99..1378a4a012 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -49,7 +49,7 @@ pub struct References { value_lookups: VecSet, /// Aliases or opaque types referenced referenced_type_defs: VecSet, - pub calls: VecSet, + calls: VecSet, } impl References { @@ -88,6 +88,10 @@ impl References { self.bound_symbols.insert(symbol); } + pub fn insert_call(&mut self, symbol: Symbol) { + self.calls.insert(symbol); + } + pub fn remove_value_lookup(&mut self, symbol: &Symbol) { self.value_lookups.remove(symbol); } @@ -108,4 +112,8 @@ impl References { pub fn bound_symbols(&self) -> impl Iterator { self.bound_symbols.iter() } + + pub fn calls(&self) -> impl Iterator { + self.calls.iter() + } }