From 2973af5f79df608e5823bbfa5c34b9ae2cf90cbb Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 27 Apr 2022 17:11:33 +0200 Subject: [PATCH] get rid of env.closure_name_symbol --- compiler/can/src/def.rs | 17 +++++++++-------- compiler/can/src/env.rs | 4 ---- compiler/can/src/expr.rs | 10 +++------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 17bdc0487e..9d2b013a1f 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -1211,18 +1211,18 @@ fn canonicalize_pending_body<'a>( let outer_identifier = env.tailcallable_symbol; env.tailcallable_symbol = Some(*defined_symbol); - // register the name of this closure, to make sure the closure won't capture it's own name - env.closure_name_symbol = Some(*defined_symbol); - - let (mut closure_data, can_output) = - crate::expr::canonicalize_closure(env, var_store, scope, arguments, body); + let (mut closure_data, can_output) = crate::expr::canonicalize_closure( + env, + var_store, + scope, + arguments, + body, + Some(*defined_symbol), + ); // reset the tailcallable_symbol env.tailcallable_symbol = outer_identifier; - let closure_references = can_output.references.clone(); - output.references.union_mut(&can_output.references); - // The closure is self tail recursive iff it tail calls itself (by defined name). let is_recursive = match can_output.tail_call { Some(tail_symbol) if tail_symbol == *defined_symbol => Recursive::TailRecursive, @@ -1242,6 +1242,7 @@ fn canonicalize_pending_body<'a>( vars_by_symbol, ); + let closure_references = can_output.references.clone(); output.union(can_output); DefOutput { diff --git a/compiler/can/src/env.rs b/compiler/can/src/env.rs index 40523b2fb7..e5dfd2e6de 100644 --- a/compiler/can/src/env.rs +++ b/compiler/can/src/env.rs @@ -24,9 +24,6 @@ pub struct Env<'a> { /// current tail-callable symbol pub tailcallable_symbol: Option, - /// current closure name (if any) - pub closure_name_symbol: Option, - /// Symbols of values/functions which were referenced by qualified lookups. pub qualified_value_lookups: VecSet, @@ -57,7 +54,6 @@ impl<'a> Env<'a> { qualified_value_lookups: VecSet::default(), qualified_type_lookups: VecSet::default(), tailcallable_symbol: None, - closure_name_symbol: None, top_level_symbols: VecSet::default(), } } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 5a0c404ed0..f04548d147 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -669,7 +669,7 @@ pub fn canonicalize_expr<'a>( } ast::Expr::Closure(loc_arg_patterns, loc_body_expr) => { let (closure_data, output) = - canonicalize_closure(env, var_store, scope, loc_arg_patterns, loc_body_expr); + canonicalize_closure(env, var_store, scope, loc_arg_patterns, loc_body_expr, None); (Closure(closure_data), output) } @@ -949,15 +949,11 @@ pub fn canonicalize_closure<'a>( scope: &mut Scope, loc_arg_patterns: &'a [Loc>], loc_body_expr: &'a Loc>, + opt_def_name: Option, ) -> (ClosureData, Output) { // The globally unique symbol that will refer to this closure once it gets converted // into a top-level procedure for code gen. - // - // In the Foo module, this will look something like Foo.$1 or Foo.$2. - let symbol = env - .closure_name_symbol - .unwrap_or_else(|| env.gen_unique_symbol()); - env.closure_name_symbol = None; + let symbol = opt_def_name.unwrap_or_else(|| env.gen_unique_symbol()); // The body expression gets a new scope for canonicalization. // Shadow `scope` to make sure we don't accidentally use the original one for the