Skip to content
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

incorrect "error: dependency loop detected" #16419

Open
buzmeg opened this issue Jul 15, 2023 · 2 comments
Open

incorrect "error: dependency loop detected" #16419

buzmeg opened this issue Jul 15, 2023 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@buzmeg
Copy link

buzmeg commented Jul 15, 2023

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.

@buzmeg buzmeg added the bug Observed behavior contradicts documented or intended behavior label Jul 15, 2023
@jsign
Copy link

jsign commented Jul 18, 2023

Looks like the same report as done in #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.

@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Jul 22, 2023
@andrewrk andrewrk added this to the 0.12.0 milestone Jul 22, 2023
sphaerophoria added a commit to sphaerophoria/video-editor that referenced this issue May 13, 2024
Implement audio playback, hopefully motivation is self explanatory

The audio landscape is vast in linux, we have alsa, pulse, jack,
pipewire and alsa, pulse, jack interfaces into pipewire, alsa interfaces
into pulse, etc. Instead of trying to deal with this ourselves, pull in
an audio lib to deal with it for us

Just skimming online, miniaudio fits well. PortAudio and libsoundio also
seem to both be good candidates. No strong reasoning went into this
choice, the single header impl of miniaudio felt easy to work with.

We were tricked though, with the default miniaudio impl we hit a zig
compiler bug that triggers circular dependencies. Something about
using a struct pointer in a function pointer stored by the struct, see
ziglang/zig#18247 (comment)

Patch miniaudio to just use void pointers instead, this doesn't seem to
have any negative effects

Add an audio player abstraction that just injects a sin wave for now,
add test binary to try it

Potentially related issues...
ziglang/zig#12325
ziglang/zig#16419
sphaerophoria added a commit to sphaerophoria/video-editor that referenced this issue May 13, 2024
Implement audio playback, hopefully motivation is self explanatory

The audio landscape is vast in linux, we have alsa, pulse, jack,
pipewire and alsa, pulse, jack interfaces into pipewire, alsa interfaces
into pulse, etc. Instead of trying to deal with this ourselves, pull in
an audio lib to deal with it for us

Just skimming online, miniaudio fits well. PortAudio and libsoundio also
seem to both be good candidates. No strong reasoning went into this
choice, the single header impl of miniaudio felt easy to work with.

We were tricked though, with the default miniaudio impl we hit a zig
compiler bug that triggers circular dependencies. Something about
using a struct pointer in a function pointer stored by the struct, see
ziglang/zig#18247 (comment)

Patch miniaudio to just use void pointers instead, this doesn't seem to
have any negative effects

Add an audio player abstraction that just injects a sin wave for now,
add test binary to try it

Potentially related issues...
ziglang/zig#12325
ziglang/zig#16419
ziglang/zig#19392
sphaerophoria added a commit to sphaerophoria/video-editor that referenced this issue May 14, 2024
Implement audio playback, hopefully motivation is self explanatory

The audio landscape is vast in linux, we have alsa, pulse, jack,
pipewire and alsa, pulse, jack interfaces into pipewire, alsa interfaces
into pulse, etc. Instead of trying to deal with this ourselves, pull in
an audio lib to deal with it for us

Just skimming online, miniaudio fits well. PortAudio and libsoundio also
seem to both be good candidates. No strong reasoning went into this
choice, the single header impl of miniaudio felt easy to work with.

We were tricked though, with the default miniaudio impl we hit a zig
compiler bug that triggers circular dependencies. Something about
using a struct pointer in a function pointer stored by the struct, see
ziglang/zig#18247 (comment)

Patch miniaudio to just use void pointers instead, this doesn't seem to
have any negative effects

Extract audio frames from ffmepg, and feed them into our audio
subsystem. Not a ton to say here, everything is just using the APIs
provided by miniaudio and ffmpeg

Replace test video with a 20s segment of big buck bunny

Potentially related issues...
ziglang/zig#12325
ziglang/zig#16419
ziglang/zig#19392
@pwbh
Copy link

pwbh commented Aug 3, 2024

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);
}

@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Feb 10, 2025
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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

4 participants