Skip to content

Spurious "dependency loop detected" and "missing struct field" errors #17255

Open
@dweiller

Description

@dweiller

Zig Version

0.12.0-dev.494+a8d2ed806

Steps to Reproduce and Observed Behavior

Clone https://github.com/dweiller/zimalloc and run

git checkout d577c4a3
zig build

I will try to make a smaller repro case and bisect the Zig commit introducing it when I get time (and llvm17 finishes compiling). A minimal repro case is below in #17255 (comment).

Here is the full error message:

Build Summary: 1/4 steps succeeded; 1 failed (disable with --summary none)
test transitive failure
└─ run test transitive failure
   └─ zig test Debug native 3 errors
src/Segment.zig:9:5: error: dependency loop detected
pub const Ptr = *align(segment_alignment) @This();
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/zimalloc.zig:50:32: error: missing struct field: thread_heaps
    var gpa = Allocator(config){};
              ~~~~~~~~~~~~~~~~~^~
src/zimalloc.zig:50:32: note: missing struct field: thread_heaps_lock
src/allocator.zig:8:12: note: struct 'allocator.Allocator(.{.thread_data_prealloc = 128, .thread_safe = true, .safety_checks = false})' declared here
    return struct {
           ^~~~~~
src/allocator.zig:10:79: error: missing struct field: prealloc_segment
        thread_heaps: std.SegmentedList(Heap, config.thread_data_prealloc) = .{},
                                                                             ~^~
src/allocator.zig:10:79: note: missing struct field: dynamic_segments
src/allocator.zig:10:79: note: missing struct field: len
/path/to/zig/zig-linux-x86_64-0.12.0-dev.494+a8d2ed806/lib/std/segmented_list.zig:79:12: note: struct 'segmented_list.SegmentedList(Heap,128)' declared here
    return struct {
           ^~~~~~

These errors are not encountered when compiling with 0.12.0-dev.464+a63a1c5cb (the commit that merged llvm17, though I can't find the tarball for this to test locally now, but my CI worked using it), so it seems the issue was introduced between that commit and when #17172 got merged.

The dependency loop issue shouldn't be the same issue as other dependency issue in the issue tracker (e.g. #16932, #16419, #14353) which are all about function pointers and affect earlier compiler versions than 0.12.0-dev.464+a63a1c5cb.

Expected Behavior

The code should compile as far as I can tell - the dependency loop is (according to the compile error) caused by a decl that is creates a type alias like pub const Ptr = *align(alignment) @This(); and the missing struct fields all have default values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.regressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions