step 1: Deriv works and has no valgrind problems

This commit is contained in:
Folkert 2022-03-26 17:56:56 +01:00
parent baec1c2de3
commit 71c11784a0
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
6 changed files with 34 additions and 21 deletions

View file

@ -83,7 +83,8 @@ pub fn call_str_bitcode_fn<'a, 'ctx, 'env>(
call_void_bitcode_fn(env, &arguments, fn_name);
env.builder.build_load(result, "load_str")
// TODO make this function return a PointerValue
result.into()
}
pub fn call_void_bitcode_fn<'a, 'ctx, 'env>(

View file

@ -824,7 +824,7 @@ pub fn build_exp_literal<'a, 'ctx, 'env>(
.as_pointer_value()
};
env.builder.build_load(global, "load_constant_string")
global.into()
}
}
}
@ -1500,7 +1500,7 @@ fn build_tag_field_value<'a, 'ctx, 'env>(
"cast_recursive_pointer",
)
} else if tag_field_layout.is_passed_by_reference() {
debug_assert!(value.is_pointer_value());
debug_assert!(value.is_pointer_value(), "{:#?}", value);
// NOTE: we rely on this being passed to `store_roc_value` so that
// the value is memcpy'd
@ -2755,6 +2755,7 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
let (value, layout) = load_symbol_and_layout(scope, symbol);
match layout {
Layout::Builtin(Builtin::Str) => todo!(),
Layout::Builtin(Builtin::List(element_layout)) => {
debug_assert!(value.is_struct_value());
let alignment = element_layout.alignment_bytes(env.target_info);
@ -6203,6 +6204,11 @@ enum RocReturn {
impl RocReturn {
fn roc_return_by_pointer(layout: Layout) -> bool {
match layout {
Layout::Builtin(builtin) => {
use Builtin::*;
matches!(builtin, Str)
}
Layout::Union(UnionLayout::NonRecursive(_)) => true,
Layout::LambdaSet(lambda_set) => {
RocReturn::roc_return_by_pointer(lambda_set.runtime_representation())
@ -6332,7 +6338,7 @@ fn build_foreign_symbol<'a, 'ctx, 'env>(
cc_argument_types.push(to_cc_type(env, layout));
let basic_type = basic_type_from_layout(env, layout);
let basic_type = argument_type_from_layout(env, layout);
fastcc_argument_types.push(basic_type);
arguments.push(value);
@ -6402,7 +6408,16 @@ fn build_foreign_symbol<'a, 'ctx, 'env>(
cc_arguments.push(as_cc_type.into());
} else {
todo!("C <-> Fastcc interaction that we haven't seen before")
// eprintln!("C type: {:?}", cc_type);
// eprintln!("Fastcc type: {:?}", param.get_type());
// todo!("C <-> Fastcc interaction that we haven't seen before")
let as_cc_type = env.builder.build_pointer_cast(
param.into_pointer_value(),
cc_type.into_pointer_type(),
"to_cc_type_ptr",
);
cc_arguments.push(as_cc_type.into());
}
}
}

View file

@ -128,14 +128,10 @@ pub fn str_concat<'a, 'ctx, 'env>(
str2_symbol: Symbol,
) -> BasicValueEnum<'ctx> {
// swap the arguments; second argument comes before the second in the output string
let str1_c_abi = str_symbol_to_c_abi(env, scope, str1_symbol);
let str2_c_abi = str_symbol_to_c_abi(env, scope, str2_symbol);
let str1 = load_symbol(scope, &str1_symbol);
let str2 = load_symbol(scope, &str2_symbol);
call_str_bitcode_fn(
env,
&[str1_c_abi.into(), str2_c_abi.into()],
bitcode::STR_CONCAT,
)
call_str_bitcode_fn(env, &[str1, str2], bitcode::STR_CONCAT)
}
/// Str.join : List Str, Str -> Str
@ -398,12 +394,5 @@ pub fn str_equal<'a, 'ctx, 'env>(
value1: BasicValueEnum<'ctx>,
value2: BasicValueEnum<'ctx>,
) -> BasicValueEnum<'ctx> {
let str1_i128 = str_to_c_abi(env, value1);
let str2_i128 = str_to_c_abi(env, value2);
call_bitcode_fn(
env,
&[str1_i128.into(), str2_i128.into()],
bitcode::STR_EQUAL,
)
call_bitcode_fn(env, &[value1, value2], bitcode::STR_EQUAL)
}

View file

@ -865,6 +865,9 @@ fn modify_refcount_str_help<'a, 'ctx, 'env>(
let parent = fn_val;
let arg_val = env
.builder
.build_load(arg_val.into_pointer_value(), "load_str_to_stack");
let str_wrapper = arg_val.into_struct_value();
let capacity = builder