authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-15 19:05:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-15 19:05:55-07:00
log8cb09db4e357c265ef3465fd736d36366d37a0a3
tree7623297bf1ee83ca0ac0e4070b585a8c269f0b41
parentba623b160ed43b720a6c653a24e9efb91f52d326

update some Module references to Zcu instead

I ended up reverting my real change, so here's a consolation prize instead.

2 files changed, 30 insertions(+), 29 deletions(-)

src/Compilation.zig+1-1
......@@ -3595,7 +3595,7 @@ fn performAllTheWorkInner(
35953595 }
35963596
35973597 if (comp.module) |zcu| {
3598 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = .main };
3598 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
35993599 if (comp.incremental) {
36003600 const update_zir_refs_node = main_progress_node.start("Update ZIR References", 0);
36013601 defer update_zir_refs_node.end();
src/Zcu.zig+29-28
......@@ -1,5 +1,8 @@
1//! Compilation of all Zig source code is represented by one `Module`.
2//! Each `Compilation` has exactly one or zero `Module`, depending on whether
1//! Zig Compilation Unit
2//!
3//! Compilation of all Zig source code is represented by one `Zcu`.
4//!
5//! Each `Compilation` has exactly one or zero `Zcu`, depending on whether
36//! there is or is not any zig source code, respectively.
47
58const std = @import("std");
......@@ -13,8 +16,6 @@ const BigIntMutable = std.math.big.int.Mutable;
1316const Target = std.Target;
1417const Ast = std.zig.Ast;
1518
16/// Deprecated, use `Zcu`.
17const Module = Zcu;
1819const Zcu = @This();
1920const Compilation = @import("Compilation.zig");
2021const Cache = std.Build.Cache;
......@@ -2393,7 +2394,7 @@ pub const CompileError = error{
23932394 ComptimeBreak,
23942395};
23952396
2396pub fn init(mod: *Module, thread_count: usize) !void {
2397pub fn init(mod: *Zcu, thread_count: usize) !void {
23972398 const gpa = mod.gpa;
23982399 try mod.intern_pool.init(gpa, thread_count);
23992400}
......@@ -2487,20 +2488,20 @@ pub fn deinit(zcu: *Zcu) void {
24872488 zcu.intern_pool.deinit(gpa);
24882489}
24892490
2490pub fn declPtr(mod: *Module, index: Decl.Index) *Decl {
2491pub fn declPtr(mod: *Zcu, index: Decl.Index) *Decl {
24912492 return mod.intern_pool.declPtr(index);
24922493}
24932494
2494pub fn namespacePtr(mod: *Module, index: Namespace.Index) *Namespace {
2495pub fn namespacePtr(mod: *Zcu, index: Namespace.Index) *Namespace {
24952496 return mod.intern_pool.namespacePtr(index);
24962497}
24972498
2498pub fn namespacePtrUnwrap(mod: *Module, index: Namespace.OptionalIndex) ?*Namespace {
2499pub fn namespacePtrUnwrap(mod: *Zcu, index: Namespace.OptionalIndex) ?*Namespace {
24992500 return mod.namespacePtr(index.unwrap() orelse return null);
25002501}
25012502
25022503/// Returns true if and only if the Decl is the top level struct associated with a File.
2503pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool {
2504pub fn declIsRoot(mod: *Zcu, decl_index: Decl.Index) bool {
25042505 const decl = mod.declPtr(decl_index);
25052506 const namespace = mod.namespacePtr(decl.src_namespace);
25062507 if (namespace.parent != .none) return false;
......@@ -2940,7 +2941,7 @@ pub fn mapOldZirToNew(
29402941/// analyzed, and for ensuring it can exist at runtime (see
29412942/// `sema.fnHasRuntimeBits`). This function does *not* guarantee that the body
29422943/// will be analyzed when it returns: for that, see `ensureFuncBodyAnalyzed`.
2943pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index) !void {
2944pub fn ensureFuncBodyAnalysisQueued(mod: *Zcu, func_index: InternPool.Index) !void {
29442945 const ip = &mod.intern_pool;
29452946 const func = mod.funcInfo(func_index);
29462947 const decl_index = func.owner_decl;
......@@ -3102,13 +3103,13 @@ pub fn addUnitReference(zcu: *Zcu, src_unit: AnalUnit, referenced_unit: AnalUnit
31023103 gop.value_ptr.* = @intCast(ref_idx);
31033104}
31043105
3105pub fn errorSetBits(mod: *Module) u16 {
3106pub fn errorSetBits(mod: *Zcu) u16 {
31063107 if (mod.error_limit == 0) return 0;
31073108 return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error
31083109}
31093110
31103111pub fn errNote(
3111 mod: *Module,
3112 mod: *Zcu,
31123113 src_loc: LazySrcLoc,
31133114 parent: *ErrorMsg,
31143115 comptime format: []const u8,
......@@ -3138,7 +3139,7 @@ pub fn optimizeMode(zcu: *const Zcu) std.builtin.OptimizeMode {
31383139 return zcu.root_mod.optimize_mode;
31393140}
31403141
3141fn lockAndClearFileCompileError(mod: *Module, file: *File) void {
3142fn lockAndClearFileCompileError(mod: *Zcu, file: *File) void {
31423143 switch (file.status) {
31433144 .success_zir, .retryable_failure => {},
31443145 .never_loaded, .parse_failure, .astgen_failure => {
......@@ -3172,7 +3173,7 @@ pub fn handleUpdateExports(
31723173 };
31733174}
31743175
3175pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u8) !void {
3176pub fn addGlobalAssembly(mod: *Zcu, decl_index: Decl.Index, source: []const u8) !void {
31763177 const gop = try mod.global_assembly.getOrPut(mod.gpa, decl_index);
31773178 if (gop.found_existing) {
31783179 const new_value = try std.fmt.allocPrint(mod.gpa, "{s}\n{s}", .{ gop.value_ptr.*, source });
......@@ -3226,7 +3227,7 @@ pub const AtomicPtrAlignmentDiagnostics = struct {
32263227// TODO this function does not take into account CPU features, which can affect
32273228// this value. Audit this!
32283229pub fn atomicPtrAlignment(
3229 mod: *Module,
3230 mod: *Zcu,
32303231 ty: Type,
32313232 diags: *AtomicPtrAlignmentDiagnostics,
32323233) AtomicPtrAlignmentError!Alignment {
......@@ -3332,7 +3333,7 @@ pub fn atomicPtrAlignment(
33323333 return error.BadType;
33333334}
33343335
3335pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File {
3336pub fn declFileScope(mod: *Zcu, decl_index: Decl.Index) *File {
33363337 return mod.declPtr(decl_index).getFileScope(mod);
33373338}
33383339
......@@ -3340,7 +3341,7 @@ pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File {
33403341/// * `@TypeOf(.{})`
33413342/// * A struct which has no fields (`struct {}`).
33423343/// * Not a struct.
3343pub fn typeToStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType {
3344pub fn typeToStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {
33443345 if (ty.ip_index == .none) return null;
33453346 const ip = &mod.intern_pool;
33463347 return switch (ip.indexToKey(ty.ip_index)) {
......@@ -3349,13 +3350,13 @@ pub fn typeToStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType {
33493350 };
33503351}
33513352
3352pub fn typeToPackedStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType {
3353pub fn typeToPackedStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {
33533354 const s = mod.typeToStruct(ty) orelse return null;
33543355 if (s.layout != .@"packed") return null;
33553356 return s;
33563357}
33573358
3358pub fn typeToUnion(mod: *Module, ty: Type) ?InternPool.LoadedUnionType {
3359pub fn typeToUnion(mod: *Zcu, ty: Type) ?InternPool.LoadedUnionType {
33593360 if (ty.ip_index == .none) return null;
33603361 const ip = &mod.intern_pool;
33613362 return switch (ip.indexToKey(ty.ip_index)) {
......@@ -3364,32 +3365,32 @@ pub fn typeToUnion(mod: *Module, ty: Type) ?InternPool.LoadedUnionType {
33643365 };
33653366}
33663367
3367pub fn typeToFunc(mod: *Module, ty: Type) ?InternPool.Key.FuncType {
3368pub fn typeToFunc(mod: *Zcu, ty: Type) ?InternPool.Key.FuncType {
33683369 if (ty.ip_index == .none) return null;
33693370 return mod.intern_pool.indexToFuncType(ty.toIntern());
33703371}
33713372
3372pub fn funcOwnerDeclPtr(mod: *Module, func_index: InternPool.Index) *Decl {
3373pub fn funcOwnerDeclPtr(mod: *Zcu, func_index: InternPool.Index) *Decl {
33733374 return mod.declPtr(mod.funcOwnerDeclIndex(func_index));
33743375}
33753376
3376pub fn funcOwnerDeclIndex(mod: *Module, func_index: InternPool.Index) Decl.Index {
3377pub fn funcOwnerDeclIndex(mod: *Zcu, func_index: InternPool.Index) Decl.Index {
33773378 return mod.funcInfo(func_index).owner_decl;
33783379}
33793380
3380pub fn iesFuncIndex(mod: *const Module, ies_index: InternPool.Index) InternPool.Index {
3381pub fn iesFuncIndex(mod: *const Zcu, ies_index: InternPool.Index) InternPool.Index {
33813382 return mod.intern_pool.iesFuncIndex(ies_index);
33823383}
33833384
3384pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func {
3385pub fn funcInfo(mod: *Zcu, func_index: InternPool.Index) InternPool.Key.Func {
33853386 return mod.intern_pool.indexToKey(func_index).func;
33863387}
33873388
3388pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {
3389pub fn toEnum(mod: *Zcu, comptime E: type, val: Value) E {
33893390 return mod.intern_pool.toEnum(E, val.toIntern());
33903391}
33913392
3392pub fn isAnytypeParam(mod: *Module, func: InternPool.Index, index: u32) bool {
3393pub fn isAnytypeParam(mod: *Zcu, func: InternPool.Index, index: u32) bool {
33933394 const file = mod.declPtr(func.owner_decl).getFileScope(mod);
33943395
33953396 const tags = file.zir.instructions.items(.tag);
......@@ -3404,7 +3405,7 @@ pub fn isAnytypeParam(mod: *Module, func: InternPool.Index, index: u32) bool {
34043405 };
34053406}
34063407
3407pub fn getParamName(mod: *Module, func_index: InternPool.Index, index: u32) [:0]const u8 {
3408pub fn getParamName(mod: *Zcu, func_index: InternPool.Index, index: u32) [:0]const u8 {
34083409 const func = mod.funcInfo(func_index);
34093410 const file = mod.declPtr(func.owner_decl).getFileScope(mod);
34103411
......@@ -3441,7 +3442,7 @@ pub const UnionLayout = struct {
34413442};
34423443
34433444/// Returns the index of the active field, given the current tag value
3444pub fn unionTagFieldIndex(mod: *Module, loaded_union: InternPool.LoadedUnionType, enum_tag: Value) ?u32 {
3445pub fn unionTagFieldIndex(mod: *Zcu, loaded_union: InternPool.LoadedUnionType, enum_tag: Value) ?u32 {
34453446 const ip = &mod.intern_pool;
34463447 if (enum_tag.toIntern() == .none) return null;
34473448 assert(ip.typeOf(enum_tag.toIntern()) == loaded_union.enum_tag_ty);