mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Register top-level accessors as functions
This commit is contained in:
parent
f0ab9f77ca
commit
bfb7bc39a7
1 changed files with 65 additions and 23 deletions
|
@ -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,19 +5781,40 @@ fn build_pending_specializations<'a>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let proc = PartialProc {
|
match body.value {
|
||||||
annotation: expr_var,
|
roc_can::expr::Expr::Accessor(accessor_data) => {
|
||||||
// This is a 0-arity thunk, so it has no arguments.
|
let fresh_record_symbol = mono_env.unique_symbol();
|
||||||
pattern_symbols: &[],
|
let closure_data = accessor_data.to_closure_data(fresh_record_symbol);
|
||||||
// This is a top-level definition, so it cannot capture anything
|
register_toplevel_function_into_procs_base(
|
||||||
captured_symbols: CapturedSymbols::None,
|
&mut mono_env,
|
||||||
body: body.value,
|
&mut procs_base,
|
||||||
body_var: expr_var,
|
closure_data.name,
|
||||||
// This is a 0-arity thunk, so it cannot be recursive
|
expr_var,
|
||||||
is_self_recursive: false,
|
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);
|
||||||
|
|
||||||
procs_base.partial_procs.insert(symbol, proc);
|
let proc = PartialProc {
|
||||||
|
annotation: expr_var,
|
||||||
|
// This is a 0-arity thunk, so it has no arguments.
|
||||||
|
pattern_symbols: &[],
|
||||||
|
// This is a top-level definition, so it cannot capture anything
|
||||||
|
captured_symbols: CapturedSymbols::None,
|
||||||
|
body: body.value,
|
||||||
|
body_var: expr_var,
|
||||||
|
// This is a 0-arity thunk, so it cannot be recursive
|
||||||
|
is_self_recursive: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue