mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Pass less arguments around
This commit is contained in:
parent
13d1232f7d
commit
b8c1436a75
3 changed files with 13 additions and 83 deletions
|
@ -606,14 +606,7 @@ fn promote_to_main_function<'a, 'ctx>(
|
||||||
);
|
);
|
||||||
|
|
||||||
// NOTE fake layout; it is only used for debug prints
|
// NOTE fake layout; it is only used for debug prints
|
||||||
let roc_main_fn = function_value_by_func_spec(
|
let roc_main_fn = function_value_by_func_spec(env, FuncBorrowSpec::Some(*func_spec), symbol);
|
||||||
env,
|
|
||||||
FuncBorrowSpec::Some(*func_spec),
|
|
||||||
symbol,
|
|
||||||
&[],
|
|
||||||
Niche::NONE,
|
|
||||||
Layout::UNIT,
|
|
||||||
);
|
|
||||||
|
|
||||||
let main_fn_name = "$Test.main";
|
let main_fn_name = "$Test.main";
|
||||||
|
|
||||||
|
@ -662,14 +655,7 @@ fn promote_to_wasm_test_wrapper<'a, 'ctx>(
|
||||||
);
|
);
|
||||||
|
|
||||||
// NOTE fake layout; it is only used for debug prints
|
// NOTE fake layout; it is only used for debug prints
|
||||||
let roc_main_fn = function_value_by_func_spec(
|
let roc_main_fn = function_value_by_func_spec(env, FuncBorrowSpec::Some(*func_spec), symbol);
|
||||||
env,
|
|
||||||
FuncBorrowSpec::Some(*func_spec),
|
|
||||||
symbol,
|
|
||||||
&[],
|
|
||||||
Niche::NONE,
|
|
||||||
Layout::UNIT,
|
|
||||||
);
|
|
||||||
|
|
||||||
let output_type = match roc_main_fn.get_type().get_return_type() {
|
let output_type = match roc_main_fn.get_type().get_return_type() {
|
||||||
Some(return_type) => {
|
Some(return_type) => {
|
||||||
|
@ -4956,14 +4942,7 @@ pub fn build_procedures<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
// NOTE fake layout; it is only used for debug prints
|
// NOTE fake layout; it is only used for debug prints
|
||||||
let getter_fn = function_value_by_func_spec(
|
let getter_fn = function_value_by_func_spec(env, FuncBorrowSpec::Some(*func_spec), symbol);
|
||||||
env,
|
|
||||||
FuncBorrowSpec::Some(*func_spec),
|
|
||||||
symbol,
|
|
||||||
&[],
|
|
||||||
niche,
|
|
||||||
Layout::UNIT,
|
|
||||||
);
|
|
||||||
|
|
||||||
let name = getter_fn.get_name().to_str().unwrap();
|
let name = getter_fn.get_name().to_str().unwrap();
|
||||||
let getter_name = symbol.as_str(&env.interns);
|
let getter_name = symbol.as_str(&env.interns);
|
||||||
|
@ -5078,14 +5057,8 @@ pub fn build_procedures_expose_expects<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
// NOTE fake layout; it is only used for debug prints
|
// NOTE fake layout; it is only used for debug prints
|
||||||
let roc_main_fn = function_value_by_func_spec(
|
let roc_main_fn =
|
||||||
env,
|
function_value_by_func_spec(env, FuncBorrowSpec::Some(*func_spec), symbol);
|
||||||
FuncBorrowSpec::Some(*func_spec),
|
|
||||||
symbol,
|
|
||||||
&[],
|
|
||||||
captures_niche,
|
|
||||||
Layout::UNIT,
|
|
||||||
);
|
|
||||||
|
|
||||||
let name = roc_main_fn.get_name().to_str().unwrap();
|
let name = roc_main_fn.get_name().to_str().unwrap();
|
||||||
|
|
||||||
|
@ -5352,14 +5325,7 @@ fn expose_alias_to_host<'a>(
|
||||||
"we expect only one specialization of this symbol"
|
"we expect only one specialization of this symbol"
|
||||||
);
|
);
|
||||||
|
|
||||||
function_value_by_func_spec(
|
function_value_by_func_spec(env, FuncBorrowSpec::Some(*func_spec), hels.symbol)
|
||||||
env,
|
|
||||||
FuncBorrowSpec::Some(*func_spec),
|
|
||||||
hels.symbol,
|
|
||||||
hels.proc_layout.arguments,
|
|
||||||
Niche::NONE,
|
|
||||||
hels.proc_layout.result,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// morphic did not generate a specialization for this function,
|
// morphic did not generate a specialization for this function,
|
||||||
|
@ -5668,45 +5634,23 @@ pub(crate) fn function_value_by_func_spec<'a, 'ctx>(
|
||||||
env: &Env<'a, 'ctx, '_>,
|
env: &Env<'a, 'ctx, '_>,
|
||||||
func_spec: FuncBorrowSpec,
|
func_spec: FuncBorrowSpec,
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
arguments: &[InLayout<'a>],
|
|
||||||
niche: Niche<'a>,
|
|
||||||
result: InLayout<'a>,
|
|
||||||
) -> FunctionValue<'ctx> {
|
) -> FunctionValue<'ctx> {
|
||||||
let fn_name = func_spec_name(env.arena, &env.interns, symbol, func_spec);
|
let fn_name = func_spec_name(env.arena, &env.interns, symbol, func_spec);
|
||||||
let fn_name = fn_name.as_str();
|
let fn_name = fn_name.as_str();
|
||||||
|
|
||||||
function_value_by_name_help(env, arguments, niche, result, symbol, fn_name)
|
function_value_by_name_help(env, symbol, fn_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn function_value_by_name_help<'a, 'ctx>(
|
fn function_value_by_name_help<'a, 'ctx>(
|
||||||
env: &Env<'a, 'ctx, '_>,
|
env: &Env<'a, 'ctx, '_>,
|
||||||
arguments: &[InLayout<'a>],
|
|
||||||
_niche: Niche<'a>,
|
|
||||||
result: InLayout<'a>,
|
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
) -> FunctionValue<'ctx> {
|
) -> FunctionValue<'ctx> {
|
||||||
env.module.get_function(fn_name).unwrap_or_else(|| {
|
env.module.get_function(fn_name).unwrap_or_else(|| {
|
||||||
if symbol.is_builtin() {
|
if symbol.is_builtin() {
|
||||||
eprintln!(
|
panic!("Unrecognized builtin function: {fn_name:?} (symbol: {symbol:?})")
|
||||||
"Unrecognized builtin function: {:?}\nLayout: {:?}\n",
|
|
||||||
fn_name,
|
|
||||||
(arguments, result)
|
|
||||||
);
|
|
||||||
eprintln!("Is the function defined? If so, maybe there is a problem with the layout");
|
|
||||||
|
|
||||||
panic!("Unrecognized builtin function: {fn_name:?} (symbol: {symbol:?})",)
|
|
||||||
} else {
|
} else {
|
||||||
// Unrecognized non-builtin function:
|
panic!("Unrecognized non-builtin function: {fn_name:?} (symbol: {symbol:?})")
|
||||||
eprintln!(
|
|
||||||
"Unrecognized non-builtin function: {:?}\n\nSymbol: {:?}\nLayout: {:?}\n",
|
|
||||||
fn_name,
|
|
||||||
symbol,
|
|
||||||
(arguments, result)
|
|
||||||
);
|
|
||||||
eprintln!("Is the function defined? If so, maybe there is a problem with the layout");
|
|
||||||
|
|
||||||
panic!("Unrecognized non-builtin function: {fn_name:?} (symbol: {symbol:?})",)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -5721,14 +5665,7 @@ fn roc_call_with_args<'a, 'ctx>(
|
||||||
func_spec: FuncBorrowSpec,
|
func_spec: FuncBorrowSpec,
|
||||||
arguments: &[BasicValueEnum<'ctx>],
|
arguments: &[BasicValueEnum<'ctx>],
|
||||||
) -> BasicValueEnum<'ctx> {
|
) -> BasicValueEnum<'ctx> {
|
||||||
let fn_val = function_value_by_func_spec(
|
let fn_val = function_value_by_func_spec(env, func_spec, name.name());
|
||||||
env,
|
|
||||||
func_spec,
|
|
||||||
name.name(),
|
|
||||||
argument_layouts,
|
|
||||||
name.niche(),
|
|
||||||
result_layout,
|
|
||||||
);
|
|
||||||
|
|
||||||
call_roc_function(
|
call_roc_function(
|
||||||
env,
|
env,
|
||||||
|
|
|
@ -68,12 +68,8 @@ pub fn build<'a, 'ctx>(
|
||||||
let alloca = env
|
let alloca = env
|
||||||
.builder
|
.builder
|
||||||
.build_alloca(function_ptr_type, "function_pointer_alloca");
|
.build_alloca(function_ptr_type, "function_pointer_alloca");
|
||||||
let func_value: FunctionValue<'ctx> = function_value_by_func_spec(
|
let func_value: FunctionValue<'ctx> =
|
||||||
env,
|
function_value_by_func_spec(env, FuncBorrowSpec::Erased, lambda_name.name());
|
||||||
FuncBorrowSpec::Erased,
|
|
||||||
lambda_name.name(),
|
|
||||||
lambda_name.niche(),
|
|
||||||
);
|
|
||||||
env.builder
|
env.builder
|
||||||
.build_store(alloca, func_value.as_global_value().as_pointer_value());
|
.build_store(alloca, func_value.as_global_value().as_pointer_value());
|
||||||
alloca.into()
|
alloca.into()
|
||||||
|
|
|
@ -2611,7 +2611,7 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
|
||||||
} = higher_order;
|
} = higher_order;
|
||||||
|
|
||||||
let PassedFunction {
|
let PassedFunction {
|
||||||
argument_layouts,
|
argument_layouts: _,
|
||||||
return_layout: result_layout,
|
return_layout: result_layout,
|
||||||
owns_captured_environment: function_owns_closure_data,
|
owns_captured_environment: function_owns_closure_data,
|
||||||
name: function_name,
|
name: function_name,
|
||||||
|
@ -2626,9 +2626,6 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
|
||||||
env,
|
env,
|
||||||
FuncBorrowSpec::Some(func_spec),
|
FuncBorrowSpec::Some(func_spec),
|
||||||
function_name.name(),
|
function_name.name(),
|
||||||
argument_layouts,
|
|
||||||
function_name.niche(),
|
|
||||||
return_layout,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let (closure, closure_layout) =
|
let (closure, closure_layout) =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue