| author | |
| committer | |
| log | f75d4cbe56f9f8212581f00700600a57ce545ba1 |
| tree | 9061ca185cd38119116333c4fee9f5d26a0619dc |
| parent | 7ed499ec4549fa7304b822446b23cff993b8fa6f |
The addition of `addDeclErr` introduced a memory leak at every call
site, and I also would like to push back on having more than 1
compilation error per `Decl`.
This reverts commit 1634d45f1d53c8d7bfefa56ab4d2fa4cc8218b6d.12 files changed, 40 insertions(+), 120 deletions(-)
src/Compilation.zig+12-13| ... | ... | @@ -1350,11 +1350,8 @@ pub fn totalErrorCount(self: *Compilation) usize { |
| 1350 | 1350 | var total: usize = self.failed_c_objects.items().len; |
| 1351 | 1351 | |
| 1352 | 1352 | if (self.bin_file.options.module) |module| { |
| 1353 | for (module.failed_decls.items()) |entry| { | |
| 1354 | assert(entry.value.items.len > 0); | |
| 1355 | total += entry.value.items.len; | |
| 1356 | } | |
| 1357 | total += module.failed_exports.items().len + | |
| 1353 | total += module.failed_decls.items().len + | |
| 1354 | module.failed_exports.items().len + | |
| 1358 | 1355 | module.failed_files.items().len + |
| 1359 | 1356 | @boolToInt(module.failed_root_src_file != null); |
| 1360 | 1357 | } |
| ... | ... | @@ -1388,11 +1385,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 1388 | 1385 | } |
| 1389 | 1386 | for (module.failed_decls.items()) |entry| { |
| 1390 | 1387 | const decl = entry.key; |
| 1391 | const err_msg_list = entry.value; | |
| 1392 | for (err_msg_list.items) |err_msg| { | |
| 1393 | const source = try decl.scope.getSource(module); | |
| 1394 | try AllErrors.add(&arena, &errors, decl.scope.subFilePath(), source, err_msg.*); | |
| 1395 | } | |
| 1388 | const err_msg = entry.value; | |
| 1389 | const source = try decl.scope.getSource(module); | |
| 1390 | try AllErrors.add(&arena, &errors, decl.scope.subFilePath(), source, err_msg.*); | |
| 1396 | 1391 | } |
| 1397 | 1392 | for (module.failed_exports.items()) |entry| { |
| 1398 | 1393 | const decl = entry.key.owner_decl; |
| ... | ... | @@ -1485,6 +1480,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1485 | 1480 | } |
| 1486 | 1481 | |
| 1487 | 1482 | assert(decl.typed_value.most_recent.typed_value.ty.hasCodeGenBits()); |
| 1483 | ||
| 1488 | 1484 | self.bin_file.updateDecl(module, decl) catch |err| { |
| 1489 | 1485 | switch (err) { |
| 1490 | 1486 | error.OutOfMemory => return error.OutOfMemory, |
| ... | ... | @@ -1492,7 +1488,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1492 | 1488 | decl.analysis = .dependency_failure; |
| 1493 | 1489 | }, |
| 1494 | 1490 | else => { |
| 1495 | try module.addDeclErr(decl, try ErrorMsg.create( | |
| 1491 | try module.failed_decls.ensureCapacity(module.gpa, module.failed_decls.items().len + 1); | |
| 1492 | module.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create( | |
| 1496 | 1493 | module.gpa, |
| 1497 | 1494 | decl.src(), |
| 1498 | 1495 | "unable to codegen: {}", |
| ... | ... | @@ -1511,7 +1508,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1511 | 1508 | decl.analysis = .dependency_failure; |
| 1512 | 1509 | }, |
| 1513 | 1510 | else => { |
| 1514 | try module.addDeclErr(decl, try ErrorMsg.create( | |
| 1511 | try module.failed_decls.ensureCapacity(module.gpa, module.failed_decls.items().len + 1); | |
| 1512 | module.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create( | |
| 1515 | 1513 | module.gpa, |
| 1516 | 1514 | decl.src(), |
| 1517 | 1515 | "unable to generate C header: {}", |
| ... | ... | @@ -1533,7 +1531,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1533 | 1531 | .update_line_number => |decl| { |
| 1534 | 1532 | const module = self.bin_file.options.module.?; |
| 1535 | 1533 | self.bin_file.updateDeclLineNumber(module, decl) catch |err| { |
| 1536 | try module.addDeclErr(decl, try ErrorMsg.create( | |
| 1534 | try module.failed_decls.ensureCapacity(module.gpa, module.failed_decls.items().len + 1); | |
| 1535 | module.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create( | |
| 1537 | 1536 | module.gpa, |
| 1538 | 1537 | decl.src(), |
| 1539 | 1538 | "unable to update line number: {}", |
src/Module.zig+17-29| ... | ... | @@ -53,7 +53,7 @@ decl_table: std.ArrayHashMapUnmanaged(Scope.NameHash, *Decl, Scope.name_hash_has |
| 53 | 53 | /// The ErrorMsg memory is owned by the decl, using Module's general purpose allocator. |
| 54 | 54 | /// Note that a Decl can succeed but the Fn it represents can fail. In this case, |
| 55 | 55 | /// a Decl can have a failed_decls entry but have analysis status of success. |
| 56 | failed_decls: std.AutoArrayHashMapUnmanaged(*Decl, ArrayListUnmanaged(*Compilation.ErrorMsg)) = .{}, | |
| 56 | failed_decls: std.AutoArrayHashMapUnmanaged(*Decl, *Compilation.ErrorMsg) = .{}, | |
| 57 | 57 | /// Using a map here for consistency with the other fields here. |
| 58 | 58 | /// The ErrorMsg memory is owned by the `Scope`, using Module's general purpose allocator. |
| 59 | 59 | failed_files: std.AutoArrayHashMapUnmanaged(*Scope, *Compilation.ErrorMsg) = .{}, |
| ... | ... | @@ -849,11 +849,8 @@ pub fn deinit(self: *Module) void { |
| 849 | 849 | } |
| 850 | 850 | self.decl_table.deinit(gpa); |
| 851 | 851 | |
| 852 | for (self.failed_decls.items()) |*entry| { | |
| 853 | for (entry.value.items) |compile_err| { | |
| 854 | compile_err.destroy(gpa); | |
| 855 | } | |
| 856 | entry.value.deinit(gpa); | |
| 852 | for (self.failed_decls.items()) |entry| { | |
| 853 | entry.value.destroy(gpa); | |
| 857 | 854 | } |
| 858 | 855 | self.failed_decls.deinit(gpa); |
| 859 | 856 | |
| ... | ... | @@ -949,7 +946,8 @@ pub fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { |
| 949 | 946 | error.OutOfMemory => return error.OutOfMemory, |
| 950 | 947 | error.AnalysisFail => return error.AnalysisFail, |
| 951 | 948 | else => { |
| 952 | try self.addDeclErr(decl, try Compilation.ErrorMsg.create( | |
| 949 | try self.failed_decls.ensureCapacity(self.gpa, self.failed_decls.items().len + 1); | |
| 950 | self.failed_decls.putAssumeCapacityNoClobber(decl, try Compilation.ErrorMsg.create( | |
| 953 | 951 | self.gpa, |
| 954 | 952 | decl.src(), |
| 955 | 953 | "unable to analyze: {}", |
| ... | ... | @@ -1556,7 +1554,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void |
| 1556 | 1554 | decl.analysis = .sema_failure; |
| 1557 | 1555 | const err_msg = try Compilation.ErrorMsg.create(self.gpa, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name}); |
| 1558 | 1556 | errdefer err_msg.destroy(self.gpa); |
| 1559 | try self.addDeclErr(decl, err_msg); | |
| 1557 | try self.failed_decls.putNoClobber(self.gpa, decl, err_msg); | |
| 1560 | 1558 | } else { |
| 1561 | 1559 | if (!srcHashEql(decl.contents_hash, contents_hash)) { |
| 1562 | 1560 | try self.markOutdatedDecl(decl); |
| ... | ... | @@ -1598,7 +1596,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void |
| 1598 | 1596 | decl.analysis = .sema_failure; |
| 1599 | 1597 | const err_msg = try Compilation.ErrorMsg.create(self.gpa, name_loc.start, "redefinition of '{}'", .{decl.name}); |
| 1600 | 1598 | errdefer err_msg.destroy(self.gpa); |
| 1601 | try self.addDeclErr(decl, err_msg); | |
| 1599 | try self.failed_decls.putNoClobber(self.gpa, decl, err_msg); | |
| 1602 | 1600 | } else if (!srcHashEql(decl.contents_hash, contents_hash)) { |
| 1603 | 1601 | try self.markOutdatedDecl(decl); |
| 1604 | 1602 | decl.contents_hash = contents_hash; |
| ... | ... | @@ -1724,11 +1722,8 @@ pub fn deleteDecl(self: *Module, decl: *Decl) !void { |
| 1724 | 1722 | try self.markOutdatedDecl(dep); |
| 1725 | 1723 | } |
| 1726 | 1724 | } |
| 1727 | if (self.failed_decls.remove(decl)) |*entry| { | |
| 1728 | for (entry.value.items) |compile_err| { | |
| 1729 | compile_err.destroy(self.gpa); | |
| 1730 | } | |
| 1731 | entry.value.deinit(self.gpa); | |
| 1725 | if (self.failed_decls.remove(decl)) |entry| { | |
| 1726 | entry.value.destroy(self.gpa); | |
| 1732 | 1727 | } |
| 1733 | 1728 | self.deleteDeclExports(decl); |
| 1734 | 1729 | self.comp.bin_file.freeDecl(decl); |
| ... | ... | @@ -1807,11 +1802,8 @@ pub fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { |
| 1807 | 1802 | fn markOutdatedDecl(self: *Module, decl: *Decl) !void { |
| 1808 | 1803 | log.debug("mark {} outdated\n", .{decl.name}); |
| 1809 | 1804 | try self.comp.work_queue.writeItem(.{ .analyze_decl = decl }); |
| 1810 | if (self.failed_decls.remove(decl)) |*entry| { | |
| 1811 | for (entry.value.items) |compile_err| { | |
| 1812 | compile_err.destroy(self.gpa); | |
| 1813 | } | |
| 1814 | entry.value.deinit(self.gpa); | |
| 1805 | if (self.failed_decls.remove(decl)) |entry| { | |
| 1806 | entry.value.destroy(self.gpa); | |
| 1815 | 1807 | } |
| 1816 | 1808 | decl.analysis = .outdated; |
| 1817 | 1809 | } |
| ... | ... | @@ -2956,14 +2948,10 @@ pub fn failNode( |
| 2956 | 2948 | return self.fail(scope, src, format, args); |
| 2957 | 2949 | } |
| 2958 | 2950 | |
| 2959 | pub fn addDeclErr(self: *Module, decl: *Decl, err: *Compilation.ErrorMsg) error{OutOfMemory}!void { | |
| 2960 | const entry = try self.failed_decls.getOrPutValue(self.gpa, decl, .{}); | |
| 2961 | try entry.value.append(self.gpa, err); | |
| 2962 | } | |
| 2963 | ||
| 2964 | 2951 | fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Compilation.ErrorMsg) InnerError { |
| 2965 | 2952 | { |
| 2966 | 2953 | errdefer err_msg.destroy(self.gpa); |
| 2954 | try self.failed_decls.ensureCapacity(self.gpa, self.failed_decls.items().len + 1); | |
| 2967 | 2955 | try self.failed_files.ensureCapacity(self.gpa, self.failed_files.items().len + 1); |
| 2968 | 2956 | } |
| 2969 | 2957 | switch (scope.tag) { |
| ... | ... | @@ -2971,7 +2959,7 @@ fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Com |
| 2971 | 2959 | const decl = scope.cast(Scope.DeclAnalysis).?.decl; |
| 2972 | 2960 | decl.analysis = .sema_failure; |
| 2973 | 2961 | decl.generation = self.generation; |
| 2974 | try self.addDeclErr(decl, err_msg); | |
| 2962 | self.failed_decls.putAssumeCapacityNoClobber(decl, err_msg); | |
| 2975 | 2963 | }, |
| 2976 | 2964 | .block => { |
| 2977 | 2965 | const block = scope.cast(Scope.Block).?; |
| ... | ... | @@ -2981,25 +2969,25 @@ fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Com |
| 2981 | 2969 | block.decl.analysis = .sema_failure; |
| 2982 | 2970 | block.decl.generation = self.generation; |
| 2983 | 2971 | } |
| 2984 | try self.addDeclErr(block.decl, err_msg); | |
| 2972 | self.failed_decls.putAssumeCapacityNoClobber(block.decl, err_msg); | |
| 2985 | 2973 | }, |
| 2986 | 2974 | .gen_zir => { |
| 2987 | 2975 | const gen_zir = scope.cast(Scope.GenZIR).?; |
| 2988 | 2976 | gen_zir.decl.analysis = .sema_failure; |
| 2989 | 2977 | gen_zir.decl.generation = self.generation; |
| 2990 | try self.addDeclErr(gen_zir.decl, err_msg); | |
| 2978 | self.failed_decls.putAssumeCapacityNoClobber(gen_zir.decl, err_msg); | |
| 2991 | 2979 | }, |
| 2992 | 2980 | .local_val => { |
| 2993 | 2981 | const gen_zir = scope.cast(Scope.LocalVal).?.gen_zir; |
| 2994 | 2982 | gen_zir.decl.analysis = .sema_failure; |
| 2995 | 2983 | gen_zir.decl.generation = self.generation; |
| 2996 | try self.addDeclErr(gen_zir.decl, err_msg); | |
| 2984 | self.failed_decls.putAssumeCapacityNoClobber(gen_zir.decl, err_msg); | |
| 2997 | 2985 | }, |
| 2998 | 2986 | .local_ptr => { |
| 2999 | 2987 | const gen_zir = scope.cast(Scope.LocalPtr).?.gen_zir; |
| 3000 | 2988 | gen_zir.decl.analysis = .sema_failure; |
| 3001 | 2989 | gen_zir.decl.generation = self.generation; |
| 3002 | try self.addDeclErr(gen_zir.decl, err_msg); | |
| 2990 | self.failed_decls.putAssumeCapacityNoClobber(gen_zir.decl, err_msg); | |
| 3003 | 2991 | }, |
| 3004 | 2992 | .zir_module => { |
| 3005 | 2993 | const zir_module = scope.cast(Scope.ZIRModule).?; |
src/astgen.zig-13| ... | ... | @@ -2333,17 +2333,6 @@ fn compileError(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerE |
| 2333 | 2333 | return addZIRUnOp(mod, scope, src, .compileerror, target); |
| 2334 | 2334 | } |
| 2335 | 2335 | |
| 2336 | fn compileLog(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst { | |
| 2337 | const tree = scope.tree(); | |
| 2338 | const arena = scope.arena(); | |
| 2339 | const src = tree.token_locs[call.builtin_token].start; | |
| 2340 | const params = call.params(); | |
| 2341 | var targets = try arena.alloc(*zir.Inst, params.len); | |
| 2342 | for (params) |param, param_i| | |
| 2343 | targets[param_i] = try expr(mod, scope, .none, param); | |
| 2344 | return addZIRInst(mod, scope, src, zir.Inst.CompileLog, .{ .to_log = targets }, .{}); | |
| 2345 | } | |
| 2346 | ||
| 2347 | 2336 | fn typeOf(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst { |
| 2348 | 2337 | const tree = scope.tree(); |
| 2349 | 2338 | const arena = scope.arena(); |
| ... | ... | @@ -2389,8 +2378,6 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built |
| 2389 | 2378 | return rlWrap(mod, scope, rl, try import(mod, scope, call)); |
| 2390 | 2379 | } else if (mem.eql(u8, builtin_name, "@compileError")) { |
| 2391 | 2380 | return compileError(mod, scope, call); |
| 2392 | } else if (mem.eql(u8, builtin_name, "@compileLog")) { | |
| 2393 | return compileLog(mod, scope, call); | |
| 2394 | 2381 | } else { |
| 2395 | 2382 | return mod.failTok(scope, call.builtin_token, "invalid builtin function: '{}'", .{builtin_name}); |
| 2396 | 2383 | } |
src/codegen/c.zig+1-1| ... | ... | @@ -106,7 +106,7 @@ pub fn generateHeader( |
| 106 | 106 | const writer = header.buf.writer(); |
| 107 | 107 | renderFunctionSignature(&ctx, header, writer, decl) catch |err| { |
| 108 | 108 | if (err == error.AnalysisFail) { |
| 109 | try module.addDeclErr(decl, ctx.error_msg); | |
| 109 | try module.failed_decls.put(module.gpa, decl, ctx.error_msg); | |
| 110 | 110 | } |
| 111 | 111 | return err; |
| 112 | 112 | }; |
src/link/C.zig+1-1| ... | ... | @@ -106,7 +106,7 @@ pub fn deinit(self: *C) void { |
| 106 | 106 | pub fn updateDecl(self: *C, module: *Module, decl: *Module.Decl) !void { |
| 107 | 107 | codegen.generate(self, decl) catch |err| { |
| 108 | 108 | if (err == error.AnalysisFail) { |
| 109 | try module.addDeclErr(decl, self.error_msg); | |
| 109 | try module.failed_decls.put(module.gpa, decl, self.error_msg); | |
| 110 | 110 | } |
| 111 | 111 | return err; |
| 112 | 112 | }; |
src/link/Coff.zig+1-1| ... | ... | @@ -658,7 +658,7 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void { |
| 658 | 658 | .appended => code_buffer.items, |
| 659 | 659 | .fail => |em| { |
| 660 | 660 | decl.analysis = .codegen_failure; |
| 661 | try module.addDeclErr(decl, em); | |
| 661 | try module.failed_decls.put(module.gpa, decl, em); | |
| 662 | 662 | return; |
| 663 | 663 | }, |
| 664 | 664 | }; |
src/link/Elf.zig+1-1| ... | ... | @@ -2248,7 +2248,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void { |
| 2248 | 2248 | .appended => code_buffer.items, |
| 2249 | 2249 | .fail => |em| { |
| 2250 | 2250 | decl.analysis = .codegen_failure; |
| 2251 | try module.addDeclErr(decl, em); | |
| 2251 | try module.failed_decls.put(module.gpa, decl, em); | |
| 2252 | 2252 | return; |
| 2253 | 2253 | }, |
| 2254 | 2254 | }; |
src/link/MachO.zig+1-1| ... | ... | @@ -1062,7 +1062,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void { |
| 1062 | 1062 | .appended => code_buffer.items, |
| 1063 | 1063 | .fail => |em| { |
| 1064 | 1064 | decl.analysis = .codegen_failure; |
| 1065 | try module.addDeclErr(decl, em); | |
| 1065 | try module.failed_decls.put(module.gpa, decl, em); | |
| 1066 | 1066 | return; |
| 1067 | 1067 | }, |
| 1068 | 1068 | }; |
src/value.zig+1-1| ... | ... | @@ -350,7 +350,7 @@ pub const Value = extern union { |
| 350 | 350 | val = elem_ptr.array_ptr; |
| 351 | 351 | }, |
| 352 | 352 | .empty_array => return out_stream.writeAll(".{}"), |
| 353 | .enum_literal => return out_stream.print(".{z}", .{@fieldParentPtr(Payload.Bytes, "base", self.ptr_otherwise).data}), | |
| 353 | .enum_literal => return out_stream.print(".{z}", .{self.cast(Payload.Bytes).?.data}), | |
| 354 | 354 | .bytes => return out_stream.print("\"{Z}\"", .{self.cast(Payload.Bytes).?.data}), |
| 355 | 355 | .repeated => { |
| 356 | 356 | try out_stream.writeAll("(repeated) "); |
src/zir.zig+4-21| ... | ... | @@ -126,8 +126,6 @@ pub const Inst = struct { |
| 126 | 126 | coerce_to_ptr_elem, |
| 127 | 127 | /// Emit an error message and fail compilation. |
| 128 | 128 | compileerror, |
| 129 | /// Log compile time variables and emit an error message. | |
| 130 | compilelog, | |
| 131 | 129 | /// Conditional branch. Splits control flow based on a boolean condition value. |
| 132 | 130 | condbr, |
| 133 | 131 | /// Special case, has no textual representation. |
| ... | ... | @@ -394,7 +392,6 @@ pub const Inst = struct { |
| 394 | 392 | .declval => DeclVal, |
| 395 | 393 | .declval_in_module => DeclValInModule, |
| 396 | 394 | .coerce_result_block_ptr => CoerceResultBlockPtr, |
| 397 | .compilelog => CompileLog, | |
| 398 | 395 | .loop => Loop, |
| 399 | 396 | .@"const" => Const, |
| 400 | 397 | .str => Str, |
| ... | ... | @@ -524,7 +521,6 @@ pub const Inst = struct { |
| 524 | 521 | .slice_start, |
| 525 | 522 | .import, |
| 526 | 523 | .switch_range, |
| 527 | .compilelog, | |
| 528 | 524 | .typeof_peer, |
| 529 | 525 | => false, |
| 530 | 526 | |
| ... | ... | @@ -709,19 +705,6 @@ pub const Inst = struct { |
| 709 | 705 | kw_args: struct {}, |
| 710 | 706 | }; |
| 711 | 707 | |
| 712 | pub const CompileLog = struct { | |
| 713 | pub const base_tag = Tag.compilelog; | |
| 714 | base: Inst, | |
| 715 | ||
| 716 | positionals: struct { | |
| 717 | to_log: []*Inst, | |
| 718 | }, | |
| 719 | kw_args: struct { | |
| 720 | /// If we have seen it already so don't make another error | |
| 721 | seen: bool = false, | |
| 722 | }, | |
| 723 | }; | |
| 724 | ||
| 725 | 708 | pub const Const = struct { |
| 726 | 709 | pub const base_tag = Tag.@"const"; |
| 727 | 710 | base: Inst, |
| ... | ... | @@ -1940,7 +1923,7 @@ const EmitZIR = struct { |
| 1940 | 1923 | .sema_failure, |
| 1941 | 1924 | .sema_failure_retryable, |
| 1942 | 1925 | .dependency_failure, |
| 1943 | => if (self.old_module.failed_decls.get(ir_decl)) |err_msg_list| { | |
| 1926 | => if (self.old_module.failed_decls.get(ir_decl)) |err_msg| { | |
| 1944 | 1927 | const fail_inst = try self.arena.allocator.create(Inst.UnOp); |
| 1945 | 1928 | fail_inst.* = .{ |
| 1946 | 1929 | .base = .{ |
| ... | ... | @@ -1949,7 +1932,7 @@ const EmitZIR = struct { |
| 1949 | 1932 | }, |
| 1950 | 1933 | .positionals = .{ |
| 1951 | 1934 | .operand = blk: { |
| 1952 | const msg_str = try self.arena.allocator.dupe(u8, err_msg_list.items[0].msg); | |
| 1935 | const msg_str = try self.arena.allocator.dupe(u8, err_msg.msg); | |
| 1953 | 1936 | |
| 1954 | 1937 | const str_inst = try self.arena.allocator.create(Inst.Str); |
| 1955 | 1938 | str_inst.* = .{ |
| ... | ... | @@ -1958,7 +1941,7 @@ const EmitZIR = struct { |
| 1958 | 1941 | .tag = Inst.Str.base_tag, |
| 1959 | 1942 | }, |
| 1960 | 1943 | .positionals = .{ |
| 1961 | .bytes = msg_str, | |
| 1944 | .bytes = err_msg.msg, | |
| 1962 | 1945 | }, |
| 1963 | 1946 | .kw_args = .{}, |
| 1964 | 1947 | }; |
| ... | ... | @@ -2085,7 +2068,7 @@ const EmitZIR = struct { |
| 2085 | 2068 | try self.emitBody(body, &inst_table, &instructions); |
| 2086 | 2069 | }, |
| 2087 | 2070 | .sema_failure => { |
| 2088 | const err_msg = self.old_module.failed_decls.get(module_fn.owner_decl).?.items[0]; | |
| 2071 | const err_msg = self.old_module.failed_decls.get(module_fn.owner_decl).?; | |
| 2089 | 2072 | const fail_inst = try self.arena.allocator.create(Inst.UnOp); |
| 2090 | 2073 | fail_inst.* = .{ |
| 2091 | 2074 | .base = .{ |
src/zir_sema.zig-23| ... | ... | @@ -45,7 +45,6 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! |
| 45 | 45 | .coerce_result_ptr => return analyzeInstCoerceResultPtr(mod, scope, old_inst.castTag(.coerce_result_ptr).?), |
| 46 | 46 | .coerce_to_ptr_elem => return analyzeInstCoerceToPtrElem(mod, scope, old_inst.castTag(.coerce_to_ptr_elem).?), |
| 47 | 47 | .compileerror => return analyzeInstCompileError(mod, scope, old_inst.castTag(.compileerror).?), |
| 48 | .compilelog => return analyzeInstCompileLog(mod, scope, old_inst.castTag(.compilelog).?), | |
| 49 | 48 | .@"const" => return analyzeInstConst(mod, scope, old_inst.castTag(.@"const").?), |
| 50 | 49 | .dbg_stmt => return analyzeInstDbgStmt(mod, scope, old_inst.castTag(.dbg_stmt).?), |
| 51 | 50 | .declref => return analyzeInstDeclRef(mod, scope, old_inst.castTag(.declref).?), |
| ... | ... | @@ -503,28 +502,6 @@ fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) In |
| 503 | 502 | return mod.fail(scope, inst.base.src, "{}", .{msg}); |
| 504 | 503 | } |
| 505 | 504 | |
| 506 | fn analyzeInstCompileLog(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileLog) InnerError!*Inst { | |
| 507 | std.debug.print("| ", .{}); | |
| 508 | for (inst.positionals.to_log) |item, i| { | |
| 509 | const to_log = try resolveInst(mod, scope, item); | |
| 510 | if (to_log.value()) |val| { | |
| 511 | std.debug.print("{}", .{val}); | |
| 512 | } else { | |
| 513 | std.debug.print("(runtime value)", .{}); | |
| 514 | } | |
| 515 | if (i != inst.positionals.to_log.len - 1) std.debug.print(", ", .{}); | |
| 516 | } | |
| 517 | std.debug.print("\n", .{}); | |
| 518 | if (!inst.kw_args.seen) { | |
| 519 | inst.kw_args.seen = true; // so that we do not give multiple compile errors if it gets evaled twice | |
| 520 | switch (mod.fail(scope, inst.base.src, "found compile log statement", .{})) { | |
| 521 | error.AnalysisFail => {}, // analysis continues | |
| 522 | else => |e| return e, | |
| 523 | } | |
| 524 | } | |
| 525 | return mod.constVoid(scope, inst.base.src); | |
| 526 | } | |
| 527 | ||
| 528 | 505 | fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst { |
| 529 | 506 | const b = try mod.requireRuntimeBlock(scope, inst.base.src); |
| 530 | 507 | const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty; |
test/stage2/test.zig+1-15| ... | ... | @@ -1171,27 +1171,13 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1171 | 1171 | \\fn entry() void {} |
| 1172 | 1172 | , &[_][]const u8{":2:4: error: redefinition of 'entry'"}); |
| 1173 | 1173 | |
| 1174 | ctx.compileError("compileLog", linux_x64, | |
| 1175 | \\export fn _start() noreturn { | |
| 1176 | \\ const b = true; | |
| 1177 | \\ var f: u32 = 1; | |
| 1178 | \\ @compileLog(b, 20, f, x, .foo); | |
| 1179 | \\ var y: u32 = true; | |
| 1180 | \\ unreachable; | |
| 1181 | \\} | |
| 1182 | \\fn x() void {} | |
| 1183 | , &[_][]const u8{ | |
| 1184 | ":4:3: error: found compile log statement", ":5:16: error: expected u32, found bool", | |
| 1185 | }); | |
| 1186 | ||
| 1187 | // "| true, 20, (runtime value), (function)" // TODO if this is here it invalidates the compile error checker. Need a way to check though. | |
| 1188 | ||
| 1189 | 1174 | ctx.compileError("compileError", linux_x64, |
| 1190 | 1175 | \\export fn _start() noreturn { |
| 1191 | 1176 | \\ @compileError("this is an error"); |
| 1192 | 1177 | \\ unreachable; |
| 1193 | 1178 | \\} |
| 1194 | 1179 | , &[_][]const u8{":2:3: error: this is an error"}); |
| 1180 | ||
| 1195 | 1181 | { |
| 1196 | 1182 | var case = ctx.obj("variable shadowing", linux_x64); |
| 1197 | 1183 | case.addError( |