mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
get rid of env.closure_name_symbol
This commit is contained in:
parent
465fad9da1
commit
2973af5f79
3 changed files with 12 additions and 19 deletions
|
@ -1211,18 +1211,18 @@ fn canonicalize_pending_body<'a>(
|
||||||
let outer_identifier = env.tailcallable_symbol;
|
let outer_identifier = env.tailcallable_symbol;
|
||||||
env.tailcallable_symbol = Some(*defined_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
|
let (mut closure_data, can_output) = crate::expr::canonicalize_closure(
|
||||||
env.closure_name_symbol = Some(*defined_symbol);
|
env,
|
||||||
|
var_store,
|
||||||
let (mut closure_data, can_output) =
|
scope,
|
||||||
crate::expr::canonicalize_closure(env, var_store, scope, arguments, body);
|
arguments,
|
||||||
|
body,
|
||||||
|
Some(*defined_symbol),
|
||||||
|
);
|
||||||
|
|
||||||
// reset the tailcallable_symbol
|
// reset the tailcallable_symbol
|
||||||
env.tailcallable_symbol = outer_identifier;
|
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).
|
// The closure is self tail recursive iff it tail calls itself (by defined name).
|
||||||
let is_recursive = match can_output.tail_call {
|
let is_recursive = match can_output.tail_call {
|
||||||
Some(tail_symbol) if tail_symbol == *defined_symbol => Recursive::TailRecursive,
|
Some(tail_symbol) if tail_symbol == *defined_symbol => Recursive::TailRecursive,
|
||||||
|
@ -1242,6 +1242,7 @@ fn canonicalize_pending_body<'a>(
|
||||||
vars_by_symbol,
|
vars_by_symbol,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let closure_references = can_output.references.clone();
|
||||||
output.union(can_output);
|
output.union(can_output);
|
||||||
|
|
||||||
DefOutput {
|
DefOutput {
|
||||||
|
|
|
@ -24,9 +24,6 @@ pub struct Env<'a> {
|
||||||
/// current tail-callable symbol
|
/// current tail-callable symbol
|
||||||
pub tailcallable_symbol: Option<Symbol>,
|
pub tailcallable_symbol: Option<Symbol>,
|
||||||
|
|
||||||
/// current closure name (if any)
|
|
||||||
pub closure_name_symbol: Option<Symbol>,
|
|
||||||
|
|
||||||
/// Symbols of values/functions which were referenced by qualified lookups.
|
/// Symbols of values/functions which were referenced by qualified lookups.
|
||||||
pub qualified_value_lookups: VecSet<Symbol>,
|
pub qualified_value_lookups: VecSet<Symbol>,
|
||||||
|
|
||||||
|
@ -57,7 +54,6 @@ impl<'a> Env<'a> {
|
||||||
qualified_value_lookups: VecSet::default(),
|
qualified_value_lookups: VecSet::default(),
|
||||||
qualified_type_lookups: VecSet::default(),
|
qualified_type_lookups: VecSet::default(),
|
||||||
tailcallable_symbol: None,
|
tailcallable_symbol: None,
|
||||||
closure_name_symbol: None,
|
|
||||||
top_level_symbols: VecSet::default(),
|
top_level_symbols: VecSet::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,7 +669,7 @@ pub fn canonicalize_expr<'a>(
|
||||||
}
|
}
|
||||||
ast::Expr::Closure(loc_arg_patterns, loc_body_expr) => {
|
ast::Expr::Closure(loc_arg_patterns, loc_body_expr) => {
|
||||||
let (closure_data, output) =
|
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)
|
(Closure(closure_data), output)
|
||||||
}
|
}
|
||||||
|
@ -949,15 +949,11 @@ pub fn canonicalize_closure<'a>(
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
loc_arg_patterns: &'a [Loc<ast::Pattern<'a>>],
|
loc_arg_patterns: &'a [Loc<ast::Pattern<'a>>],
|
||||||
loc_body_expr: &'a Loc<ast::Expr<'a>>,
|
loc_body_expr: &'a Loc<ast::Expr<'a>>,
|
||||||
|
opt_def_name: Option<Symbol>,
|
||||||
) -> (ClosureData, Output) {
|
) -> (ClosureData, Output) {
|
||||||
// The globally unique symbol that will refer to this closure once it gets converted
|
// The globally unique symbol that will refer to this closure once it gets converted
|
||||||
// into a top-level procedure for code gen.
|
// into a top-level procedure for code gen.
|
||||||
//
|
let symbol = opt_def_name.unwrap_or_else(|| env.gen_unique_symbol());
|
||||||
// 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;
|
|
||||||
|
|
||||||
// The body expression gets a new scope for canonicalization.
|
// The body expression gets a new scope for canonicalization.
|
||||||
// Shadow `scope` to make sure we don't accidentally use the original one for the
|
// Shadow `scope` to make sure we don't accidentally use the original one for the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue