aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-01-16 22:51:01 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-01-16 22:51:01 -0700
commit8c9ac4db978c80246b4872c899b1618b1b195ec2 (patch)
treee6bddfb9df54fc6d60518978506e6869c1b2be80 /src/main.zig
parent8436134499c623485aeb20374a9928685db4211e (diff)
downloadzig-8c9ac4db978c80246b4872c899b1618b1b195ec2.tar.gz
zig-8c9ac4db978c80246b4872c899b1618b1b195ec2.zip
stage2: implement error notes and regress -femit-zir
* Implement error notes - note: other symbol exported here - note: previous else prong is here - note: previous '_' prong is here * Add Compilation.CObject.ErrorMsg. This object properly converts to AllErrors.Message when the time comes. * Add Compilation.CObject.failure_retryable. Properly handles out-of-memory and other transient failures. * Introduce Module.SrcLoc which has not only a byte offset but also references the file which the byte offset applies to. * Scope.Block now contains both a pointer to the "owner" Decl and the "source" Decl. As an example, during inline function call, the "owner" will be the Decl of the caller and the "source" will be the Decl of the callee. * Module.ErrorMsg now sports a `file_scope` field so that notes can refer to source locations in a file other than the parent error message. * Some instances where a `*Scope` was stored, now store a `*Scope.Container`. * Some methods in the `Scope` namespace were moved to the more specific type, since there was only an implementation for one particular tag. - `removeDecl` moved to `Scope.Container` - `destroy` moved to `Scope.File` * Two kinds of Scope deleted: - zir_module - decl * astgen: properly use DeclVal / DeclRef. DeclVal was incorrectly changed to be a reference; this commit fixes it. Fewer ZIR instructions processed as a result. - declval_in_module is renamed to declval - previous declval ZIR instruction is deleted; it was only for .zir files. * Test harness: friendlier diagnostics when an unexpected set of errors is encountered. * zir_sema: fix analyzeInstBlockFlat by properly calling resolvingInst on the last zir instruction in the block. Compile log implementation: * Write to a buffer rather than directly to stderr. * Only keep track of 1 callsite per Decl. * No longer mutate the ZIR Inst struct data. * "Compile log statement found" errors are only emitted when there are no other compile errors. -femit-zir and support for .zir source files is regressed. If we wanted to support this again, outputting .zir would need to be done as yet another backend rather than in the haphazard way it was previously implemented. For parsing .zir, it was implemented previously in a way that was not helpful for debugging. We need tighter integration with the test harness for it to be useful; so clearly a rewrite is needed. Given that a rewrite is needed, and it was getting in the way of progress and organization of the rest of stage2, I regressed the feature.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig47
1 files changed, 14 insertions, 33 deletions
diff --git a/src/main.zig b/src/main.zig
index 867aa348b1..13bea13a5e 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -221,7 +221,6 @@ const usage_build_generic =
\\
\\Supported file types:
\\ .zig Zig source code
- \\ .zir Zig Intermediate Representation code
\\ .o ELF object file
\\ .o MACH-O (macOS) object file
\\ .obj COFF (Windows) object file
@@ -245,8 +244,6 @@ const usage_build_generic =
\\ -fno-emit-bin Do not output machine code
\\ -femit-asm[=path] Output .s (assembly code)
\\ -fno-emit-asm (default) Do not output .s (assembly code)
- \\ -femit-zir[=path] Produce a .zir file with Zig IR
- \\ -fno-emit-zir (default) Do not produce a .zir file with Zig IR
\\ -femit-llvm-ir[=path] Produce a .ll file with LLVM IR (requires LLVM extensions)
\\ -fno-emit-llvm-ir (default) Do not produce a .ll file with LLVM IR
\\ -femit-h[=path] Generate a C header file (.h)
@@ -1631,18 +1628,12 @@ fn buildOutputType(
var emit_docs_resolved = try emit_docs.resolve("docs");
defer emit_docs_resolved.deinit();
- const zir_out_path: ?[]const u8 = switch (emit_zir) {
- .no => null,
- .yes_default_path => blk: {
- if (root_src_file) |rsf| {
- if (mem.endsWith(u8, rsf, ".zir")) {
- break :blk try std.fmt.allocPrint(arena, "{s}.out.zir", .{root_name});
- }
- }
- break :blk try std.fmt.allocPrint(arena, "{s}.zir", .{root_name});
+ switch (emit_zir) {
+ .no => {},
+ .yes_default_path, .yes => {
+ fatal("The -femit-zir implementation has been intentionally deleted so that it can be rewritten as a proper backend.", .{});
},
- .yes => |p| p,
- };
+ }
const root_pkg: ?*Package = if (root_src_file) |src_path| blk: {
if (main_pkg_path) |p| {
@@ -1753,7 +1744,7 @@ fn buildOutputType(
.dll_export_fns = dll_export_fns,
.object_format = object_format,
.optimize_mode = optimize_mode,
- .keep_source_files_loaded = zir_out_path != null,
+ .keep_source_files_loaded = false,
.clang_argv = clang_argv.items,
.lld_argv = lld_argv.items,
.lib_dirs = lib_dirs.items,
@@ -1845,7 +1836,7 @@ fn buildOutputType(
}
};
- updateModule(gpa, comp, zir_out_path, hook) catch |err| switch (err) {
+ updateModule(gpa, comp, hook) catch |err| switch (err) {
error.SemanticAnalyzeFail => if (!watch) process.exit(1),
else => |e| return e,
};
@@ -1980,7 +1971,7 @@ fn buildOutputType(
if (output_mode == .Exe) {
try comp.makeBinFileWritable();
}
- updateModule(gpa, comp, zir_out_path, hook) catch |err| switch (err) {
+ updateModule(gpa, comp, hook) catch |err| switch (err) {
error.SemanticAnalyzeFail => continue,
else => |e| return e,
};
@@ -2003,7 +1994,7 @@ const AfterUpdateHook = union(enum) {
update: []const u8,
};
-fn updateModule(gpa: *Allocator, comp: *Compilation, zir_out_path: ?[]const u8, hook: AfterUpdateHook) !void {
+fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !void {
try comp.update();
var errors = try comp.getAllErrorsAlloc();
@@ -2013,6 +2004,10 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, zir_out_path: ?[]const u8,
for (errors.list) |full_err_msg| {
full_err_msg.renderToStdErr();
}
+ const log_text = comp.getCompileLogOutput();
+ if (log_text.len != 0) {
+ std.debug.print("\nCompile Log Output:\n{s}", .{log_text});
+ }
return error.SemanticAnalyzeFail;
} else switch (hook) {
.none => {},
@@ -2024,20 +2019,6 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, zir_out_path: ?[]const u8,
.{},
),
}
-
- if (zir_out_path) |zop| {
- const module = comp.bin_file.options.module orelse
- fatal("-femit-zir with no zig source code", .{});
- var new_zir_module = try zir.emit(gpa, module);
- defer new_zir_module.deinit(gpa);
-
- const baf = try io.BufferedAtomicFile.create(gpa, fs.cwd(), zop, .{});
- defer baf.destroy();
-
- try new_zir_module.writeToStream(gpa, baf.writer());
-
- try baf.finish();
- }
}
fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !void {
@@ -2506,7 +2487,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v
};
defer comp.destroy();
- try updateModule(gpa, comp, null, .none);
+ try updateModule(gpa, comp, .none);
try comp.makeBinFileExecutable();
child_argv.items[argv_index_exe] = try comp.bin_file.options.emit.?.directory.join(