Skip to content

Are tuples shared? #12159

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
htqx opened this issue Jul 18, 2022 · 3 comments
Closed

Are tuples shared? #12159

htqx opened this issue Jul 18, 2022 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@htqx
Copy link

htqx commented Jul 18, 2022

Zig Version

0.10.0-dev.2977+7d2e14267

Steps to Reproduce

var list = .{"sss", 1,2,3};
    var list2 = @TypeOf(list) {.@"0" = "xxx", .@"1" = 4, .@"2"=5,
        .@"3" = 6};
    if (&list == &list2) print("{}?\n",.{list2});

print : { [3:0]u8@203ffa, 1, 2, 3 }?

Is this a bug or a mechanism?

Expected Behavior

new tuple

Actual Behavior

list2 = list

@htqx htqx added the bug Observed behavior contradicts documented or intended behavior label Jul 18, 2022
@batiati
Copy link
Contributor

batiati commented Jul 18, 2022

All fields are comptime values, so the tuple is zero len and unique. Try to initialize some field with a runtime value and it should work as expected.

I think it behaves correctly, but it should give a compiler error on the second initialization.

@Vexu Vexu added the stage1 The process of building from source via WebAssembly and the C backend. label Jul 19, 2022
@Vexu Vexu added this to the 0.12.0 milestone Jul 19, 2022
@ghost
Copy link

ghost commented Jul 21, 2022

This makes no sense to me.

All fields are comptime values, so the tuple is zero len and unique.

But why isn't the second one just another zero len and unique value?

@batiati
Copy link
Contributor

batiati commented Jul 21, 2022

The second one should not be possible to initialize, this current issue is the same case as #5497 but using a tuple instead of a struct.

pub fn main() !void {

    const AllComptime = struct {
        comptime v0: []const u8 = "sss",
        comptime v1: u32 = 1,
        comptime v2: u32 = 2,
    };

    var allComptime = AllComptime { .v0 = "sss", .v1 = 1, .v2 = 2 };
    var allComptime2 = AllComptime { .v0 = "abc", .v1 = 2, .v2 = 3 };

    std.debug.print("SizeOf AllComptime = {}\n", .{ @sizeOf(AllComptime) });
    if (&allComptime == &allComptime2) std.debug.print("Same address\n", .{});
$ zig build run
SizeOf AllComptime = 0
Same address

wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 16, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 16, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 17, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 17, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 18, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 18, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 21, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Dec 27, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

4 participants