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

Assertion `!type_is_invalid` crashing compiler #1058

isaachier opened this Issue Jun 5, 2018 · 0 comments


None yet
2 participants

isaachier commented Jun 5, 2018

I'm trying to write an LR parser generator in Zig. Here is the minimal code so far:

const std = @import("std");
const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;
const ArrayList = std.ArrayList;
const HashMap = std.HashMap;
const Buffer = std.Buffer;
const File = std.os.File;

const Rule = struct {
    name: Buffer,
    symbols: ArrayList(Buffer),

    pub fn init(allocator: *Allocator, name: []const u8, symbols: [][]const u8) !Rule {
        var self = Rule{
            .name = try Buffer.init(allocator, name),
            .symbols = ArrayList(Buffer).init(allocator),
        for (symbols) |symbol| {
            const symbol_copy = try Buffer.init(allocator, symbol);
            try self.symbols.append(symbol_copy);
        return self;

fn hash_rule(rule: *const Rule) u32 {
    return mem.hash_slice_u8(;

fn eql_rule(lhs: *const Rule, rhs: *const Rule) bool {
    return mem.eql_slice_u8(,;

const RuleSet = struct {
    arena: ArenaAllocator,
    map: HashMap([]const u8, Rule, hash_rule, eql_rule),

    pub fn init(allocator: *Allocator) RuleSet {
        var arena = ArenaAllocator.init(allocator);
        return RuleSet{
            .arena = arena,
            .map = HashMap([]const u8, Rule, hash_rule, eql_rule).init(arena),

    pub fn deinit(self: *RuleSet) void {

test "init" {
    var rule_set = try RuleSet.init(std.debug.global_allocator);
    defer rule_set.deinit();

I am trying to test this, but get the following error from the compiler.

zig: /home/ihier/proj/zig/zig/src/analyze.cpp:386: TypeTableEntry* get_pointer_to_type_extra(CodeGen*, TypeTableEntry*, bool, bool, PtrLen, uint32_t, uint32_t, uint32_t): Assertion `!type_is_invalid(child_type)' failed.

Running gdb got me this stack trace:

#0  type_is_invalid (type_entry=0x55555787d8e0) at /home/ihier/proj/zig/zig/src/analyze.cpp:1660
#1  0x0000555555d737b0 in get_pointer_to_type_extra (g=0x5555576c58d0, child_type=0x55555787d8e0, 
    is_const=false, is_volatile=false, ptr_len=PtrLenSingle, byte_alignment=8, bit_offset=0, 
    unaligned_bit_count=0) at /home/ihier/proj/zig/zig/src/analyze.cpp:386
#2  0x0000555555d73e6a in get_pointer_to_type (g=0x5555576c58d0, child_type=0x55555787d8e0, 
    is_const=false) at /home/ihier/proj/zig/zig/src/analyze.cpp:476
#3  0x0000555555d7664b in get_fn_type (g=0x5555576c58d0, fn_type_id=0x7fffffffd2d0)
    at /home/ihier/proj/zig/zig/src/analyze.cpp:1087
#4  0x0000555555d7818e in analyze_fn_type (g=0x5555576c58d0, proto_node=0x555557737750, 
    child_scope=0x55555787eaa0, fn_entry=0x55555787e780)
    at /home/ihier/proj/zig/zig/src/analyze.cpp:1652
#5  0x0000555555d7d50c in resolve_decl_fn (g=0x5555576c58d0, tld_fn=0x55555787dc00)
    at /home/ihier/proj/zig/zig/src/analyze.cpp:3061
#6  0x0000555555d7ec41 in resolve_top_level_decl (g=0x5555576c58d0, tld=0x55555787dc00, 
    pointer_only=false, source_node=0x55555773a220) at /home/ihier/proj/zig/zig/src/analyze.cpp:3555
#7  0x0000555555de90b3 in ir_analyze_decl_ref (ira=0x55555787d5b0, source_instruction=0x55555787b940, 
    tld=0x55555787dc00) at /home/ihier/proj/zig/zig/src/ir.cpp:13617
#8  0x0000555555de9c8c in ir_analyze_instruction_field_ptr (ira=0x55555787d5b0, 
    field_ptr_instruction=0x55555787b940) at /home/ihier/proj/zig/zig/src/ir.cpp:13793
#9  0x0000555555dfe939 in ir_analyze_instruction_nocast (ira=0x55555787d5b0, instruction=0x55555787b940)
    at /home/ihier/proj/zig/zig/src/ir.cpp:19539
#10 0x0000555555dff398 in ir_analyze_instruction (ira=0x55555787d5b0, instruction=0x55555787b940)
    at /home/ihier/proj/zig/zig/src/ir.cpp:19761
#11 0x0000555555dff68c in ir_analyze (codegen=0x5555576c58d0, old_exec=0x555557755640, 
    new_exec=0x555557755728, expected_type=0x555557755910, expected_type_source_node=0x0)
    at /home/ihier/proj/zig/zig/src/ir.cpp:19815
#12 0x0000555555d7faa4 in analyze_fn_ir (g=0x5555576c58d0, fn_table_entry=0x5555577555d0, 
    return_type_node=0x0) at /home/ihier/proj/zig/zig/src/analyze.cpp:3924
#13 0x0000555555d7ff30 in analyze_fn_body (g=0x5555576c58d0, fn_table_entry=0x5555577555d0)
    at /home/ihier/proj/zig/zig/src/analyze.cpp:4011
#14 0x0000555555d80b18 in semantic_analyze (g=0x5555576c58d0)
    at /home/ihier/proj/zig/zig/src/analyze.cpp:4216
#15 0x0000555555db2b4b in gen_root_source (g=0x5555576c58d0)
    at /home/ihier/proj/zig/zig/src/codegen.cpp:6980
#16 0x0000555555db476e in codegen_build (g=0x5555576c58d0)
    at /home/ihier/proj/zig/zig/src/codegen.cpp:7493
#17 0x0000555555e193dd in main (argc=3, argv=0x7fffffffde88)
    at /home/ihier/proj/zig/zig/src/main.cpp:927

@andrewrk andrewrk added this to the 0.3.0 milestone Jun 5, 2018

@andrewrk andrewrk added the bug label Jun 5, 2018

@andrewrk andrewrk closed this in 7a09482 Jun 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment