Skip to content

Have sign bit indicating error in error union #9956

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

Closed
ArborealAnole opened this issue Oct 16, 2021 · 1 comment
Closed

Have sign bit indicating error in error union #9956

ArborealAnole opened this issue Oct 16, 2021 · 1 comment
Milestone

Comments

@ArborealAnole
Copy link

ArborealAnole commented Oct 16, 2021

const eu = error{ problem1, problem2, problem3 }!u63;
const out = std.io.getStdOut().writer();
try out.print("error union size: {}\n", .{@sizeOf(eu)});
try out.print("test size: {}\n", .{@sizeOf(?u63)});

output:

error union size: 16
?u63 size: 16

Why not just store the error codes as two's complement negative integers in the same space the u63 would be stored in the error union? That way the error union size would be only 8 bytes.

In the error union, it would also be possible to try fitting in error associated-values (which were proposed in #2647), though that could involve more complexity to varying degrees. E.g. you could truncate the negative i64 error code to i32 and have room for a u32 error-associated value in this case.

Also, I know I might eventually be able to use a proposed arbitrary-range integer type as in #3806 with 0 as sentinel for absence of value, but if for some reason I wanted 0 to be a valid value while sacrificing 2^63 valid values, the absence of a value for the optional u63 could be indicated by the sign bit (MSB) being 1.

@AssortedFantasy
Copy link

Its not implemented yet but this is #104

@andrewrk andrewrk added this to the 0.9.0 milestone Nov 20, 2021
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

No branches or pull requests

3 participants