Skip to content

Unexpected behavior changes between optimization modes in child process output collection #21838

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
brianferri opened this issue Oct 28, 2024 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@brianferri
Copy link

Zig Version

0.13.0 (MacOS 15.0.1)

Steps to Reproduce and Observed Behavior

  • git clone https://github.com/brianferri/Zig-Child.run
  • cd into the cloned repo
  • zig build -Doptimize=Debug run -- ls -a -> Exits normally
 brianferri in …/Zig-Child.run on  main at  10:46 ❯ zig build -Doptimize=Debug run -- ls -a       
info: Child process exited with out: .
..
.git
.gitignore
.vscode
.zig-cache
build.zig
build.zig.zon
src
zig-out
  • zig build -Doptimize=ReleaseSafe run -- ls -a -> thread xxx panic: reached unreachable code
 brianferri in …/Zig-Child.run on  main at  10:46 ❯ zig build -Doptimize=ReleaseSafe run -- ls -a 
thread 273404 panic: reached unreachable code
run
└─ run Zig-Child.run failure
error: the following command terminated unexpectedly:
/Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/zig-out/bin/Zig-Child.run ls -a 
Build Summary: 3/5 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run Zig-Child.run failure
error: the following build command failed with exit code 1:
/Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/.zig-cache/o/2150b426a8144f5f03b6246bfff63461/build /opt/homebrew/Cellar/zig/0.13.0/bin/zig /Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run /Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/.zig-cache /Users/brianferri/.cache/zig --seed 0x4b0119d4 -Z74439805628802fe -Doptimize=ReleaseSafe run -- ls -a
  • zig build -Doptimize=ReleaseSmall run -- ls -a -> Fails without apparent error
 brianferri in …/Zig-Child.run on  main at  10:47 ❯ zig build -Doptimize=ReleaseSmall run -- ls -a
run
└─ run Zig-Child.run failure
error: the following command terminated unexpectedly:
/Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/zig-out/bin/Zig-Child.run ls -a 
Build Summary: 3/5 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run Zig-Child.run failure
error: the following build command failed with exit code 1:
/Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/.zig-cache/o/2150b426a8144f5f03b6246bfff63461/build /opt/homebrew/Cellar/zig/0.13.0/bin/zig /Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run /Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/.zig-cache /Users/brianferri/.cache/zig --seed 0xdd3b791b -Z16cf26e22baa7c74 -Doptimize=ReleaseSmall run -- ls -a
  • zig build -Doptimize=ReleaseFast run -- ls -a -> Fails without apparent error
 brianferri in …/Zig-Child.run on  main at  10:47 ❯ zig build -Doptimize=ReleaseFast run -- ls -a 
run
└─ run Zig-Child.run failure
error: the following command terminated unexpectedly:
/Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/zig-out/bin/Zig-Child.run ls -a 
Build Summary: 3/5 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run Zig-Child.run failure
error: the following build command failed with exit code 1:
/Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/.zig-cache/o/2150b426a8144f5f03b6246bfff63461/build /opt/homebrew/Cellar/zig/0.13.0/bin/zig /Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run /Users/brianferri/Desktop/Main/Scripts/_Misc/Repros/Zig-Child.run/.zig-cache /Users/brianferri/.cache/zig --seed 0xa67cf8dc -Z9235edd05b12e303 -Doptimize=ReleaseFast run -- ls -a

Expected Behavior

I'd expect the Releases to work the same as Debug code

@brianferri brianferri added the bug Observed behavior contradicts documented or intended behavior label Oct 28, 2024
@brianferri
Copy link
Author

I've debugged some of it and noticed that the issue presents itself in:

// .../zig/0.13.0/lib/zig/std/process/Child.zig
396 |    try child.spawn();
397 |    try child.collectOutput(&stdout, &stderr, args.max_output_bytes); // <- here
398 |

line 397;
Specifically inside the collectOutput function:

pub fn collectOutput(
    child: ChildProcess,
    stdout: *std.ArrayList(u8),
    stderr: *std.ArrayList(u8),
    max_output_bytes: usize,
) !void {
    assert(child.stdout_behavior == .Pipe); // <- here

On the assert

@rohlem
Copy link
Contributor

rohlem commented Oct 28, 2024

Probably duplicate, definitely related to #21756 (to-be-fixed by #21760)

@squeek502
Copy link
Collaborator

Yep, duplicate of #21756 / #17704

@squeek502 squeek502 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 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
Projects
None yet
Development

No branches or pull requests

3 participants