mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
no_niche to represent lack of captures niche
This commit is contained in:
parent
a5ea4f8c11
commit
71d612078a
6 changed files with 31 additions and 35 deletions
|
@ -261,6 +261,7 @@ pub fn gen_from_mono_module_llvm(
|
||||||
exposed_to_host: loaded.exposed_to_host.values.keys().copied().collect(),
|
exposed_to_host: loaded.exposed_to_host.values.keys().copied().collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dbg!(21);
|
||||||
roc_gen_llvm::llvm::build::build_procedures(
|
roc_gen_llvm::llvm::build::build_procedures(
|
||||||
&env,
|
&env,
|
||||||
opt_level,
|
opt_level,
|
||||||
|
|
|
@ -4574,7 +4574,7 @@ fn build_pending_specializations<'a>(
|
||||||
|
|
||||||
procs_base.host_specializations.insert_host_exposed(
|
procs_base.host_specializations.insert_host_exposed(
|
||||||
mono_env.subs,
|
mono_env.subs,
|
||||||
LambdaName::only_receiver(symbol),
|
LambdaName::no_niche(symbol),
|
||||||
annotation,
|
annotation,
|
||||||
expr_var,
|
expr_var,
|
||||||
);
|
);
|
||||||
|
@ -4634,7 +4634,7 @@ fn build_pending_specializations<'a>(
|
||||||
|
|
||||||
procs_base.host_specializations.insert_host_exposed(
|
procs_base.host_specializations.insert_host_exposed(
|
||||||
mono_env.subs,
|
mono_env.subs,
|
||||||
LambdaName::only_receiver(symbol),
|
LambdaName::no_niche(symbol),
|
||||||
annotation,
|
annotation,
|
||||||
expr_var,
|
expr_var,
|
||||||
);
|
);
|
||||||
|
@ -4712,7 +4712,7 @@ fn build_pending_specializations<'a>(
|
||||||
|
|
||||||
procs_base.host_specializations.insert_host_exposed(
|
procs_base.host_specializations.insert_host_exposed(
|
||||||
mono_env.subs,
|
mono_env.subs,
|
||||||
LambdaName::only_receiver(symbol),
|
LambdaName::no_niche(symbol),
|
||||||
annotation,
|
annotation,
|
||||||
expr_var,
|
expr_var,
|
||||||
);
|
);
|
||||||
|
@ -4772,7 +4772,7 @@ fn build_pending_specializations<'a>(
|
||||||
|
|
||||||
procs_base.host_specializations.insert_host_exposed(
|
procs_base.host_specializations.insert_host_exposed(
|
||||||
mono_env.subs,
|
mono_env.subs,
|
||||||
LambdaName::only_receiver(symbol),
|
LambdaName::no_niche(symbol),
|
||||||
annotation,
|
annotation,
|
||||||
expr_var,
|
expr_var,
|
||||||
);
|
);
|
||||||
|
|
|
@ -170,7 +170,7 @@ impl<'a> CodeGenHelp<'a> {
|
||||||
let arg_layouts = self.arena.alloc([layout]);
|
let arg_layouts = self.arena.alloc([layout]);
|
||||||
let expr = Expr::Call(Call {
|
let expr = Expr::Call(Call {
|
||||||
call_type: CallType::ByName {
|
call_type: CallType::ByName {
|
||||||
name: LambdaName::only_receiver(proc_name),
|
name: LambdaName::no_niche(proc_name),
|
||||||
ret_layout,
|
ret_layout,
|
||||||
arg_layouts,
|
arg_layouts,
|
||||||
specialization_id: CallSpecId::BACKEND_DUMMY,
|
specialization_id: CallSpecId::BACKEND_DUMMY,
|
||||||
|
@ -262,7 +262,7 @@ impl<'a> CodeGenHelp<'a> {
|
||||||
|
|
||||||
Some(Expr::Call(Call {
|
Some(Expr::Call(Call {
|
||||||
call_type: CallType::ByName {
|
call_type: CallType::ByName {
|
||||||
name: LambdaName::only_receiver(proc_name),
|
name: LambdaName::no_niche(proc_name),
|
||||||
ret_layout,
|
ret_layout,
|
||||||
arg_layouts,
|
arg_layouts,
|
||||||
specialization_id: CallSpecId::BACKEND_DUMMY,
|
specialization_id: CallSpecId::BACKEND_DUMMY,
|
||||||
|
@ -343,7 +343,7 @@ impl<'a> CodeGenHelp<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.specializations[spec_index].proc = Some(Proc {
|
self.specializations[spec_index].proc = Some(Proc {
|
||||||
name: LambdaName::only_receiver(proc_symbol),
|
name: LambdaName::no_niche(proc_symbol),
|
||||||
args,
|
args,
|
||||||
body,
|
body,
|
||||||
closure_data_layout: None,
|
closure_data_layout: None,
|
||||||
|
|
|
@ -2839,7 +2839,7 @@ fn generate_runtime_error_function<'a>(
|
||||||
};
|
};
|
||||||
|
|
||||||
Proc {
|
Proc {
|
||||||
name: LambdaName::only_receiver(name),
|
name: LambdaName::no_niche(name),
|
||||||
args,
|
args,
|
||||||
body: runtime_error,
|
body: runtime_error,
|
||||||
closure_data_layout: None,
|
closure_data_layout: None,
|
||||||
|
@ -2941,7 +2941,7 @@ fn specialize_external<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
let proc = Proc {
|
let proc = Proc {
|
||||||
name: LambdaName::only_receiver(name),
|
name: LambdaName::no_niche(name),
|
||||||
args: proc_arguments.into_bump_slice(),
|
args: proc_arguments.into_bump_slice(),
|
||||||
body,
|
body,
|
||||||
closure_data_layout: None,
|
closure_data_layout: None,
|
||||||
|
@ -4439,7 +4439,7 @@ pub fn with_hole<'a>(
|
||||||
|
|
||||||
match procs.insert_anonymous(
|
match procs.insert_anonymous(
|
||||||
env,
|
env,
|
||||||
LambdaName::only_receiver(name),
|
LambdaName::no_niche(name),
|
||||||
function_type,
|
function_type,
|
||||||
arguments,
|
arguments,
|
||||||
*loc_body,
|
*loc_body,
|
||||||
|
@ -4798,7 +4798,12 @@ pub fn with_hole<'a>(
|
||||||
Imported(thunk_name) => {
|
Imported(thunk_name) => {
|
||||||
debug_assert!(procs.is_imported_module_thunk(thunk_name));
|
debug_assert!(procs.is_imported_module_thunk(thunk_name));
|
||||||
|
|
||||||
add_needed_external(procs, env, fn_var, LambdaName::thunk(thunk_name));
|
add_needed_external(
|
||||||
|
procs,
|
||||||
|
env,
|
||||||
|
fn_var,
|
||||||
|
LambdaName::no_niche(thunk_name),
|
||||||
|
);
|
||||||
|
|
||||||
let function_symbol = env.unique_symbol();
|
let function_symbol = env.unique_symbol();
|
||||||
|
|
||||||
|
@ -5659,7 +5664,7 @@ fn tag_union_to_function<'a>(
|
||||||
});
|
});
|
||||||
|
|
||||||
// Lambda does not capture anything, can't be multimorphic
|
// Lambda does not capture anything, can't be multimorphic
|
||||||
let lambda_name = LambdaName::only_receiver(proc_symbol);
|
let lambda_name = LambdaName::no_niche(proc_symbol);
|
||||||
|
|
||||||
let inserted = procs.insert_anonymous(
|
let inserted = procs.insert_anonymous(
|
||||||
env,
|
env,
|
||||||
|
@ -7135,7 +7140,7 @@ where
|
||||||
// specialized, and wrap the original in a function pointer.
|
// specialized, and wrap the original in a function pointer.
|
||||||
let mut result = result;
|
let mut result = result;
|
||||||
for (_, (variable, left)) in needed_specializations_of_left {
|
for (_, (variable, left)) in needed_specializations_of_left {
|
||||||
add_needed_external(procs, env, variable, LambdaName::thunk(right));
|
add_needed_external(procs, env, variable, LambdaName::no_niche(right));
|
||||||
|
|
||||||
let res_layout = layout_cache.from_var(env.arena, variable, env.subs);
|
let res_layout = layout_cache.from_var(env.arena, variable, env.subs);
|
||||||
let layout = return_on_layout_error!(env, res_layout);
|
let layout = return_on_layout_error!(env, res_layout);
|
||||||
|
@ -7146,7 +7151,7 @@ where
|
||||||
} else if env.is_imported_symbol(right) {
|
} else if env.is_imported_symbol(right) {
|
||||||
// if this is an imported symbol, then we must make sure it is
|
// if this is an imported symbol, then we must make sure it is
|
||||||
// specialized, and wrap the original in a function pointer.
|
// specialized, and wrap the original in a function pointer.
|
||||||
add_needed_external(procs, env, variable, LambdaName::only_receiver(right));
|
add_needed_external(procs, env, variable, LambdaName::no_niche(right));
|
||||||
|
|
||||||
// then we must construct its closure; since imported symbols have no closure, we use the empty struct
|
// then we must construct its closure; since imported symbols have no closure, we use the empty struct
|
||||||
let_empty_struct(left, env.arena.alloc(result))
|
let_empty_struct(left, env.arena.alloc(result))
|
||||||
|
@ -7198,7 +7203,7 @@ fn force_thunk<'a>(
|
||||||
) -> Stmt<'a> {
|
) -> Stmt<'a> {
|
||||||
let call = self::Call {
|
let call = self::Call {
|
||||||
call_type: CallType::ByName {
|
call_type: CallType::ByName {
|
||||||
name: LambdaName::thunk(thunk_name),
|
name: LambdaName::no_niche(thunk_name),
|
||||||
ret_layout: env.arena.alloc(layout),
|
ret_layout: env.arena.alloc(layout),
|
||||||
arg_layouts: &[],
|
arg_layouts: &[],
|
||||||
specialization_id: env.next_call_specialization_id(),
|
specialization_id: env.next_call_specialization_id(),
|
||||||
|
@ -7247,7 +7252,7 @@ fn specialize_symbol<'a>(
|
||||||
procs.insert_passed_by_name(
|
procs.insert_passed_by_name(
|
||||||
env,
|
env,
|
||||||
arg_var,
|
arg_var,
|
||||||
LambdaName::thunk(original),
|
LambdaName::no_niche(original),
|
||||||
top_level,
|
top_level,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
);
|
);
|
||||||
|
@ -7261,7 +7266,7 @@ fn specialize_symbol<'a>(
|
||||||
procs.insert_passed_by_name(
|
procs.insert_passed_by_name(
|
||||||
env,
|
env,
|
||||||
arg_var,
|
arg_var,
|
||||||
LambdaName::only_receiver(original),
|
LambdaName::no_niche(original),
|
||||||
top_level,
|
top_level,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
);
|
);
|
||||||
|
@ -7352,7 +7357,7 @@ fn specialize_symbol<'a>(
|
||||||
procs.insert_passed_by_name(
|
procs.insert_passed_by_name(
|
||||||
env,
|
env,
|
||||||
arg_var,
|
arg_var,
|
||||||
LambdaName::thunk(original),
|
LambdaName::no_niche(original),
|
||||||
top_level,
|
top_level,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
);
|
);
|
||||||
|
@ -7394,7 +7399,7 @@ fn specialize_symbol<'a>(
|
||||||
procs.insert_passed_by_name(
|
procs.insert_passed_by_name(
|
||||||
env,
|
env,
|
||||||
arg_var,
|
arg_var,
|
||||||
LambdaName::thunk(original),
|
LambdaName::no_niche(original),
|
||||||
top_level,
|
top_level,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
);
|
);
|
||||||
|
@ -7644,7 +7649,7 @@ fn call_by_name<'a>(
|
||||||
hole,
|
hole,
|
||||||
)
|
)
|
||||||
} else if env.is_imported_symbol(proc_name) {
|
} else if env.is_imported_symbol(proc_name) {
|
||||||
add_needed_external(procs, env, fn_var, LambdaName::thunk(proc_name));
|
add_needed_external(procs, env, fn_var, LambdaName::no_niche(proc_name));
|
||||||
force_thunk(env, proc_name, ret_layout, assigned, hole)
|
force_thunk(env, proc_name, ret_layout, assigned, hole)
|
||||||
} else {
|
} else {
|
||||||
panic!("most likely we're trying to call something that is not a function");
|
panic!("most likely we're trying to call something that is not a function");
|
||||||
|
@ -7699,7 +7704,7 @@ fn call_by_name_help<'a>(
|
||||||
);
|
);
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
None => LambdaName::only_receiver(proc_name),
|
None => LambdaName::no_niche(proc_name),
|
||||||
};
|
};
|
||||||
|
|
||||||
// If required, add an extra argument to the layout that is the captured environment
|
// If required, add an extra argument to the layout that is the captured environment
|
||||||
|
@ -7996,7 +8001,7 @@ fn call_by_name_module_thunk<'a>(
|
||||||
// register the pending specialization, so this gets code genned later
|
// register the pending specialization, so this gets code genned later
|
||||||
suspended.specialization(
|
suspended.specialization(
|
||||||
env.subs,
|
env.subs,
|
||||||
LambdaName::thunk(proc_name),
|
LambdaName::no_niche(proc_name),
|
||||||
top_level_layout,
|
top_level_layout,
|
||||||
fn_var,
|
fn_var,
|
||||||
);
|
);
|
||||||
|
@ -8018,7 +8023,7 @@ fn call_by_name_module_thunk<'a>(
|
||||||
match specialize_variable(
|
match specialize_variable(
|
||||||
env,
|
env,
|
||||||
procs,
|
procs,
|
||||||
LambdaName::thunk(proc_name),
|
LambdaName::no_niche(proc_name),
|
||||||
layout_cache,
|
layout_cache,
|
||||||
fn_var,
|
fn_var,
|
||||||
&[],
|
&[],
|
||||||
|
|
|
@ -715,17 +715,7 @@ impl LambdaName<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn thunk(name: Symbol) -> Self {
|
pub fn no_niche(name: Symbol) -> Self {
|
||||||
Self {
|
|
||||||
name,
|
|
||||||
captures_niche: &[],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the function name is known, so there can only be one possible receiver, in such cases
|
|
||||||
// the lambda cannot be multimorphic.
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn only_receiver(name: Symbol) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
captures_niche: &[],
|
captures_niche: &[],
|
||||||
|
|
|
@ -110,7 +110,7 @@ fn build_app_mono<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
let proc = Proc {
|
let proc = Proc {
|
||||||
name: LambdaName::only_receiver(app_proc),
|
name: LambdaName::no_niche(app_proc),
|
||||||
args: &[],
|
args: &[],
|
||||||
body,
|
body,
|
||||||
closure_data_layout: None,
|
closure_data_layout: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue