From b0ceaf037242e981aa38e7128067d8cbdb846b99 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 24 Apr 2022 01:04:59 +0200 Subject: [PATCH] instantiate aliases with a function --- compiler/can/src/def.rs | 11 +++++------ compiler/types/src/types.rs | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index bcdde10c17..04d5a2ccaa 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1966,13 +1966,12 @@ fn correct_mutual_recursive_type_alias<'a>( // Don't try to instantiate the alias itself in its definition. let original_alias_def = to_instantiate.remove(&rec).unwrap(); + let helper = |s| to_instantiate.get(&s); + let mut new_lambda_sets = ImSet::default(); - alias.typ.instantiate_aliases( - alias.region, - &to_instantiate, - var_store, - &mut new_lambda_sets, - ); + alias + .typ + .instantiate_aliases(alias.region, &helper, var_store, &mut new_lambda_sets); for lambda_set_var in new_lambda_sets { alias diff --git a/compiler/types/src/types.rs b/compiler/types/src/types.rs index 0f3536cd54..0e51c2dda4 100644 --- a/compiler/types/src/types.rs +++ b/compiler/types/src/types.rs @@ -120,13 +120,15 @@ impl RecordField { } } - pub fn instantiate_aliases( + pub fn instantiate_aliases<'a, F>( &mut self, region: Region, - aliases: &ImMap, + aliases: &'a F, var_store: &mut VarStore, introduced: &mut ImSet, - ) { + ) where + F: Fn(Symbol) -> Option<&'a Alias>, + { use RecordField::*; match self { @@ -168,13 +170,15 @@ impl LambdaSet { &mut self.0 } - fn instantiate_aliases( + fn instantiate_aliases<'a, F>( &mut self, region: Region, - aliases: &ImMap, + aliases: &'a F, var_store: &mut VarStore, introduced: &mut ImSet, - ) { + ) where + F: Fn(Symbol) -> Option<&'a Alias>, + { self.0 .instantiate_aliases(region, aliases, var_store, introduced) } @@ -1064,13 +1068,15 @@ impl Type { result } - pub fn instantiate_aliases( + pub fn instantiate_aliases<'a, F>( &mut self, region: Region, - aliases: &ImMap, + aliases: &'a F, var_store: &mut VarStore, new_lambda_set_variables: &mut ImSet, - ) { + ) where + F: Fn(Symbol) -> Option<&'a Alias>, + { use Type::*; match self { @@ -1138,7 +1144,7 @@ impl Type { ); } Apply(symbol, args, _) => { - if let Some(alias) = aliases.get(symbol) { + if let Some(alias) = aliases(*symbol) { // TODO switch to this, but we still need to check for recursion with the // `else` branch if false {