mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
upgrade most build_load usages
This commit is contained in:
parent
f2d0953e0a
commit
9bf8d65170
10 changed files with 165 additions and 106 deletions
|
@ -19,7 +19,8 @@ use roc_error_macros::internal_error;
|
|||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::layout::{Builtin, LambdaSet, Layout, LayoutIds};
|
||||
|
||||
use super::build::create_entry_block_alloca;
|
||||
use super::build::{create_entry_block_alloca, BuilderExt};
|
||||
use super::convert::zig_list_type;
|
||||
|
||||
use std::convert::TryInto;
|
||||
|
||||
|
@ -139,7 +140,9 @@ pub fn call_bitcode_fn_fixing_for_convention<'a, 'ctx, 'env>(
|
|||
.collect();
|
||||
call_void_bitcode_fn(env, &fixed_args, fn_name);
|
||||
|
||||
let cc_return_value = env.builder.build_load(cc_return_value_ptr, "read_result");
|
||||
let cc_return_value =
|
||||
env.builder
|
||||
.new_build_load(cc_return_type, cc_return_value_ptr, "read_result");
|
||||
if roc_return_type.size_of() == cc_return_type.size_of() {
|
||||
cc_return_value
|
||||
} else {
|
||||
|
@ -392,8 +395,8 @@ fn build_rc_wrapper<'a, 'ctx, 'env>(
|
|||
|
||||
generic_value_ptr.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
|
||||
let value_ptr_type =
|
||||
basic_type_from_layout(env, layout).ptr_type(AddressSpace::Generic);
|
||||
let value_type = basic_type_from_layout(env, layout);
|
||||
let value_ptr_type = value_type.ptr_type(AddressSpace::Generic);
|
||||
let value_ptr =
|
||||
env.builder
|
||||
.build_pointer_cast(generic_value_ptr, value_ptr_type, "load_opaque");
|
||||
|
@ -404,7 +407,8 @@ fn build_rc_wrapper<'a, 'ctx, 'env>(
|
|||
let value = if layout.is_passed_by_reference(env.layout_interner, env.target_info) {
|
||||
value_ptr.into()
|
||||
} else {
|
||||
env.builder.build_load(value_ptr, "load_opaque")
|
||||
env.builder
|
||||
.new_build_load(value_type, value_ptr, "load_opaque")
|
||||
};
|
||||
|
||||
match rc_operation {
|
||||
|
@ -573,8 +577,12 @@ pub fn build_compare_wrapper<'a, 'ctx, 'env>(
|
|||
env.builder
|
||||
.build_pointer_cast(value_ptr2, value_ptr_type, "load_opaque");
|
||||
|
||||
let value1 = env.builder.build_load(value_cast1, "load_opaque");
|
||||
let value2 = env.builder.build_load(value_cast2, "load_opaque");
|
||||
let value1 = env
|
||||
.builder
|
||||
.new_build_load(value_type, value_cast1, "load_opaque");
|
||||
let value2 = env
|
||||
.builder
|
||||
.new_build_load(value_type, value_cast2, "load_opaque");
|
||||
|
||||
let default = [value1.into(), value2.into()];
|
||||
|
||||
|
@ -596,7 +604,9 @@ pub fn build_compare_wrapper<'a, 'ctx, 'env>(
|
|||
"load_opaque",
|
||||
);
|
||||
|
||||
let closure_data = env.builder.build_load(closure_cast, "load_opaque");
|
||||
let closure_data =
|
||||
env.builder
|
||||
.new_build_load(closure_type, closure_cast, "load_opaque");
|
||||
|
||||
env.arena
|
||||
.alloc([value1.into(), value2.into(), closure_data.into()])
|
||||
|
@ -644,7 +654,8 @@ impl<'ctx> BitcodeReturnValue<'ctx> {
|
|||
match self {
|
||||
BitcodeReturnValue::List(result) => {
|
||||
call_void_bitcode_fn(env, arguments, fn_name);
|
||||
env.builder.build_load(*result, "load_list")
|
||||
env.builder
|
||||
.new_build_load(zig_list_type(env), *result, "load_list")
|
||||
}
|
||||
BitcodeReturnValue::Str(result) => {
|
||||
call_void_bitcode_fn(env, arguments, fn_name);
|
||||
|
|
|
@ -93,7 +93,7 @@ impl<'ctx> BuilderExt<'ctx> for Builder<'ctx> {
|
|||
index: u32,
|
||||
name: &str,
|
||||
) -> Result<PointerValue<'ctx>, ()> {
|
||||
assert_eq!(
|
||||
debug_assert_eq!(
|
||||
ptr.get_type().get_element_type().into_struct_type(),
|
||||
struct_type
|
||||
);
|
||||
|
@ -106,7 +106,7 @@ impl<'ctx> BuilderExt<'ctx> for Builder<'ctx> {
|
|||
ptr: PointerValue<'ctx>,
|
||||
name: &str,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
assert_eq!(
|
||||
debug_assert_eq!(
|
||||
ptr.get_type().get_element_type(),
|
||||
element_type.as_any_type_enum()
|
||||
);
|
||||
|
@ -120,7 +120,7 @@ impl<'ctx> BuilderExt<'ctx> for Builder<'ctx> {
|
|||
ordered_indexes: &[IntValue<'ctx>],
|
||||
name: &str,
|
||||
) -> PointerValue<'ctx> {
|
||||
assert_eq!(
|
||||
debug_assert_eq!(
|
||||
ptr.get_type().get_element_type(),
|
||||
element_type.as_any_type_enum()
|
||||
);
|
||||
|
@ -842,7 +842,10 @@ fn build_string_literal<'a, 'ctx, 'env>(
|
|||
let alloca = const_str_alloca_ptr(env, parent, ptr, number_of_elements, number_of_elements);
|
||||
|
||||
match env.target_info.ptr_width() {
|
||||
PtrWidth::Bytes4 => env.builder.build_load(alloca, "load_const_str"),
|
||||
PtrWidth::Bytes4 => {
|
||||
env.builder
|
||||
.new_build_load(zig_str_type(env), alloca, "load_const_str")
|
||||
}
|
||||
PtrWidth::Bytes8 => alloca.into(),
|
||||
}
|
||||
}
|
||||
|
@ -1226,31 +1229,6 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
let field_layout = field_layouts[*index as usize];
|
||||
use_roc_value(env, field_layout, field_value, "struct_field_tag")
|
||||
}
|
||||
(
|
||||
PointerValue(argument),
|
||||
Layout::Union(UnionLayout::NonNullableUnwrapped(fields)),
|
||||
) => {
|
||||
let struct_layout = Layout::struct_no_name_order(fields);
|
||||
let struct_type = basic_type_from_layout(env, &struct_layout);
|
||||
|
||||
let cast_argument = env.builder.build_pointer_cast(
|
||||
argument,
|
||||
struct_type.ptr_type(AddressSpace::Generic),
|
||||
"cast_rosetree_like",
|
||||
);
|
||||
|
||||
let ptr = env
|
||||
.builder
|
||||
.new_build_struct_gep(
|
||||
struct_type.into_struct_type(),
|
||||
cast_argument,
|
||||
*index as u32,
|
||||
env.arena.alloc(format!("non_nullable_unwrapped_{}", index)),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
env.builder.build_load(ptr, "load_rosetree_like")
|
||||
}
|
||||
(other, layout) => {
|
||||
// potential cause: indexing into an unwrapped 1-element record/tag?
|
||||
unreachable!(
|
||||
|
@ -1552,12 +1530,15 @@ fn build_struct<'a, 'ctx, 'env>(
|
|||
// The layout of the struct expects them to be dropped!
|
||||
let (field_expr, field_layout) = load_symbol_and_layout(scope, symbol);
|
||||
if !field_layout.is_dropped_because_empty() {
|
||||
field_types.push(basic_type_from_layout(env, field_layout));
|
||||
let field_type = basic_type_from_layout(env, field_layout);
|
||||
field_types.push(field_type);
|
||||
|
||||
if field_layout.is_passed_by_reference(env.layout_interner, env.target_info) {
|
||||
let field_value = env
|
||||
.builder
|
||||
.build_load(field_expr.into_pointer_value(), "load_tag_to_put_in_struct");
|
||||
let field_value = env.builder.new_build_load(
|
||||
field_type,
|
||||
field_expr.into_pointer_value(),
|
||||
"load_tag_to_put_in_struct",
|
||||
);
|
||||
|
||||
field_vals.push(field_value);
|
||||
} else {
|
||||
|
@ -1845,20 +1826,18 @@ pub fn get_tag_id<'a, 'ctx, 'env>(
|
|||
let tag_id_layout = union_layout.tag_id_layout();
|
||||
let tag_id_int_type = basic_type_from_layout(env, &tag_id_layout).into_int_type();
|
||||
|
||||
let union_struct_type = struct_type_from_union_layout(env, union_layout);
|
||||
|
||||
match union_layout {
|
||||
UnionLayout::NonRecursive(_) => {
|
||||
debug_assert!(argument.is_pointer_value(), "{:?}", argument);
|
||||
|
||||
let argument_ptr = argument.into_pointer_value();
|
||||
get_tag_id_wrapped(env, union_struct_type, argument_ptr)
|
||||
get_tag_id_wrapped(env, *union_layout, argument_ptr)
|
||||
}
|
||||
UnionLayout::Recursive(_) => {
|
||||
let argument_ptr = argument.into_pointer_value();
|
||||
|
||||
if union_layout.stores_tag_id_as_data(env.target_info) {
|
||||
get_tag_id_wrapped(env, union_struct_type, argument_ptr)
|
||||
get_tag_id_wrapped(env, *union_layout, argument_ptr)
|
||||
} else {
|
||||
tag_pointer_read_tag_id(env, argument_ptr)
|
||||
}
|
||||
|
@ -1889,7 +1868,7 @@ pub fn get_tag_id<'a, 'ctx, 'env>(
|
|||
env.builder.position_at_end(else_block);
|
||||
|
||||
let tag_id = if union_layout.stores_tag_id_as_data(env.target_info) {
|
||||
get_tag_id_wrapped(env, union_struct_type, argument_ptr)
|
||||
get_tag_id_wrapped(env, *union_layout, argument_ptr)
|
||||
} else {
|
||||
tag_pointer_read_tag_id(env, argument_ptr)
|
||||
};
|
||||
|
@ -1900,7 +1879,7 @@ pub fn get_tag_id<'a, 'ctx, 'env>(
|
|||
env.builder.position_at_end(cont_block);
|
||||
|
||||
env.builder
|
||||
.build_load(result, "load_result")
|
||||
.new_build_load(tag_id_int_type, result, "load_result")
|
||||
.into_int_value()
|
||||
}
|
||||
UnionLayout::NullableUnwrapped { nullable_id, .. } => {
|
||||
|
@ -2256,14 +2235,16 @@ pub fn load_roc_value<'a, 'ctx, 'env>(
|
|||
source: PointerValue<'ctx>,
|
||||
name: &str,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let basic_type = basic_type_from_layout(env, &layout);
|
||||
|
||||
if layout.is_passed_by_reference(env.layout_interner, env.target_info) {
|
||||
let alloca = entry_block_alloca_zerofill(env, basic_type_from_layout(env, &layout), name);
|
||||
let alloca = entry_block_alloca_zerofill(env, basic_type, name);
|
||||
|
||||
store_roc_value(env, layout, alloca, source.into());
|
||||
|
||||
alloca.into()
|
||||
} else {
|
||||
env.builder.build_load(source, name)
|
||||
env.builder.new_build_load(basic_type, source, name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3010,7 +2991,7 @@ fn complex_bitcast_from_bigger_than_to<'ctx>(
|
|||
name,
|
||||
);
|
||||
|
||||
builder.build_load(to_type_pointer, "cast_value")
|
||||
builder.new_build_load(to_type, to_type_pointer, "cast_value")
|
||||
}
|
||||
|
||||
fn complex_bitcast_to_bigger_than_from<'ctx>(
|
||||
|
@ -3037,15 +3018,18 @@ fn complex_bitcast_to_bigger_than_from<'ctx>(
|
|||
builder.build_store(from_type_pointer, from_value);
|
||||
|
||||
// then read it back as a different type
|
||||
builder.build_load(storage, "cast_value")
|
||||
builder.new_build_load(to_type, storage, "cast_value")
|
||||
}
|
||||
|
||||
/// get the tag id out of a pointer to a wrapped (i.e. stores the tag id at runtime) layout
|
||||
fn get_tag_id_wrapped<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
union_struct_type: StructType<'ctx>,
|
||||
union_layout: UnionLayout<'a>,
|
||||
from_value: PointerValue<'ctx>,
|
||||
) -> IntValue<'ctx> {
|
||||
let union_struct_type = struct_type_from_union_layout(env, &union_layout);
|
||||
let tag_id_type = basic_type_from_layout(env, &union_layout.tag_id_layout());
|
||||
|
||||
let tag_id_ptr = env
|
||||
.builder
|
||||
.new_build_struct_gep(
|
||||
|
@ -3057,7 +3041,7 @@ fn get_tag_id_wrapped<'a, 'ctx, 'env>(
|
|||
.unwrap();
|
||||
|
||||
env.builder
|
||||
.build_load(tag_id_ptr, "load_tag_id")
|
||||
.new_build_load(tag_id_type, tag_id_ptr, "load_tag_id")
|
||||
.into_int_value()
|
||||
}
|
||||
|
||||
|
@ -3434,7 +3418,9 @@ fn expose_function_to_host_help_c_abi_generic<'a, 'ctx, 'env>(
|
|||
"bitcast_arg",
|
||||
);
|
||||
|
||||
let loaded = env.builder.build_load(fastcc_ptr, "load_arg");
|
||||
let loaded = env
|
||||
.builder
|
||||
.new_build_load(fastcc_type, fastcc_ptr, "load_arg");
|
||||
arguments_for_call.push(loaded);
|
||||
} else {
|
||||
let as_cc_type = env.builder.build_pointer_cast(
|
||||
|
@ -3550,9 +3536,11 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx, 'env>(
|
|||
} else {
|
||||
match layout {
|
||||
Layout::Builtin(Builtin::List(_)) => {
|
||||
let loaded = env
|
||||
.builder
|
||||
.build_load(arg.into_pointer_value(), "load_list_pointer");
|
||||
let loaded = env.builder.new_build_load(
|
||||
arg_type,
|
||||
arg.into_pointer_value(),
|
||||
"load_list_pointer",
|
||||
);
|
||||
let cast =
|
||||
complex_bitcast_check_size(env, loaded, fastcc_type, "to_fastcc_type_1");
|
||||
arguments_for_call.push(cast);
|
||||
|
@ -3760,7 +3748,8 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx, 'env>(
|
|||
"bitcast_arg",
|
||||
);
|
||||
|
||||
env.builder.build_load(fastcc_ptr, "load_arg")
|
||||
env.builder
|
||||
.new_build_load(*fastcc_type, fastcc_ptr, "load_arg")
|
||||
} else {
|
||||
complex_bitcast_check_size(env, *arg, *fastcc_type, "to_fastcc_type_2")
|
||||
}
|
||||
|
@ -3777,9 +3766,11 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx, 'env>(
|
|||
env.builder.build_return(Some(&value));
|
||||
}
|
||||
RocReturn::ByPointer => {
|
||||
let loaded = env
|
||||
.builder
|
||||
.build_load(value.into_pointer_value(), "load_result");
|
||||
let loaded = env.builder.new_build_load(
|
||||
return_type,
|
||||
value.into_pointer_value(),
|
||||
"load_result",
|
||||
);
|
||||
env.builder.build_return(Some(&loaded));
|
||||
}
|
||||
},
|
||||
|
@ -3793,9 +3784,11 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx, 'env>(
|
|||
// TODO: ideally, in this case, we should pass the C return pointer directly
|
||||
// into the call_roc_function rather than forcing an extra alloca, load, and
|
||||
// store!
|
||||
let value = env
|
||||
.builder
|
||||
.build_load(value.into_pointer_value(), "load_roc_result");
|
||||
let value = env.builder.new_build_load(
|
||||
return_type,
|
||||
value.into_pointer_value(),
|
||||
"load_roc_result",
|
||||
);
|
||||
env.builder.build_store(out_ptr, value);
|
||||
}
|
||||
}
|
||||
|
@ -4073,7 +4066,8 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>(
|
|||
let v1 = call_result_type.const_zero();
|
||||
|
||||
// tag must be non-zero, indicating failure
|
||||
let tag = builder.build_load(error_tag_ptr, "load_panic_tag");
|
||||
let tag =
|
||||
builder.new_build_load(env.context.i64_type(), error_tag_ptr, "load_panic_tag");
|
||||
|
||||
let v2 = builder.build_insert_value(v1, tag, 0, "set_error").unwrap();
|
||||
|
||||
|
@ -4090,7 +4084,11 @@ fn set_jump_and_catch_long_jump<'a, 'ctx, 'env>(
|
|||
|
||||
env.builder.position_at_end(cont_block);
|
||||
|
||||
builder.build_load(result_alloca, "set_jump_and_catch_long_jump_load_result")
|
||||
builder.new_build_load(
|
||||
call_result_type,
|
||||
result_alloca,
|
||||
"set_jump_and_catch_long_jump_load_result",
|
||||
)
|
||||
}
|
||||
|
||||
fn make_exception_catcher<'a, 'ctx, 'env>(
|
||||
|
@ -4140,6 +4138,8 @@ fn make_good_roc_result<'a, 'ctx, 'env>(
|
|||
let context = env.context;
|
||||
let builder = env.builder;
|
||||
|
||||
let return_type = basic_type_from_layout(env, &return_layout);
|
||||
|
||||
let v1 = roc_call_result_type(env, basic_type_from_layout(env, &return_layout)).const_zero();
|
||||
|
||||
let v2 = builder
|
||||
|
@ -4147,7 +4147,8 @@ fn make_good_roc_result<'a, 'ctx, 'env>(
|
|||
.unwrap();
|
||||
|
||||
let v3 = if return_layout.is_passed_by_reference(env.layout_interner, env.target_info) {
|
||||
let loaded = env.builder.build_load(
|
||||
let loaded = env.builder.new_build_load(
|
||||
return_type,
|
||||
return_value.into_pointer_value(),
|
||||
"load_call_result_passed_by_ptr",
|
||||
);
|
||||
|
@ -4738,7 +4739,8 @@ fn build_closure_caller<'a, 'ctx, 'env>(
|
|||
if param.is_pointer_value()
|
||||
&& !layout.is_passed_by_reference(env.layout_interner, env.target_info)
|
||||
{
|
||||
*param = builder.build_load(param.into_pointer_value(), "load_param");
|
||||
let basic_type = basic_type_from_layout(env, layout);
|
||||
*param = builder.new_build_load(basic_type, param.into_pointer_value(), "load_param");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5038,7 +5040,8 @@ pub fn call_roc_function<'a, 'ctx, 'env>(
|
|||
debug_assert_eq!(roc_function.get_call_conventions(), FAST_CALL_CONV);
|
||||
call.set_call_convention(FAST_CALL_CONV);
|
||||
|
||||
env.builder.build_load(result_alloca, "load_result")
|
||||
env.builder
|
||||
.new_build_load(result_type, result_alloca, "load_result")
|
||||
}
|
||||
RocReturn::ByPointer => {
|
||||
let it = arguments.iter().map(|x| (*x).into());
|
||||
|
@ -5062,8 +5065,11 @@ pub fn call_roc_function<'a, 'ctx, 'env>(
|
|||
if result_layout.is_passed_by_reference(env.layout_interner, env.target_info) {
|
||||
result_alloca.into()
|
||||
} else {
|
||||
env.builder
|
||||
.build_load(result_alloca, "return_by_pointer_load_result")
|
||||
env.builder.new_build_load(
|
||||
result_type,
|
||||
result_alloca,
|
||||
"return_by_pointer_load_result",
|
||||
)
|
||||
}
|
||||
}
|
||||
RocReturn::Return => {
|
||||
|
@ -5540,9 +5546,11 @@ fn build_foreign_symbol<'a, 'ctx, 'env>(
|
|||
let return_value = match cc_return {
|
||||
CCReturn::Return => call.try_as_basic_value().left().unwrap(),
|
||||
|
||||
CCReturn::ByPointer => {
|
||||
env.builder.build_load(return_pointer, "read_result")
|
||||
}
|
||||
CCReturn::ByPointer => env.builder.new_build_load(
|
||||
return_type,
|
||||
return_pointer,
|
||||
"read_result",
|
||||
),
|
||||
CCReturn::Void => return_type.const_zero(),
|
||||
};
|
||||
|
||||
|
|
|
@ -326,7 +326,9 @@ pub(crate) fn list_replace_unsafe<'a, 'ctx, 'env>(
|
|||
};
|
||||
|
||||
// Load the element and returned list into a struct.
|
||||
let old_element = env.builder.build_load(element_ptr, "load_element");
|
||||
let old_element = env
|
||||
.builder
|
||||
.new_build_load(element_type, element_ptr, "load_element");
|
||||
|
||||
// the list has the same alignment as a usize / ptr. The element comes first in the struct if
|
||||
// its alignment is bigger than that of a list.
|
||||
|
@ -665,7 +667,9 @@ where
|
|||
{
|
||||
builder.position_at_end(loop_bb);
|
||||
|
||||
let current_index = builder.build_load(index_alloca, "index").into_int_value();
|
||||
let current_index = builder
|
||||
.new_build_load(env.ptr_int(), index_alloca, "index")
|
||||
.into_int_value();
|
||||
let next_index = builder.build_int_add(current_index, one, "next_index");
|
||||
builder.build_store(index_alloca, next_index);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use roc_mono::layout::Layout;
|
|||
use roc_target::PtrWidth;
|
||||
|
||||
use super::bitcode::{call_str_bitcode_fn, BitcodeReturns};
|
||||
use super::build::BuilderExt;
|
||||
|
||||
pub static CHAR_LAYOUT: Layout = Layout::u8();
|
||||
|
||||
|
@ -36,7 +37,11 @@ pub(crate) fn decode_from_utf8_result<'a, 'ctx, 'env>(
|
|||
);
|
||||
|
||||
builder
|
||||
.build_load(result_ptr_cast, "load_utf8_validate_bytes_result")
|
||||
.new_build_load(
|
||||
record_type,
|
||||
result_ptr_cast,
|
||||
"load_utf8_validate_bytes_result",
|
||||
)
|
||||
.into_struct_value()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -527,7 +527,9 @@ fn build_list_eq_help<'a, 'ctx, 'env>(
|
|||
builder.build_unconditional_branch(loop_bb);
|
||||
builder.position_at_end(loop_bb);
|
||||
|
||||
let curr_index = builder.build_load(index_alloca, "index").into_int_value();
|
||||
let curr_index = builder
|
||||
.new_build_load(env.ptr_int(), index_alloca, "index")
|
||||
.into_int_value();
|
||||
|
||||
// #index < end
|
||||
let loop_end_cond =
|
||||
|
@ -1255,12 +1257,12 @@ fn eq_ptr_to_struct<'a, 'ctx, 'env>(
|
|||
|
||||
let struct1 = env
|
||||
.builder
|
||||
.build_load(struct1_ptr, "load_struct1")
|
||||
.new_build_load(wrapper_type, struct1_ptr, "load_struct1")
|
||||
.into_struct_value();
|
||||
|
||||
let struct2 = env
|
||||
.builder
|
||||
.build_load(struct2_ptr, "load_struct2")
|
||||
.new_build_load(wrapper_type, struct2_ptr, "load_struct2")
|
||||
.into_struct_value();
|
||||
|
||||
build_struct_eq(
|
||||
|
|
|
@ -415,7 +415,7 @@ impl<'ctx> RocUnion<'ctx> {
|
|||
}
|
||||
|
||||
env.builder
|
||||
.build_load(tag_alloca, "load_tag")
|
||||
.new_build_load(self.struct_type(), tag_alloca, "load_tag")
|
||||
.into_struct_value()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,8 +102,10 @@ fn read_state<'a, 'ctx, 'env>(
|
|||
let one = env.ptr_int().const_int(1, false);
|
||||
let offset_ptr = pointer_at_offset(env.builder, env.ptr_int(), ptr, one);
|
||||
|
||||
let count = env.builder.build_load(ptr, "load_count");
|
||||
let offset = env.builder.build_load(offset_ptr, "load_offset");
|
||||
let count = env.builder.new_build_load(env.ptr_int(), ptr, "load_count");
|
||||
let offset = env
|
||||
.builder
|
||||
.new_build_load(env.ptr_int(), offset_ptr, "load_offset");
|
||||
|
||||
(count.into_int_value(), offset.into_int_value())
|
||||
}
|
||||
|
@ -1033,7 +1035,8 @@ fn build_clone_builtin<'a, 'ctx, 'env>(
|
|||
bd.build_int_mul(element_stack_size, index, "current_offset");
|
||||
let current_offset =
|
||||
bd.build_int_add(elements_start_offset, current_offset, "current_offset");
|
||||
let current_extra_offset = bd.build_load(rest_offset, "element_offset");
|
||||
let current_extra_offset =
|
||||
bd.new_build_load(env.ptr_int(), rest_offset, "element_offset");
|
||||
|
||||
let offset = current_offset;
|
||||
let extra_offset = current_extra_offset.into_int_value();
|
||||
|
@ -1064,7 +1067,7 @@ fn build_clone_builtin<'a, 'ctx, 'env>(
|
|||
|
||||
incrementing_elem_loop(env, parent, *elem, elements, len, "index", body);
|
||||
|
||||
bd.build_load(rest_offset, "rest_start_offset")
|
||||
bd.new_build_load(env.ptr_int(), rest_offset, "rest_start_offset")
|
||||
.into_int_value()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::llvm::bitcode::call_void_bitcode_fn;
|
||||
use crate::llvm::build::{add_func, get_panic_msg_ptr, get_panic_tag_ptr, C_CALL_CONV};
|
||||
use crate::llvm::build::{add_func, get_panic_msg_ptr, get_panic_tag_ptr, BuilderExt, C_CALL_CONV};
|
||||
use crate::llvm::build::{CCReturn, Env, FunctionSpec};
|
||||
use crate::llvm::convert::zig_str_type;
|
||||
use inkwell::module::Linkage;
|
||||
use inkwell::types::BasicType;
|
||||
use inkwell::values::BasicValue;
|
||||
|
@ -217,7 +218,12 @@ pub fn add_sjlj_roc_panic(env: &Env<'_, '_, '_>) {
|
|||
roc_target::PtrWidth::Bytes4 => roc_str_arg,
|
||||
// On 64-bit we pass RocStrs by reference internally
|
||||
roc_target::PtrWidth::Bytes8 => {
|
||||
builder.build_load(roc_str_arg.into_pointer_value(), "load_roc_str")
|
||||
let str_typ = zig_str_type(env);
|
||||
builder.new_build_load(
|
||||
str_typ,
|
||||
roc_str_arg.into_pointer_value(),
|
||||
"load_roc_str",
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ use crate::llvm::{
|
|||
},
|
||||
build::{
|
||||
complex_bitcast_check_size, create_entry_block_alloca, function_value_by_func_spec,
|
||||
load_roc_value, roc_function_call, RocReturn,
|
||||
load_roc_value, roc_function_call, BuilderExt, RocReturn,
|
||||
},
|
||||
build_list::{
|
||||
list_append_unsafe, list_capacity, list_concat, list_drop_at, list_get_unsafe, list_len,
|
||||
|
@ -464,7 +464,8 @@ pub(crate) fn run_low_level<'a, 'ctx, 'env>(
|
|||
"cast",
|
||||
);
|
||||
|
||||
env.builder.build_load(cast_result, "load_result")
|
||||
env.builder
|
||||
.new_build_load(return_type, cast_result, "load_result")
|
||||
}
|
||||
Unix => {
|
||||
let result = call_str_bitcode_fn(
|
||||
|
@ -1693,7 +1694,7 @@ fn dec_binop_with_overflow<'a, 'ctx, 'env>(
|
|||
}
|
||||
|
||||
env.builder
|
||||
.build_load(return_alloca, "load_dec")
|
||||
.new_build_load(return_type, return_alloca, "load_dec")
|
||||
.into_struct_value()
|
||||
}
|
||||
|
||||
|
@ -2082,15 +2083,19 @@ fn int_abs_with_overflow<'a, 'ctx, 'env>(
|
|||
|
||||
let xored_arg = bd.build_xor(
|
||||
arg,
|
||||
bd.build_load(shifted_alloca, shifted_name).into_int_value(),
|
||||
bd.new_build_load(int_type, shifted_alloca, shifted_name)
|
||||
.into_int_value(),
|
||||
"xor_arg_shifted",
|
||||
);
|
||||
|
||||
BasicValueEnum::IntValue(bd.build_int_sub(
|
||||
xored_arg,
|
||||
bd.build_load(shifted_alloca, shifted_name).into_int_value(),
|
||||
"sub_xored_shifted",
|
||||
))
|
||||
BasicValueEnum::IntValue(
|
||||
bd.build_int_sub(
|
||||
xored_arg,
|
||||
bd.new_build_load(int_type, shifted_alloca, shifted_name)
|
||||
.into_int_value(),
|
||||
"sub_xored_shifted",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn build_float_unary_op<'a, 'ctx, 'env>(
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::llvm::build::{
|
|||
WhenRecursive, FAST_CALL_CONV,
|
||||
};
|
||||
use crate::llvm::build_list::{incrementing_elem_loop, list_len, load_list};
|
||||
use crate::llvm::convert::{basic_type_from_layout, RocUnion};
|
||||
use crate::llvm::convert::{basic_type_from_layout, zig_str_type, RocUnion};
|
||||
use bumpalo::collections::Vec;
|
||||
use inkwell::basic_block::BasicBlock;
|
||||
use inkwell::module::Linkage;
|
||||
|
@ -100,7 +100,7 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
|||
|
||||
fn get_refcount<'a, 'env>(&self, env: &Env<'a, 'ctx, 'env>) -> IntValue<'ctx> {
|
||||
env.builder
|
||||
.build_load(self.value, "get_refcount")
|
||||
.new_build_load(env.ptr_int(), self.value, "get_refcount")
|
||||
.into_int_value()
|
||||
}
|
||||
|
||||
|
@ -804,8 +804,9 @@ fn modify_refcount_str_help<'a, 'ctx, 'env>(
|
|||
let arg_val = if Layout::Builtin(Builtin::Str)
|
||||
.is_passed_by_reference(env.layout_interner, env.target_info)
|
||||
{
|
||||
let str_type = zig_str_type(env);
|
||||
env.builder
|
||||
.build_load(arg_val.into_pointer_value(), "load_str_to_stack")
|
||||
.new_build_load(str_type, arg_val.into_pointer_value(), "load_str_to_stack")
|
||||
} else {
|
||||
// it's already a struct, just do nothing
|
||||
debug_assert!(arg_val.is_struct_value());
|
||||
|
@ -1240,9 +1241,11 @@ fn build_rec_union_recursive_decrement<'a, 'ctx, 'env>(
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let ptr_as_i64_ptr = env
|
||||
.builder
|
||||
.build_load(elem_pointer, "load_recursive_pointer");
|
||||
let ptr_as_i64_ptr = env.builder.new_build_load(
|
||||
env.context.i64_type().ptr_type(AddressSpace::Generic),
|
||||
elem_pointer,
|
||||
"load_recursive_pointer",
|
||||
);
|
||||
|
||||
debug_assert!(ptr_as_i64_ptr.is_pointer_value());
|
||||
|
||||
|
@ -1610,7 +1613,11 @@ fn modify_refcount_nonrecursive_help<'a, 'ctx, 'env>(
|
|||
|
||||
let tag_id = env
|
||||
.builder
|
||||
.build_load(tag_id_ptr, "load_tag_id")
|
||||
.new_build_load(
|
||||
basic_type_from_layout(env, &union_layout.tag_id_layout()),
|
||||
tag_id_ptr,
|
||||
"load_tag_id",
|
||||
)
|
||||
.into_int_value();
|
||||
|
||||
let tag_id_u8 =
|
||||
|
@ -1678,7 +1685,11 @@ fn modify_refcount_nonrecursive_help<'a, 'ctx, 'env>(
|
|||
.unwrap();
|
||||
|
||||
// This is the actual pointer to the recursive data.
|
||||
let field_value = env.builder.build_load(field_ptr, "load_recursive_pointer");
|
||||
let field_value = env.builder.new_build_load(
|
||||
env.context.i64_type().ptr_type(AddressSpace::Generic),
|
||||
field_ptr,
|
||||
"load_recursive_pointer",
|
||||
);
|
||||
|
||||
debug_assert!(field_value.is_pointer_value());
|
||||
|
||||
|
@ -1711,7 +1722,11 @@ fn modify_refcount_nonrecursive_help<'a, 'ctx, 'env>(
|
|||
if field_layout.is_passed_by_reference(env.layout_interner, env.target_info) {
|
||||
field_ptr.into()
|
||||
} else {
|
||||
env.builder.build_load(field_ptr, "field_value")
|
||||
env.builder.new_build_load(
|
||||
basic_type_from_layout(env, field_layout),
|
||||
field_ptr,
|
||||
"field_value",
|
||||
)
|
||||
};
|
||||
|
||||
modify_refcount_layout_help(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue