-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
design flaw with equality comparison of tagged unions #2251
Comments
You can compare tags of
|
This is tested and working in master branch now. |
Apologies - spoke too soon. Not sure what I was thinking of here. |
Anyway aarch64 has test coverage in the CI now; this is a different issue. I'll retitle it. const std = @import("std");
const builtin = @import("builtin");
test "" {
var arch: builtin.Arch = undefined;
var os: builtin.Os = undefined;
const is_native = (os == builtin.os and arch == builtin.arch);
std.debug.warn("is_native = {}\n", is_native);
} The issue is that it's weird that this test passes for -target x86_64-linux but it fails for -target aarch64-linux:
I think this is a flaw in the language. |
(not relevant, see below) |
That's #3330 |
x86_64 actually has three abis when it comes to vectors: sse2 (128-bit), avx2 (256-bit), and avx512f (512-bit): %xmm, %ymm, %zmm, and I'd like to extend the ABI enum so that we can forbid exporting vector widths that the current ABI can't handle. |
This example posted by Andrew no longer works:
First an error saying that the test can't have an empty name, then an error saying that builtin.Arch doesn't exist But I'm wondering about the ability to compare tagged unions in general, because this example seems to show that in the past you could compare tagged unions, but now you can't?
This fails for me with Was the ability to compare tagged unions removed? If so, why?!? |
It would really be useful to be able to compare tagged unions. For example, I worked around this limitation just now with code like this:
|
|
So what is the status of this issue? If not being able to compare tagged unions is intended (it shouldn't be), what's the bug? |
Looking at 0.4.0 const U = union(enum) {
a: u8,
b,
};
const b = U.b; // for x86_64
const b = U{ .b = {} }; // for arm
pub fn main() void {
var a = U{ .a = 4 };
_ = a == b;
} |
see #2251 (comment)
This is currently breaking the tests on Arm64 because
builtin.arch
is aunion(enum)
and the tests try to do an equality comparison on it.It is slightly weird to do a comparison on a
union
as it would always bit a bit-wise comparison, and not a float comparison.Perhaps there is another way to fix this.
The text was updated successfully, but these errors were encountered: