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

compiler crash when using std.meta.eql on TypeInfo for containers and pointers #7789

Open
emekoi opened this issue Jan 16, 2021 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@emekoi
Copy link
Contributor

emekoi commented Jan 16, 2021

minimal reproduction.

const std = @import("std");

test "basic add functionality" {
    // fails
    std.testing.expect(comptime std.meta.eql(@typeInfo(opaque{}), @typeInfo(opaque {})));
}

test of other types

test "basic add functionality" {
    const E = struct {
        fn ex_fn_sync(a: i32, b: i32) i32 {
            return a + b;
        }

        fn ex_fn_async(a: i32, b: i32) i32 {
            suspend {
                resume @frame();
            }
            return a + b;
        }
    };

    const T = .{
        .{ "Type", @TypeOf(i32) },
        .{ "Void", void },
        .{ "Bool", bool },
        .{ "NoReturn", noreturn },
        .{ "Undefined", @TypeOf(undefined) },
        .{ "Null", @TypeOf(null) },
        .{ "EnumLiteral", @TypeOf(.literal) },
        .{ "Frame", @Frame(E.ex_fn_sync) },
        .{ "Frame", @Frame(E.ex_fn_async) },
        .{ "AnyFrame", anyframe },
        .{ "ErrorSet", error{} },
        .{ "ErrorSet", error{Single} },
        .{ "ErrorUnion", error{Union}!void },
        .{ "ErrorUnion", error{Union}!i32 },
        .{ "ComptimeInt", @TypeOf(1) },
        .{ "ComptimeFloat", @TypeOf(1.0) },
        .{ "Int", i32 },
        .{ "Float", f32 },
        .{ "Optional", ?i32 },
        .{ "Array", [3]i32 },
        .{ "Fn", fn (i32) i32 },
        .{ "Vector", std.meta.Vector(4, u8) },
        
        // none of the below ttype work i don't know how to test BoundFn's
        // perhaps containters don't because they allow declarations?
        // .{"Pointer", *i32},
        // .{"Struct", struct {}},
        // .{"Opaque", opaque {}},
        // .{"Union", union {Void: void}},
        // .{"Enum", enum {Field}},
        // .{"Enum", union(enum) {Void: void}},
    };

    inline for (T) |t| {
        // uncommenting this line reveals that zig will stop logging
        // strings in inline for loops and print their bytes instead
        // but revert to normal behavior outside the loop
        // @compileLog(t[0], @typeInfo(t[1]));
        testing.expect(comptime std.meta.eql(@typeInfo(t[1]), @typeInfo(t[1])));
    }
}

zig commit: b204ea0

stack trace ``` Assertion failed at ../src/stage1/analyze.cpp:7168 in const_values_equal. This is a bug in the Zig compiler.thread 4005931 panic: /home/emekankurumeh/dev/zig/src/stage1.zig:170:5: 0x55f3cbb5cfec in stage2_panic (zig1) @Panic(ptr[0..len]); ^ ../src/stage1/util.cpp:20:17: 0x55f3cc7b5dad in zig_panic (../src/stage1/util.cpp) ../src/stage1/util_base.hpp:53:18: 0x55f3cc69ebc5 in zig_assert (../src/stage1/analyze.cpp) ../src/stage1/analyze.cpp:7168:5: 0x55f3cc6b6186 in const_values_equal (../src/stage1/analyze.cpp) ../src/stage1/analyze.cpp:7230:40: 0x55f3cc6b6643 in const_values_equal (../src/stage1/analyze.cpp) ../src/stage1/analyze.cpp:7183:42: 0x55f3cc6b62fe in const_values_equal (../src/stage1/analyze.cpp) ../src/stage1/analyze.cpp:5928:40: 0x55f3cc6b2125 in fn_eval_eql (../src/stage1/analyze.cpp) ../src/stage1/hash_map.hpp:352:47: 0x55f3cc774caf in internal_get2 (../src/stage1/ir.cpp) ../src/stage1/hash_map.hpp:334:41: 0x55f3cc76a8ae in internal_get (../src/stage1/ir.cpp) ../src/stage1/hash_map.hpp:121:28: 0x55f3cc767b14 in maybe_get (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:20810:72: 0x55f3cc722fe8 in ir_analyze_fn_call (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:21258:43: 0x55f3cc724f79 in ir_analyze_fn_call_src (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:21505:42: 0x55f3cc725f13 in ir_analyze_instruction_call (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:32252:47: 0x55f3cc750f9d in ir_analyze_instruction_base (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:32575:65: 0x55f3cc751fca in ir_analyze (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:13701:38: 0x55f3cc707d1b in ir_eval_const_value (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:20821:43: 0x55f3cc7230c5 in ir_analyze_fn_call (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:21258:43: 0x55f3cc724f79 in ir_analyze_fn_call_src (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:21505:42: 0x55f3cc725f13 in ir_analyze_instruction_call (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:32252:47: 0x55f3cc750f9d in ir_analyze_instruction_base (../src/stage1/ir.cpp) ../src/stage1/ir.cpp:32575:65: 0x55f3cc751fca in ir_analyze (../src/stage1/ir.cpp) ../src/stage1/analyze.cpp:5060:44: 0x55f3cc6af6e2 in analyze_fn_ir (../src/stage1/analyze.cpp) ../src/stage1/analyze.cpp:5176:18: 0x55f3cc6afcaf in analyze_fn_body (../src/stage1/analyze.cpp) ../src/stage1/analyze.cpp:5288:28: 0x55f3cc6b0554 in semantic_analyze (../src/stage1/analyze.cpp) ../src/stage1/codegen.cpp:9457:25: 0x55f3cc68fdab in gen_root_source (../src/stage1/codegen.cpp) ../src/stage1/codegen.cpp:9506:20: 0x55f3cc69014c in codegen_build_object (../src/stage1/codegen.cpp) ../src/stage1/stage1.cpp:129:25: 0x55f3cc66180e in zig_stage1_build_object (../src/stage1/stage1.cpp) /home/emekankurumeh/dev/zig/src/stage1.zig:142:32: 0x55f3cbecb344 in Module.build_object (zig1) zig_stage1_build_object(mod); ^ /home/emekankurumeh/dev/zig/src/Compilation.zig:3232:31: 0x55f3cbced2a6 in Compilation.updateStage1Module (zig1) stage1_module.build_object(); ^ /home/emekankurumeh/dev/zig/src/Compilation.zig:1688:36: 0x55f3cbca60fb in Compilation.performAllTheWork (zig1) self.updateStage1Module(main_progress_node) catch |err| { ^ /home/emekankurumeh/dev/zig/src/Compilation.zig:1301:31: 0x55f3cbc9f47d in Compilation.update (zig1) try self.performAllTheWork(); ^ /home/emekankurumeh/dev/zig/src/main.zig:2007:20: 0x55f3cbc37676 in main.updateModule (zig1) try comp.update(); ^ /home/emekankurumeh/dev/zig/src/main.zig:1848:17: 0x55f3cbb84d7d in main.buildOutputType (zig1) updateModule(gpa, comp, zir_out_path, hook) catch |err| switch (err) { ^ /home/emekankurumeh/dev/zig/src/main.zig:168:31: 0x55f3cbb5bcc6 in main.mainArgs (zig1) return buildOutputType(gpa, arena, args, .zig_test); ^ /home/emekankurumeh/dev/zig/src/stage1.zig:45:24: 0x55f3cbb5b4de in main (zig1) stage2.mainArgs(gpa, arena, args) catch unreachable; ^ The following command terminated unexpectedly: /home/emekankurumeh/dev/zig/build/bin/zig test /home/emekankurumeh/dev/xzb/src/main.zig --cache-dir /home/emekankurumeh/dev/xzb/zig-cache --global-cache-dir /home/emekankurumeh/.cache/zig --name test error: the following build command failed with exit code 1: /home/emekankurumeh/dev/xzb/zig-cache/o/22c50f17c33a54a18fceb94ffeee4669/build /home/emekankurumeh/dev/zig/build/bin/zig /home/emekankurumeh/dev/xzb /home/emekankurumeh/dev/xzb/zig-cache /home/emekankurumeh/.cache/zig test ```
@emekoi emekoi changed the title compiler crash when using std.meta.eql on TypeInfo for some types compiler crash when using std.meta.eql on TypeInfo for containers and pointers Jan 16, 2021
@Vexu Vexu added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Jan 26, 2021
@Vexu Vexu added this to the 0.9.0 milestone Jan 26, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
3 participants