mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
Zcu: key compile errors on AnalUnit
where appropriate
This change seeks to more appropriately model the way semantic analysis works by drawing a more clear line between errors emitted by analyzing a `Decl` (in future a `Cau`) and errors emitted by analyzing a runtime function. This does change a few compile errors surrounding compile logs by adding more "also here" notes. The new notes are more technically correct, but perhaps not so helpful. They're not doing enough harm for me to put extensive thought into this for now.
This commit is contained in:
parent
7e552dc1e9
commit
5f03c02505
@ -2831,11 +2831,11 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
|
||||
}
|
||||
}
|
||||
|
||||
if (comp.module) |module| {
|
||||
total += module.failed_exports.count();
|
||||
total += module.failed_embed_files.count();
|
||||
if (comp.module) |zcu| {
|
||||
total += zcu.failed_exports.count();
|
||||
total += zcu.failed_embed_files.count();
|
||||
|
||||
for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| {
|
||||
for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {
|
||||
if (error_msg) |_| {
|
||||
total += 1;
|
||||
} else {
|
||||
@ -2851,23 +2851,27 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
|
||||
// When a parse error is introduced, we keep all the semantic analysis for
|
||||
// the previous parse success, including compile errors, but we cannot
|
||||
// emit them until the file succeeds parsing.
|
||||
for (module.failed_decls.keys()) |key| {
|
||||
if (module.declFileScope(key).okToReportErrors()) {
|
||||
for (zcu.failed_analysis.keys()) |key| {
|
||||
const decl_index = switch (key.unwrap()) {
|
||||
.decl => |d| d,
|
||||
.func => |ip_index| zcu.funcInfo(ip_index).owner_decl,
|
||||
};
|
||||
if (zcu.declFileScope(decl_index).okToReportErrors()) {
|
||||
total += 1;
|
||||
if (module.cimport_errors.get(key)) |errors| {
|
||||
if (zcu.cimport_errors.get(key)) |errors| {
|
||||
total += errors.errorMessageCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (module.emit_h) |emit_h| {
|
||||
if (zcu.emit_h) |emit_h| {
|
||||
for (emit_h.failed_decls.keys()) |key| {
|
||||
if (module.declFileScope(key).okToReportErrors()) {
|
||||
if (zcu.declFileScope(key).okToReportErrors()) {
|
||||
total += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (module.global_error_set.entries.len - 1 > module.error_limit) {
|
||||
if (zcu.global_error_set.entries.len - 1 > zcu.error_limit) {
|
||||
total += 1;
|
||||
}
|
||||
}
|
||||
@ -2882,8 +2886,8 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
|
||||
|
||||
// Compile log errors only count if there are no other errors.
|
||||
if (total == 0) {
|
||||
if (comp.module) |module| {
|
||||
total += @intFromBool(module.compile_log_decls.count() != 0);
|
||||
if (comp.module) |zcu| {
|
||||
total += @intFromBool(zcu.compile_log_sources.count() != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2934,10 +2938,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
|
||||
.msg = try bundle.addString("memory allocation failure"),
|
||||
});
|
||||
}
|
||||
if (comp.module) |module| {
|
||||
for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| {
|
||||
if (comp.module) |zcu| {
|
||||
for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {
|
||||
if (error_msg) |msg| {
|
||||
try addModuleErrorMsg(module, &bundle, msg.*);
|
||||
try addModuleErrorMsg(zcu, &bundle, msg.*);
|
||||
} else {
|
||||
// Must be ZIR errors. Note that this may include AST errors.
|
||||
// addZirErrorMessages asserts that the tree is loaded.
|
||||
@ -2945,54 +2949,59 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
|
||||
try addZirErrorMessages(&bundle, file);
|
||||
}
|
||||
}
|
||||
for (module.failed_embed_files.values()) |error_msg| {
|
||||
try addModuleErrorMsg(module, &bundle, error_msg.*);
|
||||
for (zcu.failed_embed_files.values()) |error_msg| {
|
||||
try addModuleErrorMsg(zcu, &bundle, error_msg.*);
|
||||
}
|
||||
for (module.failed_decls.keys(), module.failed_decls.values()) |decl_index, error_msg| {
|
||||
for (zcu.failed_analysis.keys(), zcu.failed_analysis.values()) |anal_unit, error_msg| {
|
||||
const decl_index = switch (anal_unit.unwrap()) {
|
||||
.decl => |d| d,
|
||||
.func => |ip_index| zcu.funcInfo(ip_index).owner_decl,
|
||||
};
|
||||
|
||||
// Skip errors for Decls within files that had a parse failure.
|
||||
// We'll try again once parsing succeeds.
|
||||
if (module.declFileScope(decl_index).okToReportErrors()) {
|
||||
try addModuleErrorMsg(module, &bundle, error_msg.*);
|
||||
if (module.cimport_errors.get(decl_index)) |errors| {
|
||||
for (errors.getMessages()) |err_msg_index| {
|
||||
const err_msg = errors.getErrorMessage(err_msg_index);
|
||||
try bundle.addRootErrorMessage(.{
|
||||
.msg = try bundle.addString(errors.nullTerminatedString(err_msg.msg)),
|
||||
.src_loc = if (err_msg.src_loc != .none) blk: {
|
||||
const src_loc = errors.getSourceLocation(err_msg.src_loc);
|
||||
break :blk try bundle.addSourceLocation(.{
|
||||
.src_path = try bundle.addString(errors.nullTerminatedString(src_loc.src_path)),
|
||||
.span_start = src_loc.span_start,
|
||||
.span_main = src_loc.span_main,
|
||||
.span_end = src_loc.span_end,
|
||||
.line = src_loc.line,
|
||||
.column = src_loc.column,
|
||||
.source_line = if (src_loc.source_line != 0) try bundle.addString(errors.nullTerminatedString(src_loc.source_line)) else 0,
|
||||
});
|
||||
} else .none,
|
||||
});
|
||||
}
|
||||
if (!zcu.declFileScope(decl_index).okToReportErrors()) continue;
|
||||
|
||||
try addModuleErrorMsg(zcu, &bundle, error_msg.*);
|
||||
if (zcu.cimport_errors.get(anal_unit)) |errors| {
|
||||
for (errors.getMessages()) |err_msg_index| {
|
||||
const err_msg = errors.getErrorMessage(err_msg_index);
|
||||
try bundle.addRootErrorMessage(.{
|
||||
.msg = try bundle.addString(errors.nullTerminatedString(err_msg.msg)),
|
||||
.src_loc = if (err_msg.src_loc != .none) blk: {
|
||||
const src_loc = errors.getSourceLocation(err_msg.src_loc);
|
||||
break :blk try bundle.addSourceLocation(.{
|
||||
.src_path = try bundle.addString(errors.nullTerminatedString(src_loc.src_path)),
|
||||
.span_start = src_loc.span_start,
|
||||
.span_main = src_loc.span_main,
|
||||
.span_end = src_loc.span_end,
|
||||
.line = src_loc.line,
|
||||
.column = src_loc.column,
|
||||
.source_line = if (src_loc.source_line != 0) try bundle.addString(errors.nullTerminatedString(src_loc.source_line)) else 0,
|
||||
});
|
||||
} else .none,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (module.emit_h) |emit_h| {
|
||||
if (zcu.emit_h) |emit_h| {
|
||||
for (emit_h.failed_decls.keys(), emit_h.failed_decls.values()) |decl_index, error_msg| {
|
||||
// Skip errors for Decls within files that had a parse failure.
|
||||
// We'll try again once parsing succeeds.
|
||||
if (module.declFileScope(decl_index).okToReportErrors()) {
|
||||
try addModuleErrorMsg(module, &bundle, error_msg.*);
|
||||
if (zcu.declFileScope(decl_index).okToReportErrors()) {
|
||||
try addModuleErrorMsg(zcu, &bundle, error_msg.*);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (module.failed_exports.values()) |value| {
|
||||
try addModuleErrorMsg(module, &bundle, value.*);
|
||||
for (zcu.failed_exports.values()) |value| {
|
||||
try addModuleErrorMsg(zcu, &bundle, value.*);
|
||||
}
|
||||
|
||||
const actual_error_count = module.global_error_set.entries.len - 1;
|
||||
if (actual_error_count > module.error_limit) {
|
||||
const actual_error_count = zcu.global_error_set.entries.len - 1;
|
||||
if (actual_error_count > zcu.error_limit) {
|
||||
try bundle.addRootErrorMessage(.{
|
||||
.msg = try bundle.printString("module used more errors than possible: used {d}, max {d}", .{
|
||||
actual_error_count, module.error_limit,
|
||||
.msg = try bundle.printString("ZCU used more errors than possible: used {d}, max {d}", .{
|
||||
actual_error_count, zcu.error_limit,
|
||||
}),
|
||||
.notes_len = 1,
|
||||
});
|
||||
@ -3041,14 +3050,14 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
|
||||
}
|
||||
|
||||
if (comp.module) |zcu| {
|
||||
if (bundle.root_list.items.len == 0 and zcu.compile_log_decls.count() != 0) {
|
||||
const values = zcu.compile_log_decls.values();
|
||||
if (bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {
|
||||
const values = zcu.compile_log_sources.values();
|
||||
// First one will be the error; subsequent ones will be notes.
|
||||
const src_loc = values[0].src().upgrade(zcu);
|
||||
const err_msg: Module.ErrorMsg = .{
|
||||
.src_loc = src_loc,
|
||||
.msg = "found compile log statement",
|
||||
.notes = try gpa.alloc(Module.ErrorMsg, zcu.compile_log_decls.count() - 1),
|
||||
.notes = try gpa.alloc(Module.ErrorMsg, zcu.compile_log_sources.count() - 1),
|
||||
};
|
||||
defer gpa.free(err_msg.notes);
|
||||
|
||||
@ -3486,13 +3495,16 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
|
||||
const decl = module.declPtr(decl_index);
|
||||
const lf = comp.bin_file.?;
|
||||
lf.updateDeclLineNumber(module, decl_index) catch |err| {
|
||||
try module.failed_decls.ensureUnusedCapacity(gpa, 1);
|
||||
module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
|
||||
gpa,
|
||||
decl.navSrcLoc(module).upgrade(module),
|
||||
"unable to update line number: {s}",
|
||||
.{@errorName(err)},
|
||||
));
|
||||
try module.failed_analysis.ensureUnusedCapacity(gpa, 1);
|
||||
module.failed_analysis.putAssumeCapacityNoClobber(
|
||||
InternPool.AnalUnit.wrap(.{ .decl = decl_index }),
|
||||
try Module.ErrorMsg.create(
|
||||
gpa,
|
||||
decl.navSrcLoc(module).upgrade(module),
|
||||
"unable to update line number: {s}",
|
||||
.{@errorName(err)},
|
||||
),
|
||||
);
|
||||
decl.analysis = .codegen_failure;
|
||||
try module.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
|
||||
};
|
||||
|
27
src/Sema.zig
27
src/Sema.zig
@ -2486,7 +2486,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
|
||||
crash_report.compilerPanic("unexpected compile error occurred", null, null);
|
||||
}
|
||||
|
||||
try mod.failed_decls.ensureUnusedCapacity(gpa, 1);
|
||||
try mod.failed_analysis.ensureUnusedCapacity(gpa, 1);
|
||||
try mod.failed_files.ensureUnusedCapacity(gpa, 1);
|
||||
|
||||
if (block) |start_block| {
|
||||
@ -2504,7 +2504,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
|
||||
const max_references = refs: {
|
||||
if (mod.comp.reference_trace) |num| break :refs num;
|
||||
// Do not add multiple traces without explicit request.
|
||||
if (mod.failed_decls.count() > 0) break :ref;
|
||||
if (mod.failed_analysis.count() > 0) break :ref;
|
||||
break :refs default_reference_trace_len;
|
||||
};
|
||||
|
||||
@ -2544,7 +2544,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
|
||||
if (sema.func_index != .none) {
|
||||
ip.funcAnalysis(sema.func_index).state = .sema_failure;
|
||||
}
|
||||
const gop = mod.failed_decls.getOrPutAssumeCapacity(sema.owner_decl_index);
|
||||
const gop = mod.failed_analysis.getOrPutAssumeCapacity(sema.ownerUnit());
|
||||
if (gop.found_existing) {
|
||||
// If there are multiple errors for the same Decl, prefer the first one added.
|
||||
sema.err = null;
|
||||
@ -5823,11 +5823,7 @@ fn zirCompileLog(
|
||||
}
|
||||
try writer.print("\n", .{});
|
||||
|
||||
const decl_index = if (sema.func_index != .none)
|
||||
mod.funcOwnerDeclIndex(sema.func_index)
|
||||
else
|
||||
sema.owner_decl_index;
|
||||
const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);
|
||||
const gop = try mod.compile_log_sources.getOrPut(sema.gpa, sema.ownerUnit());
|
||||
if (!gop.found_existing) gop.value_ptr.* = .{
|
||||
.base_node_inst = block.src_base_inst,
|
||||
.node_offset = src_node,
|
||||
@ -5980,7 +5976,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
|
||||
if (!comp.config.link_libc)
|
||||
try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{});
|
||||
|
||||
const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index);
|
||||
const gop = try mod.cimport_errors.getOrPut(gpa, sema.ownerUnit());
|
||||
if (!gop.found_existing) {
|
||||
gop.value_ptr.* = c_import_res.errors;
|
||||
c_import_res.errors = std.zig.ErrorBundle.empty;
|
||||
@ -38487,10 +38483,7 @@ pub fn flushExports(sema: *Sema) !void {
|
||||
const zcu = sema.mod;
|
||||
const gpa = zcu.gpa;
|
||||
|
||||
const unit: AnalUnit = if (sema.owner_func_index != .none)
|
||||
AnalUnit.wrap(.{ .func = sema.owner_func_index })
|
||||
else
|
||||
AnalUnit.wrap(.{ .decl = sema.owner_decl_index });
|
||||
const unit = sema.ownerUnit();
|
||||
|
||||
// There may be existing exports. For instance, a struct may export
|
||||
// things during both field type resolution and field default resolution.
|
||||
@ -38524,6 +38517,14 @@ pub fn flushExports(sema: *Sema) !void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ownerUnit(sema: Sema) AnalUnit {
|
||||
if (sema.owner_func_index != .none) {
|
||||
return AnalUnit.wrap(.{ .func = sema.owner_func_index });
|
||||
} else {
|
||||
return AnalUnit.wrap(.{ .decl = sema.owner_decl_index });
|
||||
}
|
||||
}
|
||||
|
||||
pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;
|
||||
pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice;
|
||||
|
||||
|
52
src/Zcu.zig
52
src/Zcu.zig
@ -108,15 +108,11 @@ embed_table: std.StringArrayHashMapUnmanaged(*EmbedFile) = .{},
|
||||
/// is not yet implemented.
|
||||
intern_pool: InternPool = .{},
|
||||
|
||||
/// We optimize memory usage for a compilation with no compile errors by storing the
|
||||
/// error messages and mapping outside of `Decl`.
|
||||
/// The ErrorMsg memory is owned by the decl, using Module's general purpose allocator.
|
||||
/// Note that a Decl can succeed but the Fn it represents can fail. In this case,
|
||||
/// a Decl can have a failed_decls entry but have analysis status of success.
|
||||
failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{},
|
||||
/// Keep track of one `@compileLog` callsite per owner Decl.
|
||||
/// The ErrorMsg memory is owned by the `AnalUnit`, using Module's general purpose allocator.
|
||||
failed_analysis: std.AutoArrayHashMapUnmanaged(AnalUnit, *ErrorMsg) = .{},
|
||||
/// Keep track of one `@compileLog` callsite per `AnalUnit`.
|
||||
/// The value is the source location of the `@compileLog` call, convertible to a `LazySrcLoc`.
|
||||
compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, extern struct {
|
||||
compile_log_sources: std.AutoArrayHashMapUnmanaged(AnalUnit, extern struct {
|
||||
base_node_inst: InternPool.TrackedInst.Index,
|
||||
node_offset: i32,
|
||||
pub fn src(self: @This()) LazySrcLoc {
|
||||
@ -133,9 +129,9 @@ failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},
|
||||
failed_embed_files: std.AutoArrayHashMapUnmanaged(*EmbedFile, *ErrorMsg) = .{},
|
||||
/// Key is index into `all_exports`.
|
||||
failed_exports: std.AutoArrayHashMapUnmanaged(u32, *ErrorMsg) = .{},
|
||||
/// If a decl failed due to a cimport error, the corresponding Clang errors
|
||||
/// If analysis failed due to a cimport error, the corresponding Clang errors
|
||||
/// are stored here.
|
||||
cimport_errors: std.AutoArrayHashMapUnmanaged(Decl.Index, std.zig.ErrorBundle) = .{},
|
||||
cimport_errors: std.AutoArrayHashMapUnmanaged(AnalUnit, std.zig.ErrorBundle) = .{},
|
||||
|
||||
/// Key is the error name, index is the error tag value. Index 0 has a length-0 string.
|
||||
global_error_set: GlobalErrorSet = .{},
|
||||
@ -180,6 +176,7 @@ emit_h: ?*GlobalEmitH,
|
||||
|
||||
test_functions: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{},
|
||||
|
||||
/// TODO: the key here will be a `Cau.Index`.
|
||||
global_assembly: std.AutoArrayHashMapUnmanaged(Decl.Index, []u8) = .{},
|
||||
|
||||
reference_table: std.AutoHashMapUnmanaged(Decl.Index, struct {
|
||||
@ -371,9 +368,9 @@ pub const Decl = struct {
|
||||
/// successfully complete semantic analysis.
|
||||
dependency_failure,
|
||||
/// Semantic analysis failure.
|
||||
/// There will be a corresponding ErrorMsg in Zcu.failed_decls.
|
||||
/// There will be a corresponding ErrorMsg in Zcu.failed_analysis.
|
||||
sema_failure,
|
||||
/// There will be a corresponding ErrorMsg in Zcu.failed_decls.
|
||||
/// There will be a corresponding ErrorMsg in Zcu.failed_analysis.
|
||||
codegen_failure,
|
||||
/// Sematic analysis and constant value codegen of this Decl has
|
||||
/// succeeded. However, the Decl may be outdated due to an in-progress
|
||||
@ -1001,11 +998,6 @@ pub const EmbedFile = struct {
|
||||
/// This struct holds data necessary to construct API-facing `AllErrors.Message`.
|
||||
/// Its memory is managed with the general purpose allocator so that they
|
||||
/// can be created and destroyed in response to incremental updates.
|
||||
/// In some cases, the File could have been inferred from where the ErrorMsg
|
||||
/// is stored. For example, if it is stored in Module.failed_decls, then the File
|
||||
/// would be determined by the Decl Scope. However, the data structure contains the field
|
||||
/// anyway so that `ErrorMsg` can be reused for error notes, which may be in a different
|
||||
/// file than the parent error message. It also simplifies processing of error messages.
|
||||
pub const ErrorMsg = struct {
|
||||
src_loc: SrcLoc,
|
||||
msg: []const u8,
|
||||
@ -2454,8 +2446,6 @@ pub fn deinit(zcu: *Zcu) void {
|
||||
for (zcu.import_table.keys()) |key| {
|
||||
gpa.free(key);
|
||||
}
|
||||
var failed_decls = zcu.failed_decls;
|
||||
zcu.failed_decls = .{};
|
||||
for (zcu.import_table.values()) |value| {
|
||||
value.destroy(zcu);
|
||||
}
|
||||
@ -2473,10 +2463,10 @@ pub fn deinit(zcu: *Zcu) void {
|
||||
zcu.local_zir_cache.handle.close();
|
||||
zcu.global_zir_cache.handle.close();
|
||||
|
||||
for (failed_decls.values()) |value| {
|
||||
for (zcu.failed_analysis.values()) |value| {
|
||||
value.destroy(gpa);
|
||||
}
|
||||
failed_decls.deinit(gpa);
|
||||
zcu.failed_analysis.deinit(gpa);
|
||||
|
||||
if (zcu.emit_h) |emit_h| {
|
||||
for (emit_h.failed_decls.values()) |value| {
|
||||
@ -2507,7 +2497,7 @@ pub fn deinit(zcu: *Zcu) void {
|
||||
}
|
||||
zcu.cimport_errors.deinit(gpa);
|
||||
|
||||
zcu.compile_log_decls.deinit(gpa);
|
||||
zcu.compile_log_sources.deinit(gpa);
|
||||
|
||||
zcu.all_exports.deinit(gpa);
|
||||
zcu.free_exports.deinit(gpa);
|
||||
@ -3508,9 +3498,9 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
|
||||
error.GenericPoison => unreachable,
|
||||
else => |e| {
|
||||
decl.analysis = .sema_failure;
|
||||
try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1);
|
||||
try mod.failed_analysis.ensureUnusedCapacity(mod.gpa, 1);
|
||||
try mod.retryable_failures.append(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }));
|
||||
mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
|
||||
mod.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(
|
||||
mod.gpa,
|
||||
decl.navSrcLoc(mod).upgrade(mod),
|
||||
"unable to analyze: {s}",
|
||||
@ -3683,9 +3673,9 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
|
||||
verify.verify() catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
else => {
|
||||
try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
|
||||
zcu.failed_decls.putAssumeCapacityNoClobber(
|
||||
decl_index,
|
||||
try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
|
||||
zcu.failed_analysis.putAssumeCapacityNoClobber(
|
||||
AnalUnit.wrap(.{ .decl = decl_index }),
|
||||
try Module.ErrorMsg.create(
|
||||
gpa,
|
||||
decl.navSrcLoc(zcu).upgrade(zcu),
|
||||
@ -3709,8 +3699,8 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
|
||||
func.analysis(ip).state = .codegen_failure;
|
||||
},
|
||||
else => {
|
||||
try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
|
||||
zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
|
||||
try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
|
||||
zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try Module.ErrorMsg.create(
|
||||
gpa,
|
||||
decl.navSrcLoc(zcu).upgrade(zcu),
|
||||
"unable to codegen: {s}",
|
||||
@ -5647,8 +5637,8 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
|
||||
},
|
||||
else => {
|
||||
const gpa = zcu.gpa;
|
||||
try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
|
||||
zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
|
||||
try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
|
||||
zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(
|
||||
gpa,
|
||||
decl.navSrcLoc(zcu).upgrade(zcu),
|
||||
"unable to codegen: {s}",
|
||||
|
@ -1689,7 +1689,7 @@ pub const Object = struct {
|
||||
fg.genBody(air.getMainBody()) catch |err| switch (err) {
|
||||
error.CodegenFail => {
|
||||
decl.analysis = .codegen_failure;
|
||||
try zcu.failed_decls.put(zcu.gpa, decl_index, dg.err_msg.?);
|
||||
try zcu.failed_analysis.put(zcu.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), dg.err_msg.?);
|
||||
dg.err_msg = null;
|
||||
return;
|
||||
},
|
||||
@ -1710,7 +1710,7 @@ pub const Object = struct {
|
||||
dg.genDecl() catch |err| switch (err) {
|
||||
error.CodegenFail => {
|
||||
decl.analysis = .codegen_failure;
|
||||
try module.failed_decls.put(module.gpa, decl_index, dg.err_msg.?);
|
||||
try module.failed_analysis.put(module.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), dg.err_msg.?);
|
||||
dg.err_msg = null;
|
||||
return;
|
||||
},
|
||||
|
@ -218,7 +218,7 @@ pub const Object = struct {
|
||||
|
||||
decl_gen.genDecl() catch |err| switch (err) {
|
||||
error.CodegenFail => {
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, decl_gen.error_msg.?);
|
||||
try mod.failed_analysis.put(mod.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), decl_gen.error_msg.?);
|
||||
},
|
||||
else => |other| {
|
||||
// There might be an error that happened *after* self.error_msg
|
||||
|
@ -1155,7 +1155,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
|
||||
.ok => code_buffer.items,
|
||||
.fail => |em| {
|
||||
func.analysis(&mod.intern_pool).state = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -1183,7 +1183,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
|
||||
.ok => |atom_index| atom_index,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
log.err("{s}", .{em.msg});
|
||||
return error.CodegenFail;
|
||||
},
|
||||
@ -1277,7 +1277,7 @@ pub fn updateDecl(
|
||||
.ok => code_buffer.items,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -2751,6 +2751,7 @@ const TableSection = @import("table_section.zig").TableSection;
|
||||
const StringTable = @import("StringTable.zig");
|
||||
const Type = @import("../type.zig").Type;
|
||||
const Value = @import("../Value.zig");
|
||||
const AnalUnit = InternPool.AnalUnit;
|
||||
|
||||
pub const base_tag: link.File.Tag = .coff;
|
||||
|
||||
|
@ -1096,7 +1096,7 @@ pub fn updateFunc(
|
||||
.ok => code_buffer.items,
|
||||
.fail => |em| {
|
||||
func.analysis(&mod.intern_pool).state = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -1170,7 +1170,7 @@ pub fn updateDecl(
|
||||
.ok => code_buffer.items,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -1307,7 +1307,7 @@ pub fn lowerUnnamedConst(
|
||||
.ok => |sym_index| sym_index,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
log.err("{s}", .{em.msg});
|
||||
return error.CodegenFail;
|
||||
},
|
||||
@ -1656,4 +1656,5 @@ const Symbol = @import("Symbol.zig");
|
||||
const StringTable = @import("../StringTable.zig");
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../Value.zig");
|
||||
const AnalUnit = InternPool.AnalUnit;
|
||||
const ZigObject = @This();
|
||||
|
@ -694,7 +694,7 @@ pub fn updateFunc(
|
||||
.ok => code_buffer.items,
|
||||
.fail => |em| {
|
||||
func.analysis(&mod.intern_pool).state = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -762,7 +762,7 @@ pub fn updateDecl(
|
||||
.ok => code_buffer.items,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -1105,7 +1105,7 @@ pub fn lowerUnnamedConst(
|
||||
.ok => |sym_index| sym_index,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
log.err("{s}", .{em.msg});
|
||||
return error.CodegenFail;
|
||||
},
|
||||
@ -1596,4 +1596,5 @@ const Symbol = @import("Symbol.zig");
|
||||
const StringTable = @import("../StringTable.zig");
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../Value.zig");
|
||||
const AnalUnit = InternPool.AnalUnit;
|
||||
const ZigObject = @This();
|
||||
|
@ -17,6 +17,7 @@ const Air = @import("../Air.zig");
|
||||
const Liveness = @import("../Liveness.zig");
|
||||
const Type = @import("../type.zig").Type;
|
||||
const Value = @import("../Value.zig");
|
||||
const AnalUnit = InternPool.AnalUnit;
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
@ -449,7 +450,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
|
||||
.ok => try code_buffer.toOwnedSlice(),
|
||||
.fail => |em| {
|
||||
func.analysis(&mod.intern_pool).state = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -513,7 +514,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
|
||||
.ok => code_buffer.items,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
log.err("{s}", .{em.msg});
|
||||
return error.CodegenFail;
|
||||
},
|
||||
@ -550,7 +551,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
|
||||
.ok => code_buffer.items,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
@ -280,7 +280,7 @@ pub fn updateDecl(
|
||||
.ok => code_writer.items,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -320,7 +320,7 @@ pub fn updateFunc(
|
||||
.ok => code_writer.items,
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return;
|
||||
},
|
||||
};
|
||||
@ -501,7 +501,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
|
||||
},
|
||||
.fail => |em| {
|
||||
decl.analysis = .codegen_failure;
|
||||
try mod.failed_decls.put(mod.gpa, decl_index, em);
|
||||
try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
|
||||
return error.CodegenFail;
|
||||
},
|
||||
}
|
||||
@ -1255,4 +1255,5 @@ const Symbol = @import("Symbol.zig");
|
||||
const Type = @import("../../type.zig").Type;
|
||||
const Value = @import("../../Value.zig");
|
||||
const Wasm = @import("../Wasm.zig");
|
||||
const AnalUnit = InternPool.AnalUnit;
|
||||
const ZigObject = @This();
|
||||
|
@ -16,6 +16,7 @@ pub export fn entry() void {
|
||||
// target=native
|
||||
//
|
||||
// :6:5: error: found compile log statement
|
||||
// :6:5: note: also here
|
||||
//
|
||||
// Compile Log Output:
|
||||
// @as(tmp.Bar, .{ .X = 123 })
|
||||
|
@ -18,6 +18,7 @@ export fn baz() void {
|
||||
//
|
||||
// :6:5: error: found compile log statement
|
||||
// :12:5: note: also here
|
||||
// :6:5: note: also here
|
||||
//
|
||||
// Compile Log Output:
|
||||
// @as(*const [5:0]u8, "begin")
|
||||
|
Loading…
Reference in New Issue
Block a user