| 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,11 +1350,8 @@ pub fn totalErrorCount(self: *Compilation) usize { |
| 1350 | var total: usize = self.failed_c_objects.items().len; | 1350 | var total: usize = self.failed_c_objects.items().len; |
| 1351 | 1351 | ||
| 1352 | if (self.bin_file.options.module) |module| { | 1352 | if (self.bin_file.options.module) |module| { |
| 1353 | for (module.failed_decls.items()) |entry| { | 1353 | total += module.failed_decls.items().len + |
| 1354 | assert(entry.value.items.len > 0); | 1354 | module.failed_exports.items().len + |
| 1355 | total += entry.value.items.len; | ||
| 1356 | } | ||
| 1357 | total += module.failed_exports.items().len + | ||
| 1358 | module.failed_files.items().len + | 1355 | module.failed_files.items().len + |
| 1359 | @boolToInt(module.failed_root_src_file != null); | 1356 | @boolToInt(module.failed_root_src_file != null); |
| 1360 | } | 1357 | } |
| ... | @@ -1388,11 +1385,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { | ... | @@ -1388,11 +1385,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 1388 | } | 1385 | } |
| 1389 | for (module.failed_decls.items()) |entry| { | 1386 | for (module.failed_decls.items()) |entry| { |
| 1390 | const decl = entry.key; | 1387 | const decl = entry.key; |
| 1391 | const err_msg_list = entry.value; | 1388 | const err_msg = entry.value; |
| 1392 | for (err_msg_list.items) |err_msg| { | 1389 | const source = try decl.scope.getSource(module); |
| 1393 | const source = try decl.scope.getSource(module); | 1390 | try AllErrors.add(&arena, &errors, decl.scope.subFilePath(), source, err_msg.*); |
| 1394 | try AllErrors.add(&arena, &errors, decl.scope.subFilePath(), source, err_msg.*); | ||
| 1395 | } | ||
| 1396 | } | 1391 | } |
| 1397 | for (module.failed_exports.items()) |entry| { | 1392 | for (module.failed_exports.items()) |entry| { |
| 1398 | const decl = entry.key.owner_decl; | 1393 | const decl = entry.key.owner_decl; |
| ... | @@ -1485,6 +1480,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor | ... | @@ -1485,6 +1480,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1485 | } | 1480 | } |
| 1486 | 1481 | ||
| 1487 | assert(decl.typed_value.most_recent.typed_value.ty.hasCodeGenBits()); | 1482 | assert(decl.typed_value.most_recent.typed_value.ty.hasCodeGenBits()); |
| 1483 | |||
| 1488 | self.bin_file.updateDecl(module, decl) catch |err| { | 1484 | self.bin_file.updateDecl(module, decl) catch |err| { |
| 1489 | switch (err) { | 1485 | switch (err) { |
| 1490 | error.OutOfMemory => return error.OutOfMemory, | 1486 | error.OutOfMemory => return error.OutOfMemory, |
| ... | @@ -1492,7 +1488,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor | ... | @@ -1492,7 +1488,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1492 | decl.analysis = .dependency_failure; | 1488 | decl.analysis = .dependency_failure; |
| 1493 | }, | 1489 | }, |
| 1494 | else => { | 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 | module.gpa, | 1493 | module.gpa, |
| 1497 | decl.src(), | 1494 | decl.src(), |
| 1498 | "unable to codegen: {}", | 1495 | "unable to codegen: {}", |
| ... | @@ -1511,7 +1508,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor | ... | @@ -1511,7 +1508,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1511 | decl.analysis = .dependency_failure; | 1508 | decl.analysis = .dependency_failure; |
| 1512 | }, | 1509 | }, |
| 1513 | else => { | 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 | module.gpa, | 1513 | module.gpa, |
| 1516 | decl.src(), | 1514 | decl.src(), |
| 1517 | "unable to generate C header: {}", | 1515 | "unable to generate C header: {}", |
| ... | @@ -1533,7 +1531,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor | ... | @@ -1533,7 +1531,8 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 1533 | .update_line_number => |decl| { | 1531 | .update_line_number => |decl| { |
| 1534 | const module = self.bin_file.options.module.?; | 1532 | const module = self.bin_file.options.module.?; |
| 1535 | self.bin_file.updateDeclLineNumber(module, decl) catch |err| { | 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 | module.gpa, | 1536 | module.gpa, |
| 1538 | decl.src(), | 1537 | decl.src(), |
| 1539 | "unable to update line number: {}", | 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,7 +53,7 @@ decl_table: std.ArrayHashMapUnmanaged(Scope.NameHash, *Decl, Scope.name_hash_has |
| 53 | /// The ErrorMsg memory is owned by the decl, using Module's general purpose allocator. | 53 | /// The ErrorMsg memory is owned by the decl, using Module's general purpose allocator. |
| 54 | /// Note that a Decl can succeed but the Fn it represents can fail. In this case, | 54 | /// Note that a Decl can succeed but the Fn it represents can fail. In this case, |
| 55 | /// a Decl can have a failed_decls entry but have analysis status of success. | 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 | /// Using a map here for consistency with the other fields here. | 57 | /// Using a map here for consistency with the other fields here. |
| 58 | /// The ErrorMsg memory is owned by the `Scope`, using Module's general purpose allocator. | 58 | /// The ErrorMsg memory is owned by the `Scope`, using Module's general purpose allocator. |
| 59 | failed_files: std.AutoArrayHashMapUnmanaged(*Scope, *Compilation.ErrorMsg) = .{}, | 59 | failed_files: std.AutoArrayHashMapUnmanaged(*Scope, *Compilation.ErrorMsg) = .{}, |
| ... | @@ -849,11 +849,8 @@ pub fn deinit(self: *Module) void { | ... | @@ -849,11 +849,8 @@ pub fn deinit(self: *Module) void { |
| 849 | } | 849 | } |
| 850 | self.decl_table.deinit(gpa); | 850 | self.decl_table.deinit(gpa); |
| 851 | 851 | ||
| 852 | for (self.failed_decls.items()) |*entry| { | 852 | for (self.failed_decls.items()) |entry| { |
| 853 | for (entry.value.items) |compile_err| { | 853 | entry.value.destroy(gpa); |
| 854 | compile_err.destroy(gpa); | ||
| 855 | } | ||
| 856 | entry.value.deinit(gpa); | ||
| 857 | } | 854 | } |
| 858 | self.failed_decls.deinit(gpa); | 855 | self.failed_decls.deinit(gpa); |
| 859 | 856 | ||
| ... | @@ -949,7 +946,8 @@ pub fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { | ... | @@ -949,7 +946,8 @@ pub fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { |
| 949 | error.OutOfMemory => return error.OutOfMemory, | 946 | error.OutOfMemory => return error.OutOfMemory, |
| 950 | error.AnalysisFail => return error.AnalysisFail, | 947 | error.AnalysisFail => return error.AnalysisFail, |
| 951 | else => { | 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 | self.gpa, | 951 | self.gpa, |
| 954 | decl.src(), | 952 | decl.src(), |
| 955 | "unable to analyze: {}", | 953 | "unable to analyze: {}", |
| ... | @@ -1556,7 +1554,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void | ... | @@ -1556,7 +1554,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void |
| 1556 | decl.analysis = .sema_failure; | 1554 | decl.analysis = .sema_failure; |
| 1557 | const err_msg = try Compilation.ErrorMsg.create(self.gpa, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name}); | 1555 | const err_msg = try Compilation.ErrorMsg.create(self.gpa, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name}); |
| 1558 | errdefer err_msg.destroy(self.gpa); | 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 | } else { | 1558 | } else { |
| 1561 | if (!srcHashEql(decl.contents_hash, contents_hash)) { | 1559 | if (!srcHashEql(decl.contents_hash, contents_hash)) { |
| 1562 | try self.markOutdatedDecl(decl); | 1560 | try self.markOutdatedDecl(decl); |
| ... | @@ -1598,7 +1596,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void | ... | @@ -1598,7 +1596,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void |
| 1598 | decl.analysis = .sema_failure; | 1596 | decl.analysis = .sema_failure; |
| 1599 | const err_msg = try Compilation.ErrorMsg.create(self.gpa, name_loc.start, "redefinition of '{}'", .{decl.name}); | 1597 | const err_msg = try Compilation.ErrorMsg.create(self.gpa, name_loc.start, "redefinition of '{}'", .{decl.name}); |
| 1600 | errdefer err_msg.destroy(self.gpa); | 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 | } else if (!srcHashEql(decl.contents_hash, contents_hash)) { | 1600 | } else if (!srcHashEql(decl.contents_hash, contents_hash)) { |
| 1603 | try self.markOutdatedDecl(decl); | 1601 | try self.markOutdatedDecl(decl); |
| 1604 | decl.contents_hash = contents_hash; | 1602 | decl.contents_hash = contents_hash; |
| ... | @@ -1724,11 +1722,8 @@ pub fn deleteDecl(self: *Module, decl: *Decl) !void { | ... | @@ -1724,11 +1722,8 @@ pub fn deleteDecl(self: *Module, decl: *Decl) !void { |
| 1724 | try self.markOutdatedDecl(dep); | 1722 | try self.markOutdatedDecl(dep); |
| 1725 | } | 1723 | } |
| 1726 | } | 1724 | } |
| 1727 | if (self.failed_decls.remove(decl)) |*entry| { | 1725 | if (self.failed_decls.remove(decl)) |entry| { |
| 1728 | for (entry.value.items) |compile_err| { | 1726 | entry.value.destroy(self.gpa); |
| 1729 | compile_err.destroy(self.gpa); | ||
| 1730 | } | ||
| 1731 | entry.value.deinit(self.gpa); | ||
| 1732 | } | 1727 | } |
| 1733 | self.deleteDeclExports(decl); | 1728 | self.deleteDeclExports(decl); |
| 1734 | self.comp.bin_file.freeDecl(decl); | 1729 | self.comp.bin_file.freeDecl(decl); |
| ... | @@ -1807,11 +1802,8 @@ pub fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { | ... | @@ -1807,11 +1802,8 @@ pub fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { |
| 1807 | fn markOutdatedDecl(self: *Module, decl: *Decl) !void { | 1802 | fn markOutdatedDecl(self: *Module, decl: *Decl) !void { |
| 1808 | log.debug("mark {} outdated\n", .{decl.name}); | 1803 | log.debug("mark {} outdated\n", .{decl.name}); |
| 1809 | try self.comp.work_queue.writeItem(.{ .analyze_decl = decl }); | 1804 | try self.comp.work_queue.writeItem(.{ .analyze_decl = decl }); |
| 1810 | if (self.failed_decls.remove(decl)) |*entry| { | 1805 | if (self.failed_decls.remove(decl)) |entry| { |
| 1811 | for (entry.value.items) |compile_err| { | 1806 | entry.value.destroy(self.gpa); |
| 1812 | compile_err.destroy(self.gpa); | ||
| 1813 | } | ||
| 1814 | entry.value.deinit(self.gpa); | ||
| 1815 | } | 1807 | } |
| 1816 | decl.analysis = .outdated; | 1808 | decl.analysis = .outdated; |
| 1817 | } | 1809 | } |
| ... | @@ -2956,14 +2948,10 @@ pub fn failNode( | ... | @@ -2956,14 +2948,10 @@ pub fn failNode( |
| 2956 | return self.fail(scope, src, format, args); | 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 | fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Compilation.ErrorMsg) InnerError { | 2951 | fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Compilation.ErrorMsg) InnerError { |
| 2965 | { | 2952 | { |
| 2966 | errdefer err_msg.destroy(self.gpa); | 2953 | errdefer err_msg.destroy(self.gpa); |
| 2954 | try self.failed_decls.ensureCapacity(self.gpa, self.failed_decls.items().len + 1); | ||
| 2967 | try self.failed_files.ensureCapacity(self.gpa, self.failed_files.items().len + 1); | 2955 | try self.failed_files.ensureCapacity(self.gpa, self.failed_files.items().len + 1); |
| 2968 | } | 2956 | } |
| 2969 | switch (scope.tag) { | 2957 | switch (scope.tag) { |
| ... | @@ -2971,7 +2959,7 @@ fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Com | ... | @@ -2971,7 +2959,7 @@ fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Com |
| 2971 | const decl = scope.cast(Scope.DeclAnalysis).?.decl; | 2959 | const decl = scope.cast(Scope.DeclAnalysis).?.decl; |
| 2972 | decl.analysis = .sema_failure; | 2960 | decl.analysis = .sema_failure; |
| 2973 | decl.generation = self.generation; | 2961 | decl.generation = self.generation; |
| 2974 | try self.addDeclErr(decl, err_msg); | 2962 | self.failed_decls.putAssumeCapacityNoClobber(decl, err_msg); |
| 2975 | }, | 2963 | }, |
| 2976 | .block => { | 2964 | .block => { |
| 2977 | const block = scope.cast(Scope.Block).?; | 2965 | const block = scope.cast(Scope.Block).?; |
| ... | @@ -2981,25 +2969,25 @@ fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Com | ... | @@ -2981,25 +2969,25 @@ fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *Com |
| 2981 | block.decl.analysis = .sema_failure; | 2969 | block.decl.analysis = .sema_failure; |
| 2982 | block.decl.generation = self.generation; | 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 | .gen_zir => { | 2974 | .gen_zir => { |
| 2987 | const gen_zir = scope.cast(Scope.GenZIR).?; | 2975 | const gen_zir = scope.cast(Scope.GenZIR).?; |
| 2988 | gen_zir.decl.analysis = .sema_failure; | 2976 | gen_zir.decl.analysis = .sema_failure; |
| 2989 | gen_zir.decl.generation = self.generation; | 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 | .local_val => { | 2980 | .local_val => { |
| 2993 | const gen_zir = scope.cast(Scope.LocalVal).?.gen_zir; | 2981 | const gen_zir = scope.cast(Scope.LocalVal).?.gen_zir; |
| 2994 | gen_zir.decl.analysis = .sema_failure; | 2982 | gen_zir.decl.analysis = .sema_failure; |
| 2995 | gen_zir.decl.generation = self.generation; | 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 | .local_ptr => { | 2986 | .local_ptr => { |
| 2999 | const gen_zir = scope.cast(Scope.LocalPtr).?.gen_zir; | 2987 | const gen_zir = scope.cast(Scope.LocalPtr).?.gen_zir; |
| 3000 | gen_zir.decl.analysis = .sema_failure; | 2988 | gen_zir.decl.analysis = .sema_failure; |
| 3001 | gen_zir.decl.generation = self.generation; | 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 | .zir_module => { | 2992 | .zir_module => { |
| 3005 | const zir_module = scope.cast(Scope.ZIRModule).?; | 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,17 +2333,6 @@ fn compileError(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinCall) InnerE |
| 2333 | return addZIRUnOp(mod, scope, src, .compileerror, target); | 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 | fn typeOf(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst { | 2336 | fn typeOf(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.BuiltinCall) InnerError!*zir.Inst { |
| 2348 | const tree = scope.tree(); | 2337 | const tree = scope.tree(); |
| 2349 | const arena = scope.arena(); | 2338 | const arena = scope.arena(); |
| ... | @@ -2389,8 +2378,6 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built | ... | @@ -2389,8 +2378,6 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built |
| 2389 | return rlWrap(mod, scope, rl, try import(mod, scope, call)); | 2378 | return rlWrap(mod, scope, rl, try import(mod, scope, call)); |
| 2390 | } else if (mem.eql(u8, builtin_name, "@compileError")) { | 2379 | } else if (mem.eql(u8, builtin_name, "@compileError")) { |
| 2391 | return compileError(mod, scope, call); | 2380 | return compileError(mod, scope, call); |
| 2392 | } else if (mem.eql(u8, builtin_name, "@compileLog")) { | ||
| 2393 | return compileLog(mod, scope, call); | ||
| 2394 | } else { | 2381 | } else { |
| 2395 | return mod.failTok(scope, call.builtin_token, "invalid builtin function: '{}'", .{builtin_name}); | 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,7 +106,7 @@ pub fn generateHeader( |
| 106 | const writer = header.buf.writer(); | 106 | const writer = header.buf.writer(); |
| 107 | renderFunctionSignature(&ctx, header, writer, decl) catch |err| { | 107 | renderFunctionSignature(&ctx, header, writer, decl) catch |err| { |
| 108 | if (err == error.AnalysisFail) { | 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 | return err; | 111 | return err; |
| 112 | }; | 112 | }; |
src/link/C.zig+1-1| ... | @@ -106,7 +106,7 @@ pub fn deinit(self: *C) void { | ... | @@ -106,7 +106,7 @@ pub fn deinit(self: *C) void { |
| 106 | pub fn updateDecl(self: *C, module: *Module, decl: *Module.Decl) !void { | 106 | pub fn updateDecl(self: *C, module: *Module, decl: *Module.Decl) !void { |
| 107 | codegen.generate(self, decl) catch |err| { | 107 | codegen.generate(self, decl) catch |err| { |
| 108 | if (err == error.AnalysisFail) { | 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 | return err; | 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,7 +658,7 @@ pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void { |
| 658 | .appended => code_buffer.items, | 658 | .appended => code_buffer.items, |
| 659 | .fail => |em| { | 659 | .fail => |em| { |
| 660 | decl.analysis = .codegen_failure; | 660 | decl.analysis = .codegen_failure; |
| 661 | try module.addDeclErr(decl, em); | 661 | try module.failed_decls.put(module.gpa, decl, em); |
| 662 | return; | 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,7 +2248,7 @@ pub fn updateDecl(self: *Elf, module: *Module, decl: *Module.Decl) !void { |
| 2248 | .appended => code_buffer.items, | 2248 | .appended => code_buffer.items, |
| 2249 | .fail => |em| { | 2249 | .fail => |em| { |
| 2250 | decl.analysis = .codegen_failure; | 2250 | decl.analysis = .codegen_failure; |
| 2251 | try module.addDeclErr(decl, em); | 2251 | try module.failed_decls.put(module.gpa, decl, em); |
| 2252 | return; | 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,7 +1062,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void { |
| 1062 | .appended => code_buffer.items, | 1062 | .appended => code_buffer.items, |
| 1063 | .fail => |em| { | 1063 | .fail => |em| { |
| 1064 | decl.analysis = .codegen_failure; | 1064 | decl.analysis = .codegen_failure; |
| 1065 | try module.addDeclErr(decl, em); | 1065 | try module.failed_decls.put(module.gpa, decl, em); |
| 1066 | return; | 1066 | return; |
| 1067 | }, | 1067 | }, |
| 1068 | }; | 1068 | }; |
src/value.zig+1-1| ... | @@ -350,7 +350,7 @@ pub const Value = extern union { | ... | @@ -350,7 +350,7 @@ pub const Value = extern union { |
| 350 | val = elem_ptr.array_ptr; | 350 | val = elem_ptr.array_ptr; |
| 351 | }, | 351 | }, |
| 352 | .empty_array => return out_stream.writeAll(".{}"), | 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 | .bytes => return out_stream.print("\"{Z}\"", .{self.cast(Payload.Bytes).?.data}), | 354 | .bytes => return out_stream.print("\"{Z}\"", .{self.cast(Payload.Bytes).?.data}), |
| 355 | .repeated => { | 355 | .repeated => { |
| 356 | try out_stream.writeAll("(repeated) "); | 356 | try out_stream.writeAll("(repeated) "); |
src/zir.zig+4-21| ... | @@ -126,8 +126,6 @@ pub const Inst = struct { | ... | @@ -126,8 +126,6 @@ pub const Inst = struct { |
| 126 | coerce_to_ptr_elem, | 126 | coerce_to_ptr_elem, |
| 127 | /// Emit an error message and fail compilation. | 127 | /// Emit an error message and fail compilation. |
| 128 | compileerror, | 128 | compileerror, |
| 129 | /// Log compile time variables and emit an error message. | ||
| 130 | compilelog, | ||
| 131 | /// Conditional branch. Splits control flow based on a boolean condition value. | 129 | /// Conditional branch. Splits control flow based on a boolean condition value. |
| 132 | condbr, | 130 | condbr, |
| 133 | /// Special case, has no textual representation. | 131 | /// Special case, has no textual representation. |
| ... | @@ -394,7 +392,6 @@ pub const Inst = struct { | ... | @@ -394,7 +392,6 @@ pub const Inst = struct { |
| 394 | .declval => DeclVal, | 392 | .declval => DeclVal, |
| 395 | .declval_in_module => DeclValInModule, | 393 | .declval_in_module => DeclValInModule, |
| 396 | .coerce_result_block_ptr => CoerceResultBlockPtr, | 394 | .coerce_result_block_ptr => CoerceResultBlockPtr, |
| 397 | .compilelog => CompileLog, | ||
| 398 | .loop => Loop, | 395 | .loop => Loop, |
| 399 | .@"const" => Const, | 396 | .@"const" => Const, |
| 400 | .str => Str, | 397 | .str => Str, |
| ... | @@ -524,7 +521,6 @@ pub const Inst = struct { | ... | @@ -524,7 +521,6 @@ pub const Inst = struct { |
| 524 | .slice_start, | 521 | .slice_start, |
| 525 | .import, | 522 | .import, |
| 526 | .switch_range, | 523 | .switch_range, |
| 527 | .compilelog, | ||
| 528 | .typeof_peer, | 524 | .typeof_peer, |
| 529 | => false, | 525 | => false, |
| 530 | 526 | ||
| ... | @@ -709,19 +705,6 @@ pub const Inst = struct { | ... | @@ -709,19 +705,6 @@ pub const Inst = struct { |
| 709 | kw_args: struct {}, | 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 | pub const Const = struct { | 708 | pub const Const = struct { |
| 726 | pub const base_tag = Tag.@"const"; | 709 | pub const base_tag = Tag.@"const"; |
| 727 | base: Inst, | 710 | base: Inst, |
| ... | @@ -1940,7 +1923,7 @@ const EmitZIR = struct { | ... | @@ -1940,7 +1923,7 @@ const EmitZIR = struct { |
| 1940 | .sema_failure, | 1923 | .sema_failure, |
| 1941 | .sema_failure_retryable, | 1924 | .sema_failure_retryable, |
| 1942 | .dependency_failure, | 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 | const fail_inst = try self.arena.allocator.create(Inst.UnOp); | 1927 | const fail_inst = try self.arena.allocator.create(Inst.UnOp); |
| 1945 | fail_inst.* = .{ | 1928 | fail_inst.* = .{ |
| 1946 | .base = .{ | 1929 | .base = .{ |
| ... | @@ -1949,7 +1932,7 @@ const EmitZIR = struct { | ... | @@ -1949,7 +1932,7 @@ const EmitZIR = struct { |
| 1949 | }, | 1932 | }, |
| 1950 | .positionals = .{ | 1933 | .positionals = .{ |
| 1951 | .operand = blk: { | 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 | const str_inst = try self.arena.allocator.create(Inst.Str); | 1937 | const str_inst = try self.arena.allocator.create(Inst.Str); |
| 1955 | str_inst.* = .{ | 1938 | str_inst.* = .{ |
| ... | @@ -1958,7 +1941,7 @@ const EmitZIR = struct { | ... | @@ -1958,7 +1941,7 @@ const EmitZIR = struct { |
| 1958 | .tag = Inst.Str.base_tag, | 1941 | .tag = Inst.Str.base_tag, |
| 1959 | }, | 1942 | }, |
| 1960 | .positionals = .{ | 1943 | .positionals = .{ |
| 1961 | .bytes = msg_str, | 1944 | .bytes = err_msg.msg, |
| 1962 | }, | 1945 | }, |
| 1963 | .kw_args = .{}, | 1946 | .kw_args = .{}, |
| 1964 | }; | 1947 | }; |
| ... | @@ -2085,7 +2068,7 @@ const EmitZIR = struct { | ... | @@ -2085,7 +2068,7 @@ const EmitZIR = struct { |
| 2085 | try self.emitBody(body, &inst_table, &instructions); | 2068 | try self.emitBody(body, &inst_table, &instructions); |
| 2086 | }, | 2069 | }, |
| 2087 | .sema_failure => { | 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 | const fail_inst = try self.arena.allocator.create(Inst.UnOp); | 2072 | const fail_inst = try self.arena.allocator.create(Inst.UnOp); |
| 2090 | fail_inst.* = .{ | 2073 | fail_inst.* = .{ |
| 2091 | .base = .{ | 2074 | .base = .{ |
src/zir_sema.zig-23| ... | @@ -45,7 +45,6 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! | ... | @@ -45,7 +45,6 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! |
| 45 | .coerce_result_ptr => return analyzeInstCoerceResultPtr(mod, scope, old_inst.castTag(.coerce_result_ptr).?), | 45 | .coerce_result_ptr => return analyzeInstCoerceResultPtr(mod, scope, old_inst.castTag(.coerce_result_ptr).?), |
| 46 | .coerce_to_ptr_elem => return analyzeInstCoerceToPtrElem(mod, scope, old_inst.castTag(.coerce_to_ptr_elem).?), | 46 | .coerce_to_ptr_elem => return analyzeInstCoerceToPtrElem(mod, scope, old_inst.castTag(.coerce_to_ptr_elem).?), |
| 47 | .compileerror => return analyzeInstCompileError(mod, scope, old_inst.castTag(.compileerror).?), | 47 | .compileerror => return analyzeInstCompileError(mod, scope, old_inst.castTag(.compileerror).?), |
| 48 | .compilelog => return analyzeInstCompileLog(mod, scope, old_inst.castTag(.compilelog).?), | ||
| 49 | .@"const" => return analyzeInstConst(mod, scope, old_inst.castTag(.@"const").?), | 48 | .@"const" => return analyzeInstConst(mod, scope, old_inst.castTag(.@"const").?), |
| 50 | .dbg_stmt => return analyzeInstDbgStmt(mod, scope, old_inst.castTag(.dbg_stmt).?), | 49 | .dbg_stmt => return analyzeInstDbgStmt(mod, scope, old_inst.castTag(.dbg_stmt).?), |
| 51 | .declref => return analyzeInstDeclRef(mod, scope, old_inst.castTag(.declref).?), | 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,28 +502,6 @@ fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) In |
| 503 | return mod.fail(scope, inst.base.src, "{}", .{msg}); | 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 | fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst { | 505 | fn analyzeInstArg(mod: *Module, scope: *Scope, inst: *zir.Inst.Arg) InnerError!*Inst { |
| 529 | const b = try mod.requireRuntimeBlock(scope, inst.base.src); | 506 | const b = try mod.requireRuntimeBlock(scope, inst.base.src); |
| 530 | const fn_ty = b.func.?.owner_decl.typed_value.most_recent.typed_value.ty; | 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,27 +1171,13 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1171 | \\fn entry() void {} | 1171 | \\fn entry() void {} |
| 1172 | , &[_][]const u8{":2:4: error: redefinition of 'entry'"}); | 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 | ctx.compileError("compileError", linux_x64, | 1174 | ctx.compileError("compileError", linux_x64, |
| 1190 | \\export fn _start() noreturn { | 1175 | \\export fn _start() noreturn { |
| 1191 | \\ @compileError("this is an error"); | 1176 | \\ @compileError("this is an error"); |
| 1192 | \\ unreachable; | 1177 | \\ unreachable; |
| 1193 | \\} | 1178 | \\} |
| 1194 | , &[_][]const u8{":2:3: error: this is an error"}); | 1179 | , &[_][]const u8{":2:3: error: this is an error"}); |
| 1180 | |||
| 1195 | { | 1181 | { |
| 1196 | var case = ctx.obj("variable shadowing", linux_x64); | 1182 | var case = ctx.obj("variable shadowing", linux_x64); |
| 1197 | case.addError( | 1183 | case.addError( |