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(...@@ -3595,7 +3595,7 @@ fn performAllTheWorkInner(
3595 }3595 }
35963596
3597 if (comp.module) |zcu| {3597 if (comp.module) |zcu| {
3598 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = .main };3598 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
3599 if (comp.incremental) {3599 if (comp.incremental) {
3600 const update_zir_refs_node = main_progress_node.start("Update ZIR References", 0);3600 const update_zir_refs_node = main_progress_node.start("Update ZIR References", 0);
3601 defer update_zir_refs_node.end();3601 defer update_zir_refs_node.end();
src/Zcu.zig+29-28
...@@ -1,5 +1,8 @@...@@ -1,5 +1,8 @@
1//! Compilation of all Zig source code is represented by one `Module`.1//! Zig Compilation Unit
2//! Each `Compilation` has exactly one or zero `Module`, depending on whether2//!
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
3//! there is or is not any zig source code, respectively.6//! there is or is not any zig source code, respectively.
47
5const std = @import("std");8const std = @import("std");
...@@ -13,8 +16,6 @@ const BigIntMutable = std.math.big.int.Mutable;...@@ -13,8 +16,6 @@ const BigIntMutable = std.math.big.int.Mutable;
13const Target = std.Target;16const Target = std.Target;
14const Ast = std.zig.Ast;17const Ast = std.zig.Ast;
1518
16/// Deprecated, use `Zcu`.
17const Module = Zcu;
18const Zcu = @This();19const Zcu = @This();
19const Compilation = @import("Compilation.zig");20const Compilation = @import("Compilation.zig");
20const Cache = std.Build.Cache;21const Cache = std.Build.Cache;
...@@ -2393,7 +2394,7 @@ pub const CompileError = error{...@@ -2393,7 +2394,7 @@ pub const CompileError = error{
2393 ComptimeBreak,2394 ComptimeBreak,
2394};2395};
23952396
2396pub fn init(mod: *Module, thread_count: usize) !void {2397pub fn init(mod: *Zcu, thread_count: usize) !void {
2397 const gpa = mod.gpa;2398 const gpa = mod.gpa;
2398 try mod.intern_pool.init(gpa, thread_count);2399 try mod.intern_pool.init(gpa, thread_count);
2399}2400}
...@@ -2487,20 +2488,20 @@ pub fn deinit(zcu: *Zcu) void {...@@ -2487,20 +2488,20 @@ pub fn deinit(zcu: *Zcu) void {
2487 zcu.intern_pool.deinit(gpa);2488 zcu.intern_pool.deinit(gpa);
2488}2489}
24892490
2490pub fn declPtr(mod: *Module, index: Decl.Index) *Decl {2491pub fn declPtr(mod: *Zcu, index: Decl.Index) *Decl {
2491 return mod.intern_pool.declPtr(index);2492 return mod.intern_pool.declPtr(index);
2492}2493}
24932494
2494pub fn namespacePtr(mod: *Module, index: Namespace.Index) *Namespace {2495pub fn namespacePtr(mod: *Zcu, index: Namespace.Index) *Namespace {
2495 return mod.intern_pool.namespacePtr(index);2496 return mod.intern_pool.namespacePtr(index);
2496}2497}
24972498
2498pub fn namespacePtrUnwrap(mod: *Module, index: Namespace.OptionalIndex) ?*Namespace {2499pub fn namespacePtrUnwrap(mod: *Zcu, index: Namespace.OptionalIndex) ?*Namespace {
2499 return mod.namespacePtr(index.unwrap() orelse return null);2500 return mod.namespacePtr(index.unwrap() orelse return null);
2500}2501}
25012502
2502/// Returns true if and only if the Decl is the top level struct associated with a File.2503/// 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 {
2504 const decl = mod.declPtr(decl_index);2505 const decl = mod.declPtr(decl_index);
2505 const namespace = mod.namespacePtr(decl.src_namespace);2506 const namespace = mod.namespacePtr(decl.src_namespace);
2506 if (namespace.parent != .none) return false;2507 if (namespace.parent != .none) return false;
...@@ -2940,7 +2941,7 @@ pub fn mapOldZirToNew(...@@ -2940,7 +2941,7 @@ pub fn mapOldZirToNew(
2940/// analyzed, and for ensuring it can exist at runtime (see2941/// analyzed, and for ensuring it can exist at runtime (see
2941/// `sema.fnHasRuntimeBits`). This function does *not* guarantee that the body2942/// `sema.fnHasRuntimeBits`). This function does *not* guarantee that the body
2942/// will be analyzed when it returns: for that, see `ensureFuncBodyAnalyzed`.2943/// 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 {
2944 const ip = &mod.intern_pool;2945 const ip = &mod.intern_pool;
2945 const func = mod.funcInfo(func_index);2946 const func = mod.funcInfo(func_index);
2946 const decl_index = func.owner_decl;2947 const decl_index = func.owner_decl;
...@@ -3102,13 +3103,13 @@ pub fn addUnitReference(zcu: *Zcu, src_unit: AnalUnit, referenced_unit: AnalUnit...@@ -3102,13 +3103,13 @@ pub fn addUnitReference(zcu: *Zcu, src_unit: AnalUnit, referenced_unit: AnalUnit
3102 gop.value_ptr.* = @intCast(ref_idx);3103 gop.value_ptr.* = @intCast(ref_idx);
3103}3104}
31043105
3105pub fn errorSetBits(mod: *Module) u16 {3106pub fn errorSetBits(mod: *Zcu) u16 {
3106 if (mod.error_limit == 0) return 0;3107 if (mod.error_limit == 0) return 0;
3107 return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error3108 return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error
3108}3109}
31093110
3110pub fn errNote(3111pub fn errNote(
3111 mod: *Module,3112 mod: *Zcu,
3112 src_loc: LazySrcLoc,3113 src_loc: LazySrcLoc,
3113 parent: *ErrorMsg,3114 parent: *ErrorMsg,
3114 comptime format: []const u8,3115 comptime format: []const u8,
...@@ -3138,7 +3139,7 @@ pub fn optimizeMode(zcu: *const Zcu) std.builtin.OptimizeMode {...@@ -3138,7 +3139,7 @@ pub fn optimizeMode(zcu: *const Zcu) std.builtin.OptimizeMode {
3138 return zcu.root_mod.optimize_mode;3139 return zcu.root_mod.optimize_mode;
3139}3140}
31403141
3141fn lockAndClearFileCompileError(mod: *Module, file: *File) void {3142fn lockAndClearFileCompileError(mod: *Zcu, file: *File) void {
3142 switch (file.status) {3143 switch (file.status) {
3143 .success_zir, .retryable_failure => {},3144 .success_zir, .retryable_failure => {},
3144 .never_loaded, .parse_failure, .astgen_failure => {3145 .never_loaded, .parse_failure, .astgen_failure => {
...@@ -3172,7 +3173,7 @@ pub fn handleUpdateExports(...@@ -3172,7 +3173,7 @@ pub fn handleUpdateExports(
3172 };3173 };
3173}3174}
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 {
3176 const gop = try mod.global_assembly.getOrPut(mod.gpa, decl_index);3177 const gop = try mod.global_assembly.getOrPut(mod.gpa, decl_index);
3177 if (gop.found_existing) {3178 if (gop.found_existing) {
3178 const new_value = try std.fmt.allocPrint(mod.gpa, "{s}\n{s}", .{ gop.value_ptr.*, source });3179 const new_value = try std.fmt.allocPrint(mod.gpa, "{s}\n{s}", .{ gop.value_ptr.*, source });
...@@ -3226,7 +3227,7 @@ pub const AtomicPtrAlignmentDiagnostics = struct {...@@ -3226,7 +3227,7 @@ pub const AtomicPtrAlignmentDiagnostics = struct {
3226// TODO this function does not take into account CPU features, which can affect3227// TODO this function does not take into account CPU features, which can affect
3227// this value. Audit this!3228// this value. Audit this!
3228pub fn atomicPtrAlignment(3229pub fn atomicPtrAlignment(
3229 mod: *Module,3230 mod: *Zcu,
3230 ty: Type,3231 ty: Type,
3231 diags: *AtomicPtrAlignmentDiagnostics,3232 diags: *AtomicPtrAlignmentDiagnostics,
3232) AtomicPtrAlignmentError!Alignment {3233) AtomicPtrAlignmentError!Alignment {
...@@ -3332,7 +3333,7 @@ pub fn atomicPtrAlignment(...@@ -3332,7 +3333,7 @@ pub fn atomicPtrAlignment(
3332 return error.BadType;3333 return error.BadType;
3333}3334}
33343335
3335pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File {3336pub fn declFileScope(mod: *Zcu, decl_index: Decl.Index) *File {
3336 return mod.declPtr(decl_index).getFileScope(mod);3337 return mod.declPtr(decl_index).getFileScope(mod);
3337}3338}
33383339
...@@ -3340,7 +3341,7 @@ pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File {...@@ -3340,7 +3341,7 @@ pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File {
3340/// * `@TypeOf(.{})`3341/// * `@TypeOf(.{})`
3341/// * A struct which has no fields (`struct {}`).3342/// * A struct which has no fields (`struct {}`).
3342/// * Not a struct.3343/// * Not a struct.
3343pub fn typeToStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType {3344pub fn typeToStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3344 if (ty.ip_index == .none) return null;3345 if (ty.ip_index == .none) return null;
3345 const ip = &mod.intern_pool;3346 const ip = &mod.intern_pool;
3346 return switch (ip.indexToKey(ty.ip_index)) {3347 return switch (ip.indexToKey(ty.ip_index)) {
...@@ -3349,13 +3350,13 @@ pub fn typeToStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType {...@@ -3349,13 +3350,13 @@ pub fn typeToStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType {
3349 };3350 };
3350}3351}
33513352
3352pub fn typeToPackedStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType {3353pub fn typeToPackedStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3353 const s = mod.typeToStruct(ty) orelse return null;3354 const s = mod.typeToStruct(ty) orelse return null;
3354 if (s.layout != .@"packed") return null;3355 if (s.layout != .@"packed") return null;
3355 return s;3356 return s;
3356}3357}
33573358
3358pub fn typeToUnion(mod: *Module, ty: Type) ?InternPool.LoadedUnionType {3359pub fn typeToUnion(mod: *Zcu, ty: Type) ?InternPool.LoadedUnionType {
3359 if (ty.ip_index == .none) return null;3360 if (ty.ip_index == .none) return null;
3360 const ip = &mod.intern_pool;3361 const ip = &mod.intern_pool;
3361 return switch (ip.indexToKey(ty.ip_index)) {3362 return switch (ip.indexToKey(ty.ip_index)) {
...@@ -3364,32 +3365,32 @@ pub fn typeToUnion(mod: *Module, ty: Type) ?InternPool.LoadedUnionType {...@@ -3364,32 +3365,32 @@ pub fn typeToUnion(mod: *Module, ty: Type) ?InternPool.LoadedUnionType {
3364 };3365 };
3365}3366}
33663367
3367pub fn typeToFunc(mod: *Module, ty: Type) ?InternPool.Key.FuncType {3368pub fn typeToFunc(mod: *Zcu, ty: Type) ?InternPool.Key.FuncType {
3368 if (ty.ip_index == .none) return null;3369 if (ty.ip_index == .none) return null;
3369 return mod.intern_pool.indexToFuncType(ty.toIntern());3370 return mod.intern_pool.indexToFuncType(ty.toIntern());
3370}3371}
33713372
3372pub fn funcOwnerDeclPtr(mod: *Module, func_index: InternPool.Index) *Decl {3373pub fn funcOwnerDeclPtr(mod: *Zcu, func_index: InternPool.Index) *Decl {
3373 return mod.declPtr(mod.funcOwnerDeclIndex(func_index));3374 return mod.declPtr(mod.funcOwnerDeclIndex(func_index));
3374}3375}
33753376
3376pub fn funcOwnerDeclIndex(mod: *Module, func_index: InternPool.Index) Decl.Index {3377pub fn funcOwnerDeclIndex(mod: *Zcu, func_index: InternPool.Index) Decl.Index {
3377 return mod.funcInfo(func_index).owner_decl;3378 return mod.funcInfo(func_index).owner_decl;
3378}3379}
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 {
3381 return mod.intern_pool.iesFuncIndex(ies_index);3382 return mod.intern_pool.iesFuncIndex(ies_index);
3382}3383}
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 {
3385 return mod.intern_pool.indexToKey(func_index).func;3386 return mod.intern_pool.indexToKey(func_index).func;
3386}3387}
33873388
3388pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {3389pub fn toEnum(mod: *Zcu, comptime E: type, val: Value) E {
3389 return mod.intern_pool.toEnum(E, val.toIntern());3390 return mod.intern_pool.toEnum(E, val.toIntern());
3390}3391}
33913392
3392pub fn isAnytypeParam(mod: *Module, func: InternPool.Index, index: u32) bool {3393pub fn isAnytypeParam(mod: *Zcu, func: InternPool.Index, index: u32) bool {
3393 const file = mod.declPtr(func.owner_decl).getFileScope(mod);3394 const file = mod.declPtr(func.owner_decl).getFileScope(mod);
33943395
3395 const tags = file.zir.instructions.items(.tag);3396 const tags = file.zir.instructions.items(.tag);
...@@ -3404,7 +3405,7 @@ pub fn isAnytypeParam(mod: *Module, func: InternPool.Index, index: u32) bool {...@@ -3404,7 +3405,7 @@ pub fn isAnytypeParam(mod: *Module, func: InternPool.Index, index: u32) bool {
3404 };3405 };
3405}3406}
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 {
3408 const func = mod.funcInfo(func_index);3409 const func = mod.funcInfo(func_index);
3409 const file = mod.declPtr(func.owner_decl).getFileScope(mod);3410 const file = mod.declPtr(func.owner_decl).getFileScope(mod);
34103411
...@@ -3441,7 +3442,7 @@ pub const UnionLayout = struct {...@@ -3441,7 +3442,7 @@ pub const UnionLayout = struct {
3441};3442};
34423443
3443/// Returns the index of the active field, given the current tag value3444/// 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 {
3445 const ip = &mod.intern_pool;3446 const ip = &mod.intern_pool;
3446 if (enum_tag.toIntern() == .none) return null;3447 if (enum_tag.toIntern() == .none) return null;
3447 assert(ip.typeOf(enum_tag.toIntern()) == loaded_union.enum_tag_ty);3448 assert(ip.typeOf(enum_tag.toIntern()) == loaded_union.enum_tag_ty);