From e54344ac8bc56e77175b22ecef941cb6a03ff513 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 19 Nov 2021 17:10:30 +0100 Subject: [PATCH] storage subs for External specializations --- compiler/mono/src/ir.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index d3ceaa9ef5..d1ee990559 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -419,7 +419,7 @@ pub struct ExternalSpecializations<'a> { /// Not a bumpalo vec because bumpalo is not thread safe /// Separate array so we can search for membership quickly symbols: std::vec::Vec, - storage_subs: Subs, + storage_subs: StorageSubs, /// For each symbol, what types to specialize it for, points into the storage_subs types_to_specialize: std::vec::Vec>, _lifetime: std::marker::PhantomData<&'a u8>, @@ -429,15 +429,14 @@ impl<'a> ExternalSpecializations<'a> { pub fn new_in(_arena: &'a Bump) -> Self { Self { symbols: std::vec::Vec::new(), - storage_subs: Subs::default(), + storage_subs: StorageSubs::new(Subs::default()), types_to_specialize: std::vec::Vec::new(), _lifetime: std::marker::PhantomData, } } fn insert_external(&mut self, symbol: Symbol, env_subs: &mut Subs, variable: Variable) { - let variable = - roc_types::subs::deep_copy_var_to(env_subs, &mut self.storage_subs, variable); + let variable = self.storage_subs.extend_with_variable(env_subs, variable); match self.symbols.iter().position(|s| *s == symbol) { None => { @@ -454,7 +453,7 @@ impl<'a> ExternalSpecializations<'a> { fn decompose( self, ) -> ( - Subs, + StorageSubs, impl Iterator)>, ) { ( @@ -2051,9 +2050,13 @@ fn specialize_externals_others_need<'a>( layout_cache: &mut LayoutCache<'a>, ) { for externals_others_need in all_externals_others_need { - let (mut store, it) = externals_others_need.decompose(); + let (store, it) = externals_others_need.decompose(); + + let offset_variable = StorageSubs::merge_into(store, env.subs); + for (symbol, solved_types) in it { for store_variable in solved_types { + let variable = offset_variable(store_variable); // historical note: we used to deduplicate with a hash here, // but the cost of that hash is very high. So for now we make // duplicate specializations, and the insertion into a hash map @@ -2068,9 +2071,6 @@ fn specialize_externals_others_need<'a>( } }; - let variable = - roc_types::subs::deep_copy_var_to(&mut store, env.subs, store_variable); - // TODO I believe this is also duplicated match specialize_variable( env,