mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
working Set.walk
This commit is contained in:
parent
d25b1dc549
commit
ca78439756
8 changed files with 471 additions and 576 deletions
|
@ -145,6 +145,7 @@ fn build_transform_caller_help_new<'a, 'ctx, 'env>(
|
|||
arguments_cast.push(argument);
|
||||
}
|
||||
|
||||
dbg!(closure_data_layout);
|
||||
match closure_data_layout {
|
||||
Layout::FunctionPointer(_, _) => {
|
||||
// do nothing
|
||||
|
@ -167,9 +168,31 @@ fn build_transform_caller_help_new<'a, 'ctx, 'env>(
|
|||
arguments_cast.push(closure_data);
|
||||
}
|
||||
}
|
||||
Layout::Struct([Layout::Closure(_, lambda_set, _)]) => {
|
||||
// a case required for Set.walk; may be able to remove when we can define builtins in
|
||||
// terms of other builtins in the right way (using their function symbols instead of
|
||||
// hacking with lowlevel ops).
|
||||
let closure_type = basic_type_from_layout(
|
||||
env,
|
||||
&Layout::Struct(&[lambda_set.runtime_representation()]),
|
||||
)
|
||||
.ptr_type(AddressSpace::Generic);
|
||||
|
||||
let closure_cast = env
|
||||
.builder
|
||||
.build_bitcast(closure_ptr, closure_type, "load_opaque")
|
||||
.into_pointer_value();
|
||||
|
||||
let closure_data = env.builder.build_load(closure_cast, "load_opaque");
|
||||
|
||||
arguments_cast.push(closure_data);
|
||||
}
|
||||
Layout::Struct([]) => {
|
||||
// do nothing, should try to remove this case later
|
||||
}
|
||||
Layout::Struct(_) => {
|
||||
// do nothing, should try to remove this case later
|
||||
}
|
||||
other => unreachable!("layout is not valid for a closure: {:?}", other),
|
||||
}
|
||||
|
||||
|
|
|
@ -3069,8 +3069,6 @@ pub fn build_proc_header_new<'a, 'ctx, 'env>(
|
|||
) -> FunctionValue<'ctx> {
|
||||
let layout = env.arena.alloc(layout).full();
|
||||
|
||||
dbg!(symbol, layout);
|
||||
|
||||
build_proc_header(env, layout_ids, symbol, &layout, proc)
|
||||
}
|
||||
|
||||
|
@ -4448,11 +4446,12 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
}
|
||||
}
|
||||
DictWalk => {
|
||||
debug_assert_eq!(args.len(), 3);
|
||||
debug_assert_eq!(args.len(), 4);
|
||||
|
||||
let (dict, dict_layout) = load_symbol_and_layout(scope, &args[0]);
|
||||
let (stepper, stepper_layout) = load_symbol_and_layout(scope, &args[1]);
|
||||
let (accum, accum_layout) = load_symbol_and_layout(scope, &args[2]);
|
||||
let (default, default_layout) = load_symbol_and_layout(scope, &args[1]);
|
||||
let (function_layout, function) = scope.function_pointers[&args[2]];
|
||||
let (closure, closure_layout) = load_symbol_and_layout(scope, &args[3]);
|
||||
|
||||
match dict_layout {
|
||||
Layout::Builtin(Builtin::EmptyDict) => {
|
||||
|
@ -4463,12 +4462,14 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
env,
|
||||
layout_ids,
|
||||
dict,
|
||||
stepper,
|
||||
accum,
|
||||
stepper_layout,
|
||||
function,
|
||||
function_layout,
|
||||
closure,
|
||||
*closure_layout,
|
||||
default,
|
||||
key_layout,
|
||||
value_layout,
|
||||
accum_layout,
|
||||
default_layout,
|
||||
),
|
||||
_ => unreachable!("invalid dict layout"),
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::debug_info_init;
|
||||
use crate::llvm::bitcode::{
|
||||
build_dec_wrapper, build_eq_wrapper, build_inc_wrapper, build_transform_caller,
|
||||
build_dec_wrapper, build_eq_wrapper, build_inc_wrapper, build_transform_caller_new,
|
||||
call_bitcode_fn, call_void_bitcode_fn,
|
||||
};
|
||||
use crate::llvm::build::{
|
||||
|
@ -633,9 +633,11 @@ pub fn dict_walk<'a, 'ctx, 'env>(
|
|||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
dict: BasicValueEnum<'ctx>,
|
||||
stepper: BasicValueEnum<'ctx>,
|
||||
transform: FunctionValue<'ctx>,
|
||||
transform_layout: Layout<'a>,
|
||||
closure_data: BasicValueEnum<'ctx>,
|
||||
closure_data_layout: Layout<'a>,
|
||||
accum: BasicValueEnum<'ctx>,
|
||||
stepper_layout: &Layout<'a>,
|
||||
key_layout: &Layout<'a>,
|
||||
value_layout: &Layout<'a>,
|
||||
accum_layout: &Layout<'a>,
|
||||
|
@ -648,13 +650,13 @@ pub fn dict_walk<'a, 'ctx, 'env>(
|
|||
let dict_ptr = builder.build_alloca(zig_dict_type, "dict_ptr");
|
||||
env.builder.build_store(dict_ptr, dict);
|
||||
|
||||
let stepper_ptr = builder.build_alloca(stepper.get_type(), "stepper_ptr");
|
||||
env.builder.build_store(stepper_ptr, stepper);
|
||||
let closure_data_ptr = builder.build_alloca(closure_data.get_type(), "closure_data_ptr");
|
||||
env.builder.build_store(closure_data_ptr, closure_data);
|
||||
|
||||
let stepper_caller = build_transform_caller(
|
||||
let stepper_caller = build_transform_caller_new(
|
||||
env,
|
||||
layout_ids,
|
||||
stepper_layout,
|
||||
transform,
|
||||
closure_data_layout,
|
||||
&[*key_layout, *value_layout, *accum_layout],
|
||||
)
|
||||
.as_global_value()
|
||||
|
@ -688,7 +690,8 @@ pub fn dict_walk<'a, 'ctx, 'env>(
|
|||
env,
|
||||
&[
|
||||
dict_ptr.into(),
|
||||
env.builder.build_bitcast(stepper_ptr, u8_ptr, "to_opaque"),
|
||||
env.builder
|
||||
.build_bitcast(closure_data_ptr, u8_ptr, "to_opaque"),
|
||||
stepper_caller.into(),
|
||||
env.builder.build_bitcast(accum_ptr, u8_ptr, "to_opaque"),
|
||||
alignment_iv.into(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue