authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-22 16:11:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-23 10:44:46-07:00
log150515f44db9cecbda31d579861dc6f6080c2f75
tree859145a3479f7e9880269b2ef945bfce3043ccf3
parent6fb45807abab49982c12b71112e9acb39cf94270

stage2: slightly improve error reporting for missing imports

There is now a distinction between `@import` with a .zig extension and without. Without a .zig extension it assumes it is a package name, and returns error.PackageNotFound if not mapped into the package table.

3 files changed, 20 insertions(+), 5 deletions(-)

src/Compilation.zig+17-4
...@@ -2319,6 +2319,9 @@ fn workerAstGenFile(...@@ -2319,6 +2319,9 @@ fn workerAstGenFile(
2319 break :blk mod.importFile(file, import_path) catch continue;2319 break :blk mod.importFile(file, import_path) catch continue;
2320 };2320 };
2321 if (import_result.is_new) {2321 if (import_result.is_new) {
2322 log.debug("AstGen of {s} has import '{s}'; queuing AstGen of {s}", .{
2323 file.sub_file_path, import_path, import_result.file.sub_file_path,
2324 });
2322 wg.start();2325 wg.start();
2323 comp.thread_pool.spawn(workerAstGenFile, .{2326 comp.thread_pool.spawn(workerAstGenFile, .{
2324 comp, import_result.file, prog_node, wg,2327 comp, import_result.file, prog_node, wg,
...@@ -2540,13 +2543,23 @@ fn reportRetryableAstGenError(...@@ -2540,13 +2543,23 @@ fn reportRetryableAstGenError(
25402543
2541 file.status = .retryable_failure;2544 file.status = .retryable_failure;
25422545
2543 const err_msg = try Module.ErrorMsg.create(gpa, .{2546 const src_loc: Module.SrcLoc = .{
2544 .file_scope = file,2547 .file_scope = file,
2545 .parent_decl_node = 0,2548 .parent_decl_node = 0,
2546 .lazy = .entire_file,2549 .lazy = .entire_file,
2547 }, "unable to load {s}: {s}", .{2550 };
2548 file.sub_file_path, @errorName(err),2551
2549 });2552 const err_msg = if (file.pkg.root_src_directory.path) |dir_path|
2553 try Module.ErrorMsg.create(
2554 gpa,
2555 src_loc,
2556 "unable to load {s}" ++ std.fs.path.sep_str ++ "{s}: {s}",
2557 .{ dir_path, file.sub_file_path, @errorName(err) },
2558 )
2559 else
2560 try Module.ErrorMsg.create(gpa, src_loc, "unable to load {s}: {s}", .{
2561 file.sub_file_path, @errorName(err),
2562 });
2550 errdefer err_msg.destroy(gpa);2563 errdefer err_msg.destroy(gpa);
25512564
2552 {2565 {
src/Module.zig+3
...@@ -3185,6 +3185,9 @@ pub fn importFile(...@@ -3185,6 +3185,9 @@ pub fn importFile(
3185 if (cur_file.pkg.table.get(import_string)) |pkg| {3185 if (cur_file.pkg.table.get(import_string)) |pkg| {
3186 return mod.importPkg(pkg);3186 return mod.importPkg(pkg);
3187 }3187 }
3188 if (!mem.endsWith(u8, import_string, ".zig")) {
3189 return error.PackageNotFound;
3190 }
3188 const gpa = mod.gpa;3191 const gpa = mod.gpa;
31893192
3190 // The resolved path is used as the key in the import table, to detect if3193 // The resolved path is used as the key in the import table, to detect if
src/codegen/x86_64.zig-1
...@@ -4,7 +4,6 @@ const mem = std.mem;...@@ -4,7 +4,6 @@ const mem = std.mem;
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const ArrayList = std.ArrayList;5const ArrayList = std.ArrayList;
6const Allocator = std.mem.Allocator;6const Allocator = std.mem.Allocator;
7const Type = @import("../Type.zig");
8const DW = std.dwarf;7const DW = std.dwarf;
98
10// zig fmt: off9// zig fmt: off