diff --git a/cli/src/repl/eval.rs b/cli/src/repl/eval.rs index f75826c1a5..1375c19d54 100644 --- a/cli/src/repl/eval.rs +++ b/cli/src/repl/eval.rs @@ -247,7 +247,7 @@ fn jit_to_ast_help<'a>( *(ptr.add(offset as usize) as *const i16) as i64 } Builtin::Int64 => { - // used by non-recursive tag unions at the + // used by non-recursive unions at the // moment, remove if that is no longer the case *(ptr.add(offset as usize) as *const i64) as i64 } diff --git a/compiler/mono/src/layout.rs b/compiler/mono/src/layout.rs index 3b308b6c2c..7cfad1495f 100644 --- a/compiler/mono/src/layout.rs +++ b/compiler/mono/src/layout.rs @@ -636,6 +636,19 @@ impl<'a> Layout<'a> { } pub fn stack_size(&self, pointer_size: u32) -> u32 { + let width = self.stack_size_without_alignment(pointer_size); + let alignment = self.alignment_bytes(pointer_size); + + if alignment == 0 { + width + } else if width % alignment > 0 { + width + alignment - (width % alignment) + } else { + width + } + } + + fn stack_size_without_alignment(&self, pointer_size: u32) -> u32 { use Layout::*; match self { diff --git a/compiler/test_gen/src/gen_primitives.rs b/compiler/test_gen/src/gen_primitives.rs index 68c2b53142..c8fe4de948 100644 --- a/compiler/test_gen/src/gen_primitives.rs +++ b/compiler/test_gen/src/gen_primitives.rs @@ -2529,3 +2529,25 @@ fn pattern_match_unit_tag() { i64 ); } + +#[test] +fn mirror_llvm_alignment_padding() { + // see https://github.com/rtfeldman/roc/issues/1569 + assert_evals_to!( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + main : Str + main = + p1 = {name : "test1", test: 1 == 1 } + + List.map [p1, p1 ] (\{ test } -> if test then "pass" else "fail") + |> Str.joinWith "\n" + + "# + ), + RocStr::from_slice(b"pass\npass"), + RocStr + ); +}