Skip to content

Initial pass at new host ABI #7795

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

Merged
merged 14 commits into from
May 19, 2025
Prev Previous commit
Next Next commit
Rename ret to answer
  • Loading branch information
rtfeldman committed May 18, 2025
commit 609bac1e41a39edf5b38a4c0b0aabd52effc6215
4 changes: 2 additions & 2 deletions src/host_abi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn RocOps(comptime CallEnv: type, comptime HostFns: type) type {
pub const RocAlloc = struct {
alignment: usize,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this helps here since the struct has no padding, but in Zig std lib we've started using an Alignment type that stores the log2 value. It's pretty handy because you only need 6 bits to describe any alignment for a 64-bit address.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, that's a cool trick! I agree that it probably doesn't help here, but that's a good one to know for future reference. 🤘

length: usize,
ret: *anyopaque,
answer: *anyopaque,
};
Copy link
Contributor Author

@rtfeldman rtfeldman May 18, 2025

Choose a reason for hiding this comment

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

This is a bit different from how we're doing it in the Rust compiler. Some notes:

  • To avoid needing to get into the C calling convention at all, I continued using the "all functions take a single pointer and return void" thing with roc_alloc and friends.
    • The one exception is that I have them all take a second argument, the "env pointer" that's a pointer to whatever the host wants it to be - e.g. a pointer to an arena in case the host wants to use arena allocation for everything.
  • Since this is now different enough from the signature for something like malloc, I figured it would be fine to require that the host handle OOM itself rather than the Roc compiler generating an extra conditional to detect null and call roc_crashed if so. (All the hosts that anyone will use as templates to copy from will do this anyway, so I don't think it will be a problem.)


/// When RocOps.roc_dealloc gets called, it will be passed one of these.
Expand All @@ -87,7 +87,7 @@ pub const RocDealloc = struct {
pub const RocRealloc = struct {
alignment: usize,
new_length: usize,
ret: *anyopaque,
answer: *anyopaque,
};

/// The UTF-8 string message the host receives when a Roc program crashes
Expand Down
Loading