Skip to content

False dependency loop #14147

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
DerryAlex opened this issue Jan 1, 2023 · 6 comments
Closed

False dependency loop #14147

DerryAlex opened this issue Jan 1, 2023 · 6 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@DerryAlex
Copy link
Contributor

DerryAlex commented Jan 1, 2023

Zig Version

0.11.0-dev.923+a52dcdd3c

Steps to Reproduce and Observed Behavior

Possibly related #14005

Observed Behavior:

error: struct 'GLib.SListNullable' depends on itself
pub const SListNullable = packed struct {
                          ~~~~~~~^~~~~~
referenced by:
    SListImpl: /home/chief/workplace/gir-zig/generate/output/GLib.zig:8243:30
    SListNullable: /home/chief/workplace/gir-zig/generate/output/GLib.zig:8250:17
    SListNullable: /home/chief/workplace/gir-zig/generate/output/GLib.zig:8249:34
    SListImpl: /home/chief/workplace/gir-zig/generate/output/GLib.zig:8247:15

Related code

pub const SListImpl = extern struct { // L8243
    /// read write 
    Data: ?*anyopaque,
    /// read write 
    Next: core.SListNullable, // L8247
};
pub const SListNullable = packed struct { // L8249
    instance: ?*SListImpl, // L8250

    pub fn new(self: ?SList) SListNullable {
        return .{ .instance = if (self) |some| some.instance else null };
    }

    pub fn get(self: SListNullable) ?SList {
        return if (self.instance) |some| SList{ .instance = some } else null;
    }
};

I failed to narrow down this. If extracted into small files, it behaves correctly. Maybe there is something to do with the file size.

Possibly related infomation

// GLib.zig
const core = @import("core.zig");

// core.zig
const GLib = @import("GLib.zig");
pub usingnamespace GLib;

Expected Behavior

No error

@DerryAlex DerryAlex added the bug Observed behavior contradicts documented or intended behavior label Jan 1, 2023
@nektro
Copy link
Contributor

nektro commented Jan 1, 2023

don't think there's a bug here imo likely duplicate of #12325

@Vexu
Copy link
Member

Vexu commented Jan 1, 2023

Reduction:

const SListImpl = extern struct {
    Next: SListNullable,
};
const SListNullable = packed struct {
    instance: ?*SListImpl,
};
comptime {
    _ = @sizeOf(SListNullable) + 1;
}

Removing extern makes it work.

@jayschwa
Copy link
Contributor

This appears to be fixed in master after #17172 was merged.

@Vexu Vexu closed this as completed Sep 25, 2023
@jayschwa jayschwa modified the milestones: 0.11.1, 0.12.0 Sep 25, 2023
@jayschwa
Copy link
Contributor

This issue was originally assigned to the 0.11.1 milestone. Now that it's closed and only fixed in master, I changed the milestone to 0.12.0. FYI, in case the issue should still exist in 0.11.1 and be reopened.

@nektro
Copy link
Contributor

nektro commented Sep 25, 2023

the 0.11.1 milestone is andrew's checklist to cherry pick fixes, 0.12.0 is for if only going to be fixed in future versions

@andrewrk
Copy link
Member

Don't worry, the git commit log is my checklist

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
Projects
None yet
Development

No branches or pull requests

5 participants