aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-07-02 15:27:00 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-02 15:27:00 -0700
commitd979dd9b58f6d5462b009002e0a0eb79f94fb9a7 (patch)
tree6cb9504f15c34fd32f732b930b8d770346576617 /src/AstGen.zig
parent5103053977573131d8040a53d9ab3f2afd1b01b0 (diff)
downloadzig-d979dd9b58f6d5462b009002e0a0eb79f94fb9a7.tar.gz
zig-d979dd9b58f6d5462b009002e0a0eb79f94fb9a7.zip
stage2: improve AstGen FileNotFound error message
Partially addresses #9203. It fixes the first case, but not the second one mentioned in the issue.
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 4e3473629b..d511cc13aa 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -34,8 +34,9 @@ string_table: std.StringHashMapUnmanaged(u32) = .{},
compile_errors: ArrayListUnmanaged(Zir.Inst.CompileErrors.Item) = .{},
/// The topmost block of the current function.
fn_block: ?*GenZir = null,
-/// String table indexes, keeps track of all `@import` operands.
-imports: std.AutoArrayHashMapUnmanaged(u32, void) = .{},
+/// Maps string table indexes to the first `@import` ZIR instruction
+/// that uses this string as the operand.
+imports: std.AutoArrayHashMapUnmanaged(u32, Zir.Inst.Index) = .{},
const InnerError = error{ OutOfMemory, AnalysisFail };
@@ -154,7 +155,7 @@ pub fn generate(gpa: *Allocator, tree: ast.Tree) Allocator.Error!Zir {
astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{
.imports_len = @intCast(u32, astgen.imports.count()),
});
- astgen.extra.appendSliceAssumeCapacity(astgen.imports.keys());
+ astgen.extra.appendSliceAssumeCapacity(astgen.imports.values());
}
return Zir{
@@ -6863,8 +6864,13 @@ fn builtinCall(
}
const str_lit_token = main_tokens[operand_node];
const str = try astgen.strLitAsString(str_lit_token);
- try astgen.imports.put(astgen.gpa, str.index, {});
const result = try gz.addStrTok(.import, str.index, str_lit_token);
+ if (gz.refToIndex(result)) |import_inst_index| {
+ const gop = try astgen.imports.getOrPut(astgen.gpa, str.index);
+ if (!gop.found_existing) {
+ gop.value_ptr.* = import_inst_index;
+ }
+ }
return rvalue(gz, rl, result, node);
},
.compile_log => {