From 764eda0780fd8a7e7bb5f6c7912ec6ac18339906 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 12 Jul 2020 23:53:58 -0400 Subject: [PATCH] Fix anonymous function specialization --- compiler/mono/src/expr.rs | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/compiler/mono/src/expr.rs b/compiler/mono/src/expr.rs index 790fc92503..775eaa1e80 100644 --- a/compiler/mono/src/expr.rs +++ b/compiler/mono/src/expr.rs @@ -82,7 +82,8 @@ impl<'a> Procs<'a> { ret_var: Variable, layout_cache: &mut LayoutCache<'a>, ) -> Layout<'a> { - let (_, pattern_symbols, body) = patterns_to_when(env, loc_args, ret_var, loc_body); + let (pattern_vars, pattern_symbols, body) = + patterns_to_when(env, loc_args, ret_var, loc_body); // an anonymous closure. These will always be specialized already // by the surrounding context, so we can add pending specializations @@ -97,18 +98,40 @@ impl<'a> Procs<'a> { pattern_vars, }; - self.add_pending_specialization(symbol, layout.clone(), pending); + match &mut self.pending_specializations { + Some(pending_specializations) => { + // register the pending specialization, so this gets code genned later + add_pending(pending_specializations, symbol, layout.clone(), pending); - debug_assert!(!self.partial_procs.contains_key(&symbol), "Procs was told to insert a value for symbol {:?}, but there was already an entry for that key! Procs should never attempt to insert duplicates.", symbol); + debug_assert!(!self.partial_procs.contains_key(&symbol), "Procs was told to insert a value for symbol {:?}, but there was already an entry for that key! Procs should never attempt to insert duplicates.", symbol); - self.partial_procs.insert( - symbol, - PartialProc { - annotation, - pattern_symbols, - body: body.value, - }, - ); + self.partial_procs.insert( + symbol, + PartialProc { + annotation, + pattern_symbols, + body: body.value, + }, + ); + } + None => { + // TODO should pending_procs hold a Rc? + let partial_proc = PartialProc { + annotation, + pattern_symbols, + body: body.value, + }; + + match specialize(env, self, symbol, layout_cache, pending, partial_proc) { + Ok(proc) => { + self.specialized.insert((symbol, layout.clone()), proc); + } + Err(_) => { + self.runtime_errors.insert(symbol); + } + } + } + } layout }