roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.49k stars 316 forks source link

Glue spec generating invalid rust #6012

Open lukewilliamboswell opened 1 year ago

lukewilliamboswell commented 1 year ago

Run bash platform/glue-gen.sh from the root directory.

Navigate to platform/src/glue_manual/src and there are at least two common issues.

Issue 1 Assertions

Generated assertions such as the following will fail

const _SIZE_CHECK_ConnectErr: () = assert!(core::mem::size_of::<ConnectErr>() == 40);

Issue 2 Impls

Generated struct for some types will be missing a comma between the f0, and f1 idents.

pub fn DirReadErr(f0: UnwrappedPath, f1: roc_std::RocStr) -> Self {
    Self {
        f0
        f1
    }
}
bhansconnect commented 1 year ago

const _SIZE_CHECK_ConnectErr: () = assert!(core::mem::size_of::() == 40);

This looks like a menial bug to me at first glance at least.

The failing assertion is for the union:

// const _SIZE_CHECK_union_ConnectErr: () = assert!(core::mem::size_of::<union_ConnectErr>() == 40);

It is simply wrong. 40 is the size of the tagged union, not the size of just the union without the tag. That should be 32. The check for the union as a whole looks correct:

const _SIZE_CHECK_ConnectErr: () = assert!(core::mem::size_of::<ConnectErr>() == 40);