mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
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 {}`.
This commit is contained in:
parent
38674aeb94
commit
a7eae239f0
2 changed files with 0 additions and 32 deletions
|
@ -315,17 +315,6 @@ impl<'ctx> RocUnion<'ctx> {
|
||||||
.as_basic_type_enum();
|
.as_basic_type_enum();
|
||||||
|
|
||||||
let struct_type = if let Some(tag_type) = tag_type {
|
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(
|
context.struct_type(
|
||||||
&[
|
&[
|
||||||
alignment_array_type,
|
alignment_array_type,
|
||||||
|
@ -334,7 +323,6 @@ impl<'ctx> RocUnion<'ctx> {
|
||||||
TagType::I8 => context.i8_type().into(),
|
TagType::I8 => context.i8_type().into(),
|
||||||
TagType::I16 => context.i16_type().into(),
|
TagType::I16 => context.i16_type().into(),
|
||||||
},
|
},
|
||||||
tag_padding_type,
|
|
||||||
],
|
],
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1288,7 +1288,6 @@ generateRecursiveTagUnion = \buf, types, id, tagUnionName, tags, discriminantSiz
|
||||||
union $(unionName) {
|
union $(unionName) {
|
||||||
"""
|
"""
|
||||||
|> \b -> List.walk tags b (generateUnionField types)
|
|> \b -> List.walk tags b (generateUnionField types)
|
||||||
|> generateTagUnionSizer types id tags
|
|
||||||
|> Str.concat "}\n\n"
|
|> Str.concat "}\n\n"
|
||||||
|> generateRocRefcounted types unionType escapedName
|
|> generateRocRefcounted types unionType escapedName
|
||||||
|
|
||||||
|
@ -1337,25 +1336,6 @@ writeTagImpls = \buf, tags, discriminantName, indents, f ->
|
||||||
|> writeIndents indents
|
|> writeIndents indents
|
||||||
|> Str.concat "}\n"
|
|> 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 ->
|
generateDiscriminant = \buf, types, name, tags, size ->
|
||||||
if size > 0 then
|
if size > 0 then
|
||||||
enumType =
|
enumType =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue