mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
enable recursive definitions at the top-level
This commit is contained in:
parent
2da2c25d32
commit
6aaba98d31
1 changed files with 115 additions and 89 deletions
|
@ -2166,11 +2166,59 @@ fn build_pending_specializations<'a>(
|
|||
// Add modules' decls to Procs
|
||||
for decl in decls {
|
||||
use roc_can::def::Declaration::*;
|
||||
|
||||
match decl {
|
||||
Declare(def) | Builtin(def) => add_def_to_module(
|
||||
&mut layout_cache,
|
||||
&mut procs,
|
||||
&mut mono_env,
|
||||
def,
|
||||
&exposed_to_host,
|
||||
false,
|
||||
),
|
||||
DeclareRec(defs) => {
|
||||
for def in defs {
|
||||
add_def_to_module(
|
||||
&mut layout_cache,
|
||||
&mut procs,
|
||||
&mut mono_env,
|
||||
def,
|
||||
&exposed_to_host,
|
||||
true,
|
||||
)
|
||||
}
|
||||
}
|
||||
InvalidCycle(_loc_idents, _regions) => {
|
||||
todo!("TODO handle InvalidCycle");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let problems = mono_env.problems.to_vec();
|
||||
|
||||
Msg::FoundSpecializations {
|
||||
module_id: home,
|
||||
solved_subs: roc_types::solved_types::Solved(subs),
|
||||
ident_ids,
|
||||
layout_cache,
|
||||
procs,
|
||||
problems,
|
||||
finished_info,
|
||||
}
|
||||
}
|
||||
|
||||
fn add_def_to_module<'a>(
|
||||
layout_cache: &mut LayoutCache<'a>,
|
||||
procs: &mut Procs<'a>,
|
||||
mono_env: &mut roc_mono::ir::Env<'a, '_>,
|
||||
def: roc_can::def::Def,
|
||||
exposed_to_host: &MutSet<Symbol>,
|
||||
is_recursive: bool,
|
||||
) {
|
||||
use roc_can::expr::Expr::*;
|
||||
use roc_can::pattern::Pattern::*;
|
||||
|
||||
match decl {
|
||||
Declare(def) | Builtin(def) => match def.loc_pattern.value {
|
||||
match def.loc_pattern.value {
|
||||
Identifier(symbol) => {
|
||||
let is_exposed = exposed_to_host.contains(&symbol);
|
||||
|
||||
|
@ -2182,8 +2230,6 @@ fn build_pending_specializations<'a>(
|
|||
loc_body,
|
||||
..
|
||||
} => {
|
||||
// this is a non-recursive declaration
|
||||
let is_tail_recursive = false;
|
||||
// If this is an exposed symbol, we need to
|
||||
// register it as such. Otherwise, since it
|
||||
// never gets called by Roc code, it will never
|
||||
|
@ -2191,7 +2237,7 @@ fn build_pending_specializations<'a>(
|
|||
if is_exposed {
|
||||
let mut pattern_vars = bumpalo::collections::Vec::with_capacity_in(
|
||||
loc_args.len(),
|
||||
arena,
|
||||
mono_env.arena,
|
||||
);
|
||||
|
||||
for (var, _) in loc_args.iter() {
|
||||
|
@ -2214,13 +2260,13 @@ fn build_pending_specializations<'a>(
|
|||
}
|
||||
|
||||
procs.insert_named(
|
||||
&mut mono_env,
|
||||
&mut layout_cache,
|
||||
mono_env,
|
||||
layout_cache,
|
||||
symbol,
|
||||
annotation,
|
||||
loc_args,
|
||||
*loc_body,
|
||||
is_tail_recursive,
|
||||
is_recursive,
|
||||
ret_var,
|
||||
);
|
||||
}
|
||||
|
@ -2255,26 +2301,6 @@ fn build_pending_specializations<'a>(
|
|||
other => {
|
||||
todo!("TODO gracefully handle Declare({:?})", other);
|
||||
}
|
||||
},
|
||||
DeclareRec(_defs) => {
|
||||
todo!("TODO support DeclareRec");
|
||||
}
|
||||
InvalidCycle(_loc_idents, _regions) => {
|
||||
todo!("TODO handle InvalidCycle");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let problems = mono_env.problems.to_vec();
|
||||
|
||||
Msg::FoundSpecializations {
|
||||
module_id: home,
|
||||
solved_subs: roc_types::solved_types::Solved(subs),
|
||||
ident_ids,
|
||||
layout_cache,
|
||||
procs,
|
||||
problems,
|
||||
finished_info,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue