Register top-level accessors as functions

This commit is contained in:
Ayaz Hafiz 2023-01-20 11:28:55 -06:00
parent f0ab9f77ca
commit bfb7bc39a7
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -5744,11 +5744,6 @@ fn build_pending_specializations<'a>(
let tag = declarations.declarations[index]; let tag = declarations.declarations[index];
match tag { match tag {
Value => { Value => {
if !matches!(body.value, roc_can::expr::Expr::Accessor(..)) {
// mark this symbols as a top-level thunk before any other work on the procs
module_thunks.push(symbol);
}
// If this is an exposed symbol, we need to // If this is an exposed symbol, we need to
// register it as such. Otherwise, since it // register it as such. Otherwise, since it
// never gets called by Roc code, it will never // never gets called by Roc code, it will never
@ -5786,6 +5781,25 @@ fn build_pending_specializations<'a>(
); );
} }
match body.value {
roc_can::expr::Expr::Accessor(accessor_data) => {
let fresh_record_symbol = mono_env.unique_symbol();
let closure_data = accessor_data.to_closure_data(fresh_record_symbol);
register_toplevel_function_into_procs_base(
&mut mono_env,
&mut procs_base,
closure_data.name,
expr_var,
closure_data.arguments,
closure_data.return_type,
*closure_data.loc_body,
false,
);
}
_ => {
// mark this symbols as a top-level thunk before any other work on the procs
module_thunks.push(symbol);
let proc = PartialProc { let proc = PartialProc {
annotation: expr_var, annotation: expr_var,
// This is a 0-arity thunk, so it has no arguments. // This is a 0-arity thunk, so it has no arguments.
@ -5800,6 +5814,8 @@ fn build_pending_specializations<'a>(
procs_base.partial_procs.insert(symbol, proc); procs_base.partial_procs.insert(symbol, proc);
} }
}
}
Function(f_index) | Recursive(f_index) | TailRecursive(f_index) => { Function(f_index) | Recursive(f_index) | TailRecursive(f_index) => {
let function_def = &declarations.function_bodies[f_index.index()].value; let function_def = &declarations.function_bodies[f_index.index()].value;
// this is a top-level definition, it should not capture anything // this is a top-level definition, it should not capture anything
@ -5848,17 +5864,16 @@ fn build_pending_specializations<'a>(
let is_recursive = matches!(tag, Recursive(_) | TailRecursive(_)); let is_recursive = matches!(tag, Recursive(_) | TailRecursive(_));
let partial_proc = PartialProc::from_named_function( register_toplevel_function_into_procs_base(
&mut mono_env, &mut mono_env,
&mut procs_base,
symbol,
expr_var, expr_var,
function_def.arguments.clone(), function_def.arguments.clone(),
body,
CapturedSymbols::None,
is_recursive,
function_def.return_type, function_def.return_type,
body,
is_recursive,
); );
procs_base.partial_procs.insert(symbol, partial_proc);
} }
Destructure(d_index) => { Destructure(d_index) => {
let loc_pattern = &declarations.destructs[d_index.index()].loc_pattern; let loc_pattern = &declarations.destructs[d_index.index()].loc_pattern;
@ -6109,6 +6124,33 @@ fn build_pending_specializations<'a>(
} }
} }
fn register_toplevel_function_into_procs_base<'a>(
mono_env: &mut roc_mono::ir::Env<'a, '_>,
procs_base: &mut ProcsBase<'a>,
symbol: Symbol,
expr_var: Variable,
arguments: Vec<(
Variable,
roc_can::expr::AnnotatedMark,
Loc<roc_can::pattern::Pattern>,
)>,
return_type: Variable,
body: Loc<roc_can::expr::Expr>,
is_recursive: bool,
) {
let partial_proc = PartialProc::from_named_function(
mono_env,
expr_var,
arguments,
body,
CapturedSymbols::None,
is_recursive,
return_type,
);
procs_base.partial_procs.insert(symbol, partial_proc);
}
/// Loads derived ability members up for specialization into the Derived module, prior to making /// Loads derived ability members up for specialization into the Derived module, prior to making
/// their specializations. /// their specializations.
// TODO: right now, this runs sequentially, and no other modules are mono'd in parallel to the // TODO: right now, this runs sequentially, and no other modules are mono'd in parallel to the