diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 87dc27f336..1d83835d38 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -125,7 +125,7 @@ impl IntroducedVariables { self.lambda_sets.extend(other.lambda_sets.iter().copied()); self.inferred.extend(other.inferred.iter().copied()); self.host_exposed_aliases - .extend(other.host_exposed_aliases.clone()); + .extend(other.host_exposed_aliases.iter().map(|(k, v)| (*k, *v))); self.named.extend(other.named.iter().cloned()); self.able.extend(other.able.iter().cloned()); diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 0fbe917e30..5d7b0ced91 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -334,8 +334,7 @@ pub fn canonicalize_defs<'a>( // Record all the annotation's references in output.references.lookups for symbol in can_ann.references { - output.references.type_lookups.insert(symbol); - output.references.referenced_type_defs.insert(symbol); + output.references.insert_type_lookup(symbol); } let mut can_vars: Vec> = Vec::with_capacity(vars.len()); @@ -445,8 +444,7 @@ pub fn canonicalize_defs<'a>( // Record all the annotation's references in output.references.lookups for symbol in member_annot.references { - output.references.type_lookups.insert(symbol); - output.references.referenced_type_defs.insert(symbol); + output.references.insert_type_lookup(symbol); } let name_region = member.name.region; @@ -1162,8 +1160,7 @@ fn canonicalize_pending_value_def<'a>( // Record all the annotation's references in output.references.lookups for symbol in type_annotation.references.iter() { - output.references.type_lookups.insert(*symbol); - output.references.referenced_type_defs.insert(*symbol); + output.references.insert_type_lookup(*symbol); } add_annotation_aliases(&type_annotation, aliases); @@ -1282,8 +1279,7 @@ fn canonicalize_pending_value_def<'a>( // Record all the annotation's references in output.references.lookups for symbol in type_annotation.references.iter() { - output.references.type_lookups.insert(*symbol); - output.references.referenced_type_defs.insert(*symbol); + output.references.insert_type_lookup(*symbol); } add_annotation_aliases(&type_annotation, aliases); diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 9ec675185f..c916ffe2f7 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -487,8 +487,7 @@ pub fn canonicalize_expr<'a>( } Ok((name, opaque_def)) => { let argument = Box::new(args.pop().unwrap()); - output.references.referenced_type_defs.insert(name); - output.references.type_lookups.insert(name); + output.references.insert_type_lookup(name); let (type_arguments, lambda_set_variables, specialized_def_type) = freshen_opaque_def(var_store, opaque_def); @@ -685,7 +684,7 @@ pub fn canonicalize_expr<'a>( // filter out aliases debug_assert!(captured_symbols .iter() - .all(|s| !output.references.referenced_type_defs.contains(s))); + .all(|s| !output.references.references_type_def(*s))); // captured_symbols.retain(|s| !output.references.referenced_type_defs.contains(s)); // filter out functions that don't close over anything diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index dbd4a30274..ba4ece29d5 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -329,8 +329,8 @@ pub fn canonicalize_module_defs<'a>( let mut referenced_types = VecSet::default(); // Gather up all the symbols that were referenced across all the defs' lookups. - referenced_values.extend(output.references.value_lookups); - referenced_types.extend(output.references.type_lookups); + referenced_values.extend(output.references.value_lookups.iter().copied()); + 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); @@ -528,8 +528,8 @@ pub fn canonicalize_module_defs<'a>( } // Incorporate any remaining output.lookups entries into references. - referenced_values.extend(output.references.value_lookups); - referenced_types.extend(output.references.type_lookups); + referenced_values.extend(output.references.value_lookups.iter().copied()); + referenced_types.extend(output.references.type_lookups().copied()); // Incorporate any remaining output.calls entries into references. referenced_values.extend(output.references.calls); diff --git a/compiler/can/src/pattern.rs b/compiler/can/src/pattern.rs index c47af17fb4..f6885c15d0 100644 --- a/compiler/can/src/pattern.rs +++ b/compiler/can/src/pattern.rs @@ -318,8 +318,7 @@ pub fn canonicalize_pattern<'a>( let (type_arguments, lambda_set_variables, specialized_def_type) = freshen_opaque_def(var_store, opaque_def); - output.references.referenced_type_defs.insert(opaque); - output.references.type_lookups.insert(opaque); + output.references.insert_type_lookup(opaque); Pattern::UnwrappedOpaque { whole_var: var_store.fresh(), diff --git a/compiler/can/src/procedure.rs b/compiler/can/src/procedure.rs index fd0fd5d372..d893f1a1bb 100644 --- a/compiler/can/src/procedure.rs +++ b/compiler/can/src/procedure.rs @@ -45,10 +45,10 @@ impl Procedure { #[derive(Clone, Debug, Default, PartialEq)] pub struct References { pub bound_symbols: VecSet, - pub type_lookups: VecSet, + type_lookups: VecSet, pub value_lookups: VecSet, /// Aliases or opaque types referenced - pub referenced_type_defs: VecSet, + referenced_type_defs: VecSet, pub calls: VecSet, } @@ -75,4 +75,17 @@ impl References { pub fn has_type_lookup(&self, symbol: Symbol) -> bool { self.type_lookups.contains(&symbol) } + + pub fn references_type_def(&self, symbol: Symbol) -> bool { + self.referenced_type_defs.contains(&symbol) + } + + pub fn insert_type_lookup(&mut self, symbol: Symbol) { + self.type_lookups.insert(symbol); + self.referenced_type_defs.insert(symbol); + } + + pub fn type_lookups(&self) -> impl Iterator { + self.type_lookups.iter() + } }