mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Merge remote-tracking branch 'origin/trunk' into tag-union-imitate-rust
This commit is contained in:
commit
c827256e47
41 changed files with 957 additions and 532 deletions
|
@ -3351,8 +3351,7 @@ fn expose_function_to_host_help_c_abi_generic<'a, 'ctx, 'env>(
|
|||
|
||||
builder.position_at_end(entry);
|
||||
|
||||
let elements = [Layout::Builtin(Builtin::Int64), return_layout];
|
||||
let wrapped_layout = Layout::Struct(&elements);
|
||||
let wrapped_layout = roc_result_layout(env.arena, return_layout);
|
||||
call_roc_function(env, roc_function, &wrapped_layout, arguments_for_call)
|
||||
} else {
|
||||
call_roc_function(env, roc_function, &return_layout, arguments_for_call)
|
||||
|
@ -3380,18 +3379,11 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx, 'env>(
|
|||
return_layout: Layout<'a>,
|
||||
c_function_name: &str,
|
||||
) -> FunctionValue<'ctx> {
|
||||
let context = env.context;
|
||||
|
||||
// a tagged union to indicate to the test loader that a panic occurred.
|
||||
// especially when running 32-bit binaries on a 64-bit machine, there
|
||||
// does not seem to be a smarter solution
|
||||
let wrapper_return_type = context.struct_type(
|
||||
&[
|
||||
context.i64_type().into(),
|
||||
basic_type_from_layout(env, &return_layout),
|
||||
],
|
||||
false,
|
||||
);
|
||||
let wrapper_return_type =
|
||||
roc_result_type(env, roc_function.get_type().get_return_type().unwrap());
|
||||
|
||||
let mut cc_argument_types = Vec::with_capacity_in(arguments.len(), env.arena);
|
||||
for layout in arguments {
|
||||
|
@ -3510,8 +3502,6 @@ fn expose_function_to_host_help_c_abi<'a, 'ctx, 'env>(
|
|||
return_layout: Layout<'a>,
|
||||
c_function_name: &str,
|
||||
) -> FunctionValue<'ctx> {
|
||||
let context = env.context;
|
||||
|
||||
if env.is_gen_test {
|
||||
return expose_function_to_host_help_c_abi_gen_test(
|
||||
env,
|
||||
|
@ -3533,15 +3523,7 @@ fn expose_function_to_host_help_c_abi<'a, 'ctx, 'env>(
|
|||
);
|
||||
|
||||
let wrapper_return_type = if env.is_gen_test {
|
||||
context
|
||||
.struct_type(
|
||||
&[
|
||||
context.i64_type().into(),
|
||||
roc_function.get_type().get_return_type().unwrap(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
.into()
|
||||
roc_result_type(env, roc_function.get_type().get_return_type().unwrap()).into()
|
||||
} else {
|
||||
// roc_function.get_type().get_return_type().unwrap()
|
||||
basic_type_from_layout(env, &return_layout)
|
||||
|
@ -3708,12 +3690,7 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>(
|
|||
let builder = env.builder;
|
||||
|
||||
let return_type = basic_type_from_layout(env, &return_layout);
|
||||
|
||||
let call_result_type = context.struct_type(
|
||||
&[context.i64_type().into(), return_type.as_basic_type_enum()],
|
||||
false,
|
||||
);
|
||||
|
||||
let call_result_type = roc_result_type(env, return_type.as_basic_type_enum());
|
||||
let result_alloca = builder.build_alloca(call_result_type, "result");
|
||||
|
||||
let then_block = context.append_basic_block(parent, "then_block");
|
||||
|
@ -3811,12 +3788,8 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>(
|
|||
ptr_int
|
||||
};
|
||||
|
||||
let u8_ptr = env.context.i8_type().ptr_type(AddressSpace::Generic);
|
||||
let return_type = context.struct_type(&[context.i64_type().into(), u8_ptr.into()], false);
|
||||
// let return_type = call_result_type;
|
||||
|
||||
let return_value = {
|
||||
let v1 = return_type.const_zero();
|
||||
let v1 = call_result_type.const_zero();
|
||||
|
||||
// flag is non-zero, indicating failure
|
||||
let flag = context.i64_type().const_int(1, false);
|
||||
|
@ -3831,17 +3804,7 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>(
|
|||
v3
|
||||
};
|
||||
|
||||
// bitcast result alloca so we can store our concrete type { flag, error_msg } in there
|
||||
let result_alloca_bitcast = builder
|
||||
.build_bitcast(
|
||||
result_alloca,
|
||||
return_type.ptr_type(AddressSpace::Generic),
|
||||
"result_alloca_bitcast",
|
||||
)
|
||||
.into_pointer_value();
|
||||
|
||||
// store our return value
|
||||
builder.build_store(result_alloca_bitcast, return_value);
|
||||
builder.build_store(result_alloca, return_value);
|
||||
|
||||
env.builder.build_unconditional_branch(cont_block);
|
||||
}
|
||||
|
@ -3866,6 +3829,30 @@ fn make_exception_catcher<'a, 'ctx, 'env>(
|
|||
function_value
|
||||
}
|
||||
|
||||
fn roc_result_layout<'a>(arena: &'a Bump, return_layout: Layout<'a>) -> Layout<'a> {
|
||||
let elements = [
|
||||
Layout::Builtin(Builtin::Int64),
|
||||
Layout::Builtin(Builtin::Usize),
|
||||
return_layout,
|
||||
];
|
||||
|
||||
Layout::Struct(arena.alloc(elements))
|
||||
}
|
||||
|
||||
fn roc_result_type<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
return_type: BasicTypeEnum<'ctx>,
|
||||
) -> StructType<'ctx> {
|
||||
env.context.struct_type(
|
||||
&[
|
||||
env.context.i64_type().into(),
|
||||
env.context.i8_type().ptr_type(AddressSpace::Generic).into(),
|
||||
return_type,
|
||||
],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn make_good_roc_result<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
return_layout: Layout<'a>,
|
||||
|
@ -3874,11 +3861,7 @@ fn make_good_roc_result<'a, 'ctx, 'env>(
|
|||
let context = env.context;
|
||||
let builder = env.builder;
|
||||
|
||||
let content_type = basic_type_from_layout(env, &return_layout);
|
||||
let wrapper_return_type =
|
||||
context.struct_type(&[context.i64_type().into(), content_type], false);
|
||||
|
||||
let v1 = wrapper_return_type.const_zero();
|
||||
let v1 = roc_result_type(env, return_value.get_type()).const_zero();
|
||||
|
||||
let v2 = builder
|
||||
.build_insert_value(v1, context.i64_type().const_zero(), 0, "set_no_error")
|
||||
|
@ -3890,11 +3873,11 @@ fn make_good_roc_result<'a, 'ctx, 'env>(
|
|||
"load_call_result_passed_by_ptr",
|
||||
);
|
||||
builder
|
||||
.build_insert_value(v2, loaded, 1, "set_call_result")
|
||||
.build_insert_value(v2, loaded, 2, "set_call_result")
|
||||
.unwrap()
|
||||
} else {
|
||||
builder
|
||||
.build_insert_value(v2, return_value, 1, "set_call_result")
|
||||
.build_insert_value(v2, return_value, 2, "set_call_result")
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
|
@ -3923,13 +3906,8 @@ fn make_exception_catching_wrapper<'a, 'ctx, 'env>(
|
|||
}
|
||||
};
|
||||
|
||||
let wrapper_return_type = context.struct_type(
|
||||
&[
|
||||
context.i64_type().into(),
|
||||
basic_type_from_layout(env, &return_layout),
|
||||
],
|
||||
false,
|
||||
);
|
||||
let wrapper_return_type =
|
||||
roc_result_type(env, roc_function.get_type().get_return_type().unwrap());
|
||||
|
||||
// argument_types.push(wrapper_return_type.ptr_type(AddressSpace::Generic).into());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue