incorrect "error: dependency loop detected"
Zig Version
0.11.0-dev.3952+82a9d5d78
Steps to Reproduce and Observed Behavior
The following code refuses to compile on 0.11.0-dev.3952+82a9d5d78 but compiles just fine on Godbolt on 0.10.0. So, the dependency loop error if presumably false.
src/main.zig:16:1: error: dependency loop detected
const ContinuationStackType = std.BoundedArray(SmolkContinuationNative, MAX_CONTINUATION_STACK_SIZE);
const std = @import("std");
const KO_Ref = u16;
const KO_State = u16;
const KOErr = error {
GENERIC,
};
const MAX_CONTINUATION_STACK_SIZE = 8;
const ContinuationStackType = std.BoundedArray(SmolkContinuationNative, MAX_CONTINUATION_STACK_SIZE);
var kont_continuation_stack: ContinuationStackType = .{};
const SmolkPointerContinuationFunction = *const fn (pkos: *KO_State, kont_stack: *ContinuationStackType, args: SmolkContinuationNative) KOErr!SmolkContinuationNative;
const SMOLK_CONTINUATION_INITIAL_CALL_STATE = 1;
const SmolkContinuationNative = struct {
pcfn: SmolkPointerContinuationFunction,
kor_result: KO_Ref,
};
pub fn kont_fail(pkos: *KO_State, kont_stack: *ContinuationStackType, args: SmolkContinuationNative) KOErr!SmolkContinuationNative
{
_ = pkos;
_ = kont_stack;
_ = args;
std.debug.print("FAIL!\n", .{});
return KOErr.GENERIC;
}
pub fn main() !void {
try kont_continuation_stack.append(.{
.pcfn = kont_fail,
.kor_result = 0,
});
std.debug.print("Stack: {any}\n", .{kont_continuation_stack});
}
Expected Behavior
Expected to compile.
Looks like the same report as done in https://github.com/ziglang/zig/issues/14353.
In your case, SmolkContinuationNative depends on SmolkPointerContinouationFunction, a function pointer with SmolkContinuationNative in its args.
Yesterday, I had the same dependency loop compilation problem for some C-imported header file which was doing a similar thing from a translated .h file.
Same happens for libuv, dependency loop detected for *c.uv_stream_t
const ConnectionCb = *const fn (server: *c.uv_stream_t, status: i32) void;
pub fn init(loop: Loop) Tcp {
var handle: c.uv_tcp_t = undefined;
c.uv_tcp_init(loop.loop, &handle);
return .{ .handle = handle, .addr = .{} };
}
pub fn listen(self: Tcp, addr: []const u8, port: i32, backlog: usize, cb: ConnectionCb) !void {
c.uv_ip4_addr(addr, port, &self.addr);
c.uv_tcp_bind(&self.handle, @bitCast(addr), 0);
const result = c.uv_listen(@alignCast(self.handle), backlog, cb);
try errors.translate(result);
}
This instance is, I think, working correctly, and was simply a design flaw in BoundedArray where it used @alignOf on the child type, rather than doing what ArrayList does and having a specific representation for "default alignment". Additionally, BoundedArray has now been removed from the standard library, so this no longer reproduces.