-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
std: std.MultiArrayList(TaggedUnion) will store the tag twice in Debug and ReleaseSafe #22785
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
Comments
It's possible to explicitly remove the safety tag of an untagged |
Here's test for anyone wondering: // multi_array_list.zig
pub const Bare = Bare: {
@setRuntimeSafety(false);
break :Bare @Type(.{ .@"union" = .{
.layout = u.layout,
.tag_type = null,
.fields = u.fields,
.decls = &.{},
} });
};
// main.zig
const std = @import("std");
const MultiArrayList = @import("multi_array_list.zig").MultiArrayList;
const Tag = enum(u32) { foo, bar };
pub const TaggedUnion = union(Tag) {
foo: u4,
bar: u32,
};
test {
const list: MultiArrayList(TaggedUnion) = undefined;
std.debug.assert(@sizeOf(@typeInfo(@TypeOf(list.items(.tags))).pointer.child) == 4);
std.debug.assert(@sizeOf(@typeInfo(@TypeOf(list.items(.data))).pointer.child) == 4);
} $ zig test -ODebug main.zig
All 9 tests passed. |
* add insertAssumeCapacity(), addOne(), addOneAssumeCapacity() * only store union tags once in Debug and ReleaseSafe as discussed in ziglang/zig#22785 * add all tests from std.MultiArrayList
std.MultiArrayList
will convert a tagged union into two fields. One for the tag and one for the untagged data. Problem is that the untagged data will also have a safety tag which counteracts the point of storing the tag separately. This will compile in ReleaseFast and ReleaseSmall but not in Debug and ReleaseSafe:The untagged union type is being constructed here. I don't think that internally using an
extern union
andpacked union
would resolve this since they have stricter requirements (well-defined in-memory layout, C ABI compatibility).The text was updated successfully, but these errors were encountered: