Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary padding between tag union payload and discriminant #7171

Open
svcxc opened this issue Oct 17, 2024 · 1 comment
Open

Unnecessary padding between tag union payload and discriminant #7171

svcxc opened this issue Oct 17, 2024 · 1 comment
Labels
enhancement New feature or request intermediate issue Likely good for someone who has completed a few other issues

Comments

@svcxc
Copy link
Contributor

svcxc commented Oct 17, 2024

In a non-recursive tag union layout, the discriminant deliberately comes after the payload in memory. This is to allow it to be placed in what might otherwise become padding. According to roc glue, this optimization is not currently taking place. Given the following glue platform:

platform "test-platform"
    requires {} { main : _ }
    exposes []
    packages {}
    imports []
    provides [mainForHost]

mainForHost : [A U16 U8, B]
mainForHost = main

The following shape is emitted by the glue platform for mainForHost:

(TagUnion (NonRecursive {discriminantOffset: 4, discriminantSize: 1, ...))

Ideally discriminantOffset should equal 3, as that byte is now unnecessarily used as padding. This bug does not break anything, but it is a missed optimization.

@bhansconnect bhansconnect added enhancement New feature or request intermediate issue Likely good for someone who has completed a few other issues labels Oct 17, 2024
@bhansconnect
Copy link
Contributor

My guess for this issue is that we are representing the union as {payload: {u16, u8}, tag: u8}. This leads to extra padding and is not what we want. We want {u16, u8, u8} where the last u8 in the struct is the tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request intermediate issue Likely good for someone who has completed a few other issues
Projects
None yet
Development

No branches or pull requests

2 participants