diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-07-04 15:47:47 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-07-04 17:56:01 -0700 |
| commit | 74346b0f79ca4bf67d61008030c7cc3565bff3f9 (patch) | |
| tree | 69bdcb7800608daed4a8908406623f3bab38f0e4 /src/Sema.zig | |
| parent | 30ec43a6c78d9c8803becbea5a02edb8fae08af6 (diff) | |
| download | zig-74346b0f79ca4bf67d61008030c7cc3565bff3f9.tar.gz zig-74346b0f79ca4bf67d61008030c7cc3565bff3f9.zip | |
frontend: TrackedInst stores FileIndex instead of path digest
The purpose of using path digest was to reference a file in a
serializable manner. Now that there is a stable index associated with
files, it is a superior way to accomplish that goal, since removes one
layer of indirection, and makes TrackedInst 8 bytes instead of 20.
The saved Zig Compiler State file for "hello world" goes from 1.3M to
1.2M with this change.
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index b2d4fd9a24..40fe11af3a 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -839,8 +839,7 @@ pub const Block = struct { const zcu = sema.mod; const ip = &zcu.intern_pool; const file_index = block.getFileScopeIndex(zcu); - const path_digest = zcu.filePathDigest(file_index); - return ip.trackZir(gpa, path_digest, inst); + return ip.trackZir(gpa, file_index, inst); } }; @@ -993,7 +992,7 @@ fn analyzeBodyInner( try sema.inst_map.ensureSpaceForInstructions(sema.gpa, body); - const mod = sema.mod; + const zcu = sema.mod; const map = &sema.inst_map; const tags = sema.code.instructions.items(.tag); const datas = sema.code.instructions.items(.data); @@ -1013,9 +1012,9 @@ fn analyzeBodyInner( // The hashmap lookup in here is a little expensive, and LLVM fails to optimize it away. if (build_options.enable_logging) { std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: { - const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest; - const index = mod.files.getIndex(path_digest).?; - break :sub_file_path mod.import_table.values()[index].sub_file_path; + const file_index = block.src_base_inst.resolveFull(&zcu.intern_pool).file; + const file = zcu.fileByIndex(file_index); + break :sub_file_path file.sub_file_path; }, inst }); } @@ -1776,9 +1775,9 @@ fn analyzeBodyInner( const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); const err_union = try sema.resolveInst(extra.data.operand); const err_union_ty = sema.typeOf(err_union); - if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { + if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) { return sema.fail(block, operand_src, "expected error union type, found '{}'", .{ - err_union_ty.fmt(mod), + err_union_ty.fmt(zcu), }); } const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); @@ -6003,7 +6002,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr const path_digest = zcu.filePathDigest(result.file_index); const root_decl = zcu.fileRootDecl(result.file_index); - zcu.astGenFile(result.file, path_digest, root_decl) catch |err| + zcu.astGenFile(result.file, result.file_index, path_digest, root_decl) catch |err| return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); try zcu.ensureFileAnalyzed(result.file_index); |
