| ... | @@ -8,6 +8,7 @@ const CompilationModule = @import("Module.zig"); | ... | @@ -8,6 +8,7 @@ const CompilationModule = @import("Module.zig"); |
| 8 | const File = CompilationModule.File; | 8 | const File = CompilationModule.File; |
| 9 | const Module = @import("Package.zig"); | 9 | const Module = @import("Package.zig"); |
| 10 | const Tokenizer = std.zig.Tokenizer; | 10 | const Tokenizer = std.zig.Tokenizer; |
| | 11 | const InternPool = @import("InternPool.zig"); |
| 11 | const Zir = @import("Zir.zig"); | 12 | const Zir = @import("Zir.zig"); |
| 12 | const Ref = Zir.Inst.Ref; | 13 | const Ref = Zir.Inst.Ref; |
| 13 | const log = std.log.scoped(.autodoc); | 14 | const log = std.log.scoped(.autodoc); |
| ... | @@ -106,18 +107,20 @@ pub fn generateZirData(self: *Autodoc) !void { | ... | @@ -106,18 +107,20 @@ pub fn generateZirData(self: *Autodoc) !void { |
| 106 | const file = self.comp_module.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table | 107 | const file = self.comp_module.import_table.get(abs_root_src_path).?; // file is expected to be present in the import table |
| 107 | // Append all the types in Zir.Inst.Ref. | 108 | // Append all the types in Zir.Inst.Ref. |
| 108 | { | 109 | { |
| 109 | try self.types.append(self.arena, .{ | 110 | comptime std.debug.assert(@enumToInt(InternPool.Index.first_type) == 0); |
| 110 | .ComptimeExpr = .{ .name = "ComptimeExpr" }, | 111 | var i: u32 = 0; |
| 111 | }); | 112 | while (i <= @enumToInt(InternPool.Index.last_type)) : (i += 1) { |
| 112 | | 113 | const ip_index = @intToEnum(InternPool.Index, i); |
| 113 | // this skips Ref.none but it's ok becuse we replaced it with ComptimeExpr | | |
| 114 | var i: u32 = 1; | | |
| 115 | while (i <= @enumToInt(Ref.anyerror_void_error_union_type)) : (i += 1) { | | |
| 116 | var tmpbuf = std.ArrayList(u8).init(self.arena); | 114 | var tmpbuf = std.ArrayList(u8).init(self.arena); |
| 117 | try Ref.typed_value_map[i].val.fmtDebug().format("", .{}, tmpbuf.writer()); | 115 | if (ip_index == .generic_poison_type) { |
| | 116 | // Not a real type, doesn't have a normal name |
| | 117 | try tmpbuf.writer().writeAll("(generic poison)"); |
| | 118 | } else { |
| | 119 | try ip_index.toType().fmt(self.comp_module).format("", .{}, tmpbuf.writer()); |
| | 120 | } |
| 118 | try self.types.append( | 121 | try self.types.append( |
| 119 | self.arena, | 122 | self.arena, |
| 120 | switch (@intToEnum(Ref, i)) { | 123 | switch (ip_index) { |
| 121 | else => blk: { | 124 | else => blk: { |
| 122 | // TODO: map the remaining refs to a correct type | 125 | // TODO: map the remaining refs to a correct type |
| 123 | // instead of just assinging "array" to them. | 126 | // instead of just assinging "array" to them. |
| ... | @@ -1038,7 +1041,7 @@ fn walkInstruction( | ... | @@ -1038,7 +1041,7 @@ fn walkInstruction( |
| 1038 | .ret_load => { | 1041 | .ret_load => { |
| 1039 | const un_node = data[inst_index].un_node; | 1042 | const un_node = data[inst_index].un_node; |
| 1040 | const res_ptr_ref = un_node.operand; | 1043 | const res_ptr_ref = un_node.operand; |
| 1041 | const res_ptr_inst = @enumToInt(res_ptr_ref) - Ref.typed_value_map.len; | 1044 | const res_ptr_inst = Zir.refToIndex(res_ptr_ref).?; |
| 1042 | // TODO: this instruction doesn't let us know trivially if there's | 1045 | // TODO: this instruction doesn't let us know trivially if there's |
| 1043 | // branching involved or not. For now here's the strat: | 1046 | // branching involved or not. For now here's the strat: |
| 1044 | // We search backwarts until `ret_ptr` for `store_node`, | 1047 | // We search backwarts until `ret_ptr` for `store_node`, |
| ... | @@ -2155,11 +2158,10 @@ fn walkInstruction( | ... | @@ -2155,11 +2158,10 @@ fn walkInstruction( |
| 2155 | const lhs_ref = blk: { | 2158 | const lhs_ref = blk: { |
| 2156 | var lhs_extra = extra; | 2159 | var lhs_extra = extra; |
| 2157 | while (true) { | 2160 | while (true) { |
| 2158 | if (@enumToInt(lhs_extra.data.lhs) < Ref.typed_value_map.len) { | 2161 | const lhs = Zir.refToIndex(lhs_extra.data.lhs) orelse { |
| 2159 | break :blk lhs_extra.data.lhs; | 2162 | break :blk lhs_extra.data.lhs; |
| 2160 | } | 2163 | }; |
| 2161 | | 2164 | |
| 2162 | const lhs = @enumToInt(lhs_extra.data.lhs) - Ref.typed_value_map.len; | | |
| 2163 | if (tags[lhs] != .field_val and | 2165 | if (tags[lhs] != .field_val and |
| 2164 | tags[lhs] != .field_ptr and | 2166 | tags[lhs] != .field_ptr and |
| 2165 | tags[lhs] != .field_type) break :blk lhs_extra.data.lhs; | 2167 | tags[lhs] != .field_type) break :blk lhs_extra.data.lhs; |
| ... | @@ -2186,8 +2188,7 @@ fn walkInstruction( | ... | @@ -2186,8 +2188,7 @@ fn walkInstruction( |
| 2186 | // TODO: double check that we really don't need type info here | 2188 | // TODO: double check that we really don't need type info here |
| 2187 | | 2189 | |
| 2188 | const wr = blk: { | 2190 | const wr = blk: { |
| 2189 | if (@enumToInt(lhs_ref) >= Ref.typed_value_map.len) { | 2191 | if (Zir.refToIndex(lhs_ref)) |lhs_inst| { |
| 2190 | const lhs_inst = @enumToInt(lhs_ref) - Ref.typed_value_map.len; | | |
| 2191 | if (tags[lhs_inst] == .call or tags[lhs_inst] == .field_call) { | 2192 | if (tags[lhs_inst] == .call or tags[lhs_inst] == .field_call) { |
| 2192 | break :blk DocData.WalkResult{ | 2193 | break :blk DocData.WalkResult{ |
| 2193 | .expr = .{ | 2194 | .expr = .{ |
| ... | @@ -4670,16 +4671,19 @@ fn walkRef( | ... | @@ -4670,16 +4671,19 @@ fn walkRef( |
| 4670 | ref: Ref, | 4671 | ref: Ref, |
| 4671 | need_type: bool, // true when the caller needs also a typeRef for the return value | 4672 | need_type: bool, // true when the caller needs also a typeRef for the return value |
| 4672 | ) AutodocErrors!DocData.WalkResult { | 4673 | ) AutodocErrors!DocData.WalkResult { |
| 4673 | const enum_value = @enumToInt(ref); | 4674 | if (ref == .none) { |
| 4674 | if (enum_value <= @enumToInt(Ref.anyerror_void_error_union_type)) { | 4675 | return .{ .expr = .{ .comptimeExpr = 0 } }; |
| | 4676 | } else if (@enumToInt(ref) <= @enumToInt(InternPool.Index.last_type)) { |
| 4675 | // We can just return a type that indexes into `types` with the | 4677 | // We can just return a type that indexes into `types` with the |
| 4676 | // enum value because in the beginning we pre-filled `types` with | 4678 | // enum value because in the beginning we pre-filled `types` with |
| 4677 | // the types that are listed in `Ref`. | 4679 | // the types that are listed in `Ref`. |
| 4678 | return DocData.WalkResult{ | 4680 | return DocData.WalkResult{ |
| 4679 | .typeRef = .{ .type = @enumToInt(std.builtin.TypeId.Type) }, | 4681 | .typeRef = .{ .type = @enumToInt(std.builtin.TypeId.Type) }, |
| 4680 | .expr = .{ .type = enum_value }, | 4682 | .expr = .{ .type = @enumToInt(ref) }, |
| 4681 | }; | 4683 | }; |
| 4682 | } else if (enum_value < Ref.typed_value_map.len) { | 4684 | } else if (Zir.refToIndex(ref)) |zir_index| { |
| | 4685 | return self.walkInstruction(file, parent_scope, parent_src, zir_index, need_type); |
| | 4686 | } else { |
| 4683 | switch (ref) { | 4687 | switch (ref) { |
| 4684 | else => { | 4688 | else => { |
| 4685 | panicWithContext( | 4689 | panicWithContext( |
| ... | @@ -4772,9 +4776,6 @@ fn walkRef( | ... | @@ -4772,9 +4776,6 @@ fn walkRef( |
| 4772 | // } }; | 4776 | // } }; |
| 4773 | // }, | 4777 | // }, |
| 4774 | } | 4778 | } |
| 4775 | } else { | | |
| 4776 | const zir_index = enum_value - Ref.typed_value_map.len; | | |
| 4777 | return self.walkInstruction(file, parent_scope, parent_src, zir_index, need_type); | | |
| 4778 | } | 4779 | } |
| 4779 | } | 4780 | } |
| 4780 | | 4781 | |