From 0b893eb9723f66e05b2863dce1fdfcbefde8202a Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 12 Sep 2021 14:01:41 +0200 Subject: [PATCH 1/2] remove alignment bump again --- compiler/gen_llvm/src/llvm/build_str.rs | 24 ++---------------------- compiler/mono/src/layout.rs | 4 ++-- compiler/test_gen/src/gen_primitives.rs | 2 ++ 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/compiler/gen_llvm/src/llvm/build_str.rs b/compiler/gen_llvm/src/llvm/build_str.rs index 87a8c50c57..4c3c815b60 100644 --- a/compiler/gen_llvm/src/llvm/build_str.rs +++ b/compiler/gen_llvm/src/llvm/build_str.rs @@ -268,25 +268,19 @@ fn decode_from_utf8_result<'a, 'ctx, 'env>( let ctx = env.context; let fields = match env.ptr_bytes { - 8 => [ + 8 | 4 => [ env.ptr_int().into(), super::convert::zig_str_type(env).into(), env.context.bool_type().into(), ctx.i8_type().into(), ], - 4 => [ - super::convert::zig_str_type(env).into(), - env.ptr_int().into(), - env.context.bool_type().into(), - ctx.i8_type().into(), - ], _ => unreachable!(), }; let record_type = env.context.struct_type(&fields, false); match env.ptr_bytes { - 8 => { + 8 | 4 => { let zig_struct = builder .build_load(pointer, "load_utf8_validate_bytes_result") .into_struct_value(); @@ -309,20 +303,6 @@ fn decode_from_utf8_result<'a, 'ctx, 'env>( struct_from_fields(env, record_type, values.iter().copied().enumerate()) } - 4 => { - let result_ptr_cast = env - .builder - .build_bitcast( - pointer, - record_type.ptr_type(AddressSpace::Generic), - "to_unnamed", - ) - .into_pointer_value(); - - builder - .build_load(result_ptr_cast, "load_utf8_validate_bytes_result") - .into_struct_value() - } _ => unreachable!(), } } diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 3568ce5045..acc4c5fd78 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -1158,8 +1158,8 @@ impl<'a> Builtin<'a> { // // In webassembly, For that to be safe // they must be aligned to allow such access - List(_) | EmptyList => pointer_size.max(8), - Str | EmptyStr => pointer_size.max(8), + List(_) | EmptyList => pointer_size, + Str | EmptyStr => pointer_size, } } diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 9a43cb8a78..f71ce6e98f 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -2531,6 +2531,8 @@ fn pattern_match_unit_tag() { ); } +// see for why this is disabled on wasm32 https://github.com/rtfeldman/roc/issues/1687 +#[cfg(not(feature = "wasm-cli-run"))] #[test] fn mirror_llvm_alignment_padding() { // see https://github.com/rtfeldman/roc/issues/1569 From c0cfd6ac161da2beb54560857e2484f8e0f506ea Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 12 Sep 2021 14:28:44 +0200 Subject: [PATCH 2/2] make conversion a cast again --- compiler/builtins/bitcode/src/str.zig | 2 +- compiler/gen_llvm/src/llvm/build_str.rs | 33 +++++++++---------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/compiler/builtins/bitcode/src/str.zig b/compiler/builtins/bitcode/src/str.zig index 801550663c..2172e693d7 100644 --- a/compiler/builtins/bitcode/src/str.zig +++ b/compiler/builtins/bitcode/src/str.zig @@ -1150,8 +1150,8 @@ fn strToBytes(arg: RocStr) RocList { } const FromUtf8Result = extern struct { - string: RocStr, byte_index: usize, + string: RocStr, is_ok: bool, problem_code: Utf8ByteProblem, }; diff --git a/compiler/gen_llvm/src/llvm/build_str.rs b/compiler/gen_llvm/src/llvm/build_str.rs index 4c3c815b60..80bfa0fa3a 100644 --- a/compiler/gen_llvm/src/llvm/build_str.rs +++ b/compiler/gen_llvm/src/llvm/build_str.rs @@ -1,5 +1,5 @@ use crate::llvm::bitcode::{call_bitcode_fn, call_void_bitcode_fn}; -use crate::llvm::build::{complex_bitcast, struct_from_fields, Env, Scope}; +use crate::llvm::build::{complex_bitcast, Env, Scope}; use crate::llvm::build_list::{allocate_list, call_bitcode_fn_returns_list, store_list}; use inkwell::builder::Builder; use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue, StructValue}; @@ -281,27 +281,18 @@ fn decode_from_utf8_result<'a, 'ctx, 'env>( match env.ptr_bytes { 8 | 4 => { - let zig_struct = builder - .build_load(pointer, "load_utf8_validate_bytes_result") - .into_struct_value(); + let result_ptr_cast = env + .builder + .build_bitcast( + pointer, + record_type.ptr_type(AddressSpace::Generic), + "to_unnamed", + ) + .into_pointer_value(); - let string = builder - .build_extract_value(zig_struct, 0, "string") - .unwrap(); - - let byte_index = builder - .build_extract_value(zig_struct, 1, "byte_index") - .unwrap(); - - let is_ok = builder.build_extract_value(zig_struct, 2, "is_ok").unwrap(); - - let problem_code = builder - .build_extract_value(zig_struct, 3, "problem_code") - .unwrap(); - - let values = [byte_index, string, is_ok, problem_code]; - - struct_from_fields(env, record_type, values.iter().copied().enumerate()) + builder + .build_load(result_ptr_cast, "load_utf8_validate_bytes_result") + .into_struct_value() } _ => unreachable!(), }