#Cannot compile fuzz test in zig 0.16

1 messages · Page 1 of 1 (latest)

gentle crow
#

I receive the following internal compile error:

❯ zig build test --fuzz
info(web_server): web interface listening at http://[::1]:38197/
info(web_server): hint: pass '--webui=[::1]:38197' to use the same port next time
Build Summary: 3/3 steps succeeded; 1/1 tests passed
test
└─ run test
   └─ compile test Debug native 1 errors
/usr/lib/zig/compiler/test_runner.zig:566:55: error: expected type '*const debug.StackTrace', found '*builtin.StackTrace'
                            std.debug.writeStackTrace(trace, stderr) catch break :p;
                                                      ^~~~~
/usr/lib/zig/compiler/test_runner.zig:566:55: note: pointer type child 'builtin.StackTrace' cannot cast into pointer type child 'debug.StackTrace'
/usr/lib/zig/std/builtin.zig:11:24: note: struct declared here
pub const StackTrace = struct {
                       ^~~~~~
/usr/lib/zig/std/debug.zig:604:24: note: struct declared here
pub const StackTrace = struct {
                       ^~~~~~
/usr/lib/zig/std/debug.zig:824:28: note: parameter type declared here
pub fn writeStackTrace(st: *const StackTrace, t: Io.Terminal) Writer.Error!void {
                           ^~~~~~~~~~~~~~~~~
referenced by:
    fuzz__anon_48913: /usr/lib/zig/compiler/test_runner.zig:589:41
    fuzz [inlined]: /usr/lib/zig/std/testing.zig:1232:32
    test.fuzz parser: src/parser.zig:867:25
error: 1 compilation errors
failed command: /usr/bin/zig test -ffuzz -ODebug -Mroot=/home/max/Documents/programming/github/ironmatch/src/parser.zig --cache-dir .zig-cache --global-cache-dir /home/max/.cache/zig --name test --zig-lib-dir /usr/lib/zig/ --listen=-

error: one or more unit tests failed to be rebuilt in fuzz mode
error: the following build command failed with exit code 1:
.zig-cache/o/bbf98b5211b68f8544003036256c057a/build /usr/bin/zig /usr/lib/zig /home/max/Documents/programming/github/ironmatch .zig-cache /home/max/.cache/zig --seed 0x7a2a62a7 -Z015a4ad1ae65fe37 test --fuzz

For details see below

#

I tried it both with and without the llvm middle-end.

Here is the relevant part of my build.zig


    const test_step = b.step("test", "Run tests");

    const unit_tests = b.addTest(.{
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/parser.zig"),
            .target = target,
            .optimize = .Debug,
        }),
        .use_llvm = true,
    });

    const run_tests = b.addRunArtifact(unit_tests);
    test_step.dependOn(&run_tests.step);

here is the fuzz test:


test "fuzz parser" {
    try std.testing.fuzz({}, struct {
        fn testOne(_: void, smith: *std.testing.Smith) anyerror!void {
            var input: [4096]u8 = undefined;
            smith.bytes(&input);

            var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
            defer arena.deinit();
            const allocator = arena.allocator();

            var ast_u = im_parse(&input, IM_INPUT_UNICODE, allocator) catch return;
            defer ast_u.deinit(allocator);

            var ast = im_parse(&input, root.IM_INPUT_DEFAULT, allocator) catch return;
            defer ast.deinit(allocator);
        }
    }.testOne, .{ .corpus = parse_property.PARSER_FUZZ_CORPUS });
}

Normal compilation without the fuzz test works just fine. Please let me know if this is an issue on my end or if this is a known issue. If it's an unknown issue let me know as well so I can file an issue.

serene herald
#

fwiw i could never figure it out eithet

hardy vortex
gentle crow
#

But in release mode I have no bounds checks

#

Does it work with ReleaseSafe?

hardy vortex
#

yes

serene herald
#

you'd want release if you're fuzzing regardless bc speed

gentle crow
#

but with ReleaseSafe it takes forever to build (at least 30 minutes) and I don't think my project is that big right now (there is one generated file, but it's basically just one massive if else chain)

 103907 ./parse_property.zig
     65 ./root.zig
     36 ./nfa.zig
    123 ./dump/parser.zig
    141 ./cli.zig
     25 ./main.zig
    883 ./parser.zig
 105180 total

can I someone optimize less while still getting the same result (because 30+ minutes build times is insane)

#

if it finished compiling at some point sure, but zig must have set some crazy optimisation level (I expect compile times like that only for way bigger projects)

#

maybe it's trying to construct a massive dfa to match all input strings quickly, but at some point the optimizer should just give up and recognize that the problem is too big? Here is what the generated code looks like

pub fn parse_property(property: []const u8, ast: *IMAst, allocator: std.mem.Allocator) !void {
    if (std.mem.eql(u8, property, "Cn") or
        std.mem.eql(u8, property, "Unassigned") or
        std.mem.eql(u8, property, "gc=Cn") or
        std.mem.eql(u8, property, "gc=Unassigned") or
        std.mem.eql(u8, property, "General_Category=Cn") or
        std.mem.eql(u8, property, "General_Category=Unassigned")) {
        const range_start = ast.ranges.items.len;
        try ast.ranges.ensureUnusedCapacity(allocator, 735);
        try ast.ranges.append(allocator, .{ .lo = 0x000378, .hi = 0x000379 });
// ...
        try ast.nodes.append(allocator, .{ .kind = .range, .val = .{ .range = .{ .idx = range_start, .len = 735 } } });
    } else if (std.mem.eql(u8, property, "Lu") or
        std.mem.eql(u8, property, "Uppercase_Letter") or
        std.mem.eql(u8, property, "gc=Lu") or
        std.mem.eql(u8, property, "gc=Uppercase_Letter") or
        std.mem.eql(u8, property, "General_Category=Lu") or
        std.mem.eql(u8, property, "General_Category=Uppercase_Letter")) {
        const range_start = ast.ranges.items.len;
        try ast.ranges.ensureUnusedCapacity(allocator, 655);
        try ast.ranges.append(allocator, .{ .lo = 0x000041, .hi = 0x00005A });
// ...
hardy vortex
serene herald
gentle crow
#

sounds like an upstream llvm issue. (LLVM emit object is llvm running right?). Is there a way to emit llvm as well as the intermediate representations for each optimization pass? (like gcc -fdump-all)

worldly skiff
#
--verbose-llvm-ir[=file]     Enable compiler debug output for LLVM IR
--verbose-llvm-bc=[file]     Enable compiler debug output for LLVM BC
gentle crow
#

and for the intermediate steps? Ideally I would like a file for each pass

#

well at least now it completed. Still took way too long