Skip to content

Conversation

@feds01
Copy link
Contributor

@feds01 feds01 commented Apr 21, 2025

This PR implements the #size_of directive, which allows the caller to inspect
and use the size of a type within the program.

This means that we can now do things like:

foo := () => {
    ty_size := #size_of u32

    // `ty_size` is now a constant expression that can be used in the program.
    // `ty_size` has a type of `usize`
    // `ty_size` is a compile-time constant of 4.
}

The implementation itself simply captures all of these calls and expands them during TIR to then indicate that they should be in fact expanded at lowering or evaluation.

There are several restrictions to where the directive can be applied to:

  • #size_of can only be called on types & expressions that look like types.

@feds01 feds01 self-assigned this Apr 21, 2025
@feds01 feds01 requested a review from kontheocharis April 21, 2025 16:19
Copy link
Collaborator

@kontheocharis kontheocharis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice and clean

@feds01 feds01 merged commit a31e0de into main Apr 21, 2025
1 check failed
@feds01 feds01 deleted the directives/size_of branch April 21, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants