Merge branch 'trunk' of github.com:rtfeldman/roc into list-str-capacity

This commit is contained in:
Brian Carroll 2022-03-11 19:28:13 +00:00
commit 456d8ff9cb
41 changed files with 790 additions and 210 deletions

View file

@ -24,7 +24,7 @@ use crate::llvm::build_str::{
};
use crate::llvm::compare::{generic_eq, generic_neq};
use crate::llvm::convert::{
self, basic_type_from_builtin, basic_type_from_layout, basic_type_from_layout_1,
self, argument_type_from_layout, basic_type_from_builtin, basic_type_from_layout,
block_of_memory_slices, zig_str_type,
};
use crate::llvm::refcounting::{
@ -1100,6 +1100,30 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
..
} => build_tag(env, scope, union_layout, *tag_id, arguments, None, parent),
ExprBox { symbol } => {
let (value, layout) = load_symbol_and_layout(scope, symbol);
let basic_type = basic_type_from_layout(env, layout);
let allocation = reserve_with_refcount_help(
env,
basic_type,
layout.stack_size(env.target_info),
layout.alignment_bytes(env.target_info),
);
env.builder.build_store(allocation, value);
allocation.into()
}
ExprUnbox { symbol } => {
let value = load_symbol(scope, symbol);
debug_assert!(value.is_pointer_value());
env.builder
.build_load(value.into_pointer_value(), "load_boxed_value")
}
Reset { symbol, .. } => {
let (tag_ptr, layout) = load_symbol_and_layout(scope, symbol);
let tag_ptr = tag_ptr.into_pointer_value();
@ -1798,7 +1822,7 @@ pub fn tag_pointer_read_tag_id<'a, 'ctx, 'env>(
let masked = env.builder.build_and(as_int, mask_intval, "mask");
env.builder
.build_int_cast(masked, env.context.i8_type(), "to_u8")
.build_int_cast_sign_flag(masked, env.context.i8_type(), false, "to_u8")
}
pub fn tag_pointer_clear_tag_id<'a, 'ctx, 'env>(
@ -2553,6 +2577,7 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
let align_bytes = layout.alignment_bytes(env.target_info);
if align_bytes > 0 {
debug_assert!(value.is_pointer_value(), "{:?}\n{:?}", value, layout);
let value_ptr = value.into_pointer_value();
// We can only do this if the function itself writes data into this
@ -4197,7 +4222,7 @@ fn build_proc_header<'a, 'ctx, 'env>(
let mut arg_basic_types = Vec::with_capacity_in(args.len(), arena);
for (layout, _) in args.iter() {
let arg_type = basic_type_from_layout_1(env, layout);
let arg_type = argument_type_from_layout(env, layout);
arg_basic_types.push(arg_type);
}
@ -5864,8 +5889,11 @@ fn run_low_level<'a, 'ctx, 'env>(
let arg = load_symbol(scope, &args[0]).into_int_value();
let to = basic_type_from_layout(env, layout).into_int_type();
let to_signed = intwidth_from_layout(*layout).is_signed();
env.builder.build_int_cast(arg, to, "inc_cast").into()
env.builder
.build_int_cast_sign_flag(arg, to, to_signed, "inc_cast")
.into()
}
Eq => {
debug_assert_eq!(args.len(), 2);
@ -6091,6 +6119,10 @@ fn run_low_level<'a, 'ctx, 'env>(
unreachable!("these are higher order, and are handled elsewhere")
}
BoxExpr | UnboxExpr => {
unreachable!("The {:?} operation is turned into mono Expr", op)
}
PtrCast | RefCountInc | RefCountDec => {
unreachable!("Not used in LLVM backend: {:?}", op);
}
@ -6969,7 +7001,12 @@ fn build_int_unary_op<'a, 'ctx, 'env>(
let target_int_type = convert::int_type_from_int_width(env, target_int_width);
let target_int_val: BasicValueEnum<'ctx> = env
.builder
.build_int_cast(arg, target_int_type, "int_cast")
.build_int_cast_sign_flag(
arg,
target_int_type,
target_int_width.is_signed(),
"int_cast",
)
.into();
let return_type =