From a7eae239f037cfe724cf74f7c559fed9dd87bfde Mon Sep 17 00:00:00 2001 From: Brendan Hansknecht Date: Mon, 16 Sep 2024 16:47:20 -0700 Subject: [PATCH] Avoid explicit tag padding Explicit padding changes the c-abi when passed to/returned from functions. This is leading to incorrect loading of types like `Task U64 {}`. --- crates/compiler/gen_llvm/src/llvm/convert.rs | 12 ------------ crates/glue/src/RustGlue.roc | 20 -------------------- 2 files changed, 32 deletions(-) diff --git a/crates/compiler/gen_llvm/src/llvm/convert.rs b/crates/compiler/gen_llvm/src/llvm/convert.rs index 73eb20f344..257f661363 100644 --- a/crates/compiler/gen_llvm/src/llvm/convert.rs +++ b/crates/compiler/gen_llvm/src/llvm/convert.rs @@ -315,17 +315,6 @@ impl<'ctx> RocUnion<'ctx> { .as_basic_type_enum(); let struct_type = if let Some(tag_type) = tag_type { - let tag_width = match tag_type { - TagType::I8 => 1, - TagType::I16 => 2, - }; - - let tag_padding = round_up_to_alignment(tag_width, data_align) - tag_width; - let tag_padding_type = context - .i8_type() - .array_type(tag_padding) - .as_basic_type_enum(); - context.struct_type( &[ alignment_array_type, @@ -334,7 +323,6 @@ impl<'ctx> RocUnion<'ctx> { TagType::I8 => context.i8_type().into(), TagType::I16 => context.i16_type().into(), }, - tag_padding_type, ], false, ) diff --git a/crates/glue/src/RustGlue.roc b/crates/glue/src/RustGlue.roc index 61402a838d..0531aaa602 100644 --- a/crates/glue/src/RustGlue.roc +++ b/crates/glue/src/RustGlue.roc @@ -1288,7 +1288,6 @@ generateRecursiveTagUnion = \buf, types, id, tagUnionName, tags, discriminantSiz union $(unionName) { """ |> \b -> List.walk tags b (generateUnionField types) - |> generateTagUnionSizer types id tags |> Str.concat "}\n\n" |> generateRocRefcounted types unionType escapedName @@ -1337,25 +1336,6 @@ writeTagImpls = \buf, tags, discriminantName, indents, f -> |> writeIndents indents |> Str.concat "}\n" -generateTagUnionSizer : Str, Types, TypeId, _ -> Str -generateTagUnionSizer = \buf, types, id, tags -> - if List.len tags > 1 then - # When there's a discriminant (so, multiple tags) and there is - # no alignment padding after the largest variant, - # the compiler will make extra room for the discriminant. - # We need that to be reflected in the overall size of the enum, - # so add an extra variant with the appropriate size. - # - # (Do this even if theoretically shouldn't be necessary, since - # there's no runtime cost and it more explicitly syncs the - # union's size with what we think it should be.) - size = getSizeRoundedToAlignment types id - sizeStr = Num.toStr size - - Str.concat buf "$(indent)_sizer: [u8; $(sizeStr)],\n" - else - buf - generateDiscriminant = \buf, types, name, tags, size -> if size > 0 then enumType =