| ... | @@ -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 whether | 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 |
| 3 | //! there is or is not any zig source code, respectively. | 6 | //! there is or is not any zig source code, respectively. |
| 4 | | 7 | |
| 5 | const std = @import("std"); | 8 | const 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; |
| 13 | const Target = std.Target; | 16 | const Target = std.Target; |
| 14 | const Ast = std.zig.Ast; | 17 | const Ast = std.zig.Ast; |
| 15 | | 18 | |
| 16 | /// Deprecated, use `Zcu`. | | |
| 17 | const Module = Zcu; | | |
| 18 | const Zcu = @This(); | 19 | const Zcu = @This(); |
| 19 | const Compilation = @import("Compilation.zig"); | 20 | const Compilation = @import("Compilation.zig"); |
| 20 | const Cache = std.Build.Cache; | 21 | const 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 | }; |
| 2395 | | 2396 | |
| 2396 | pub fn init(mod: *Module, thread_count: usize) !void { | 2397 | pub 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 | } |
| 2489 | | 2490 | |
| 2490 | pub fn declPtr(mod: *Module, index: Decl.Index) *Decl { | 2491 | pub fn declPtr(mod: *Zcu, index: Decl.Index) *Decl { |
| 2491 | return mod.intern_pool.declPtr(index); | 2492 | return mod.intern_pool.declPtr(index); |
| 2492 | } | 2493 | } |
| 2493 | | 2494 | |
| 2494 | pub fn namespacePtr(mod: *Module, index: Namespace.Index) *Namespace { | 2495 | pub fn namespacePtr(mod: *Zcu, index: Namespace.Index) *Namespace { |
| 2495 | return mod.intern_pool.namespacePtr(index); | 2496 | return mod.intern_pool.namespacePtr(index); |
| 2496 | } | 2497 | } |
| 2497 | | 2498 | |
| 2498 | pub fn namespacePtrUnwrap(mod: *Module, index: Namespace.OptionalIndex) ?*Namespace { | 2499 | pub 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 | } |
| 2501 | | 2502 | |
| 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. |
| 2503 | pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool { | 2504 | pub 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 (see | 2941 | /// analyzed, and for ensuring it can exist at runtime (see |
| 2941 | /// `sema.fnHasRuntimeBits`). This function does *not* guarantee that the body | 2942 | /// `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`. |
| 2943 | pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index) !void { | 2944 | pub 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 | } |
| 3104 | | 3105 | |
| 3105 | pub fn errorSetBits(mod: *Module) u16 { | 3106 | pub 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 error | 3108 | return std.math.log2_int_ceil(ErrorInt, mod.error_limit + 1); // +1 for no error |
| 3108 | } | 3109 | } |
| 3109 | | 3110 | |
| 3110 | pub fn errNote( | 3111 | pub 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 | } |
| 3140 | | 3141 | |
| 3141 | fn lockAndClearFileCompileError(mod: *Module, file: *File) void { | 3142 | fn 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 | } |
| 3174 | | 3175 | |
| 3175 | pub fn addGlobalAssembly(mod: *Module, decl_index: Decl.Index, source: []const u8) !void { | 3176 | pub 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 affect | 3227 | // TODO this function does not take into account CPU features, which can affect |
| 3227 | // this value. Audit this! | 3228 | // this value. Audit this! |
| 3228 | pub fn atomicPtrAlignment( | 3229 | pub 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 | } |
| 3334 | | 3335 | |
| 3335 | pub fn declFileScope(mod: *Module, decl_index: Decl.Index) *File { | 3336 | pub 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 | } |
| 3338 | | 3339 | |
| ... | @@ -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. |
| 3343 | pub fn typeToStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType { | 3344 | pub 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 | } |
| 3351 | | 3352 | |
| 3352 | pub fn typeToPackedStruct(mod: *Module, ty: Type) ?InternPool.LoadedStructType { | 3353 | pub 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 | } |
| 3357 | | 3358 | |
| 3358 | pub fn typeToUnion(mod: *Module, ty: Type) ?InternPool.LoadedUnionType { | 3359 | pub 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 | } |
| 3366 | | 3367 | |
| 3367 | pub fn typeToFunc(mod: *Module, ty: Type) ?InternPool.Key.FuncType { | 3368 | pub 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 | } |
| 3371 | | 3372 | |
| 3372 | pub fn funcOwnerDeclPtr(mod: *Module, func_index: InternPool.Index) *Decl { | 3373 | pub 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 | } |
| 3375 | | 3376 | |
| 3376 | pub fn funcOwnerDeclIndex(mod: *Module, func_index: InternPool.Index) Decl.Index { | 3377 | pub 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 | } |
| 3379 | | 3380 | |
| 3380 | pub fn iesFuncIndex(mod: *const Module, ies_index: InternPool.Index) InternPool.Index { | 3381 | pub 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 | } |
| 3383 | | 3384 | |
| 3384 | pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func { | 3385 | pub 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 | } |
| 3387 | | 3388 | |
| 3388 | pub fn toEnum(mod: *Module, comptime E: type, val: Value) E { | 3389 | pub 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 | } |
| 3391 | | 3392 | |
| 3392 | pub fn isAnytypeParam(mod: *Module, func: InternPool.Index, index: u32) bool { | 3393 | pub 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); |
| 3394 | | 3395 | |
| 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 | } |
| 3406 | | 3407 | |
| 3407 | pub fn getParamName(mod: *Module, func_index: InternPool.Index, index: u32) [:0]const u8 { | 3408 | pub 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); |
| 3410 | | 3411 | |
| ... | @@ -3441,7 +3442,7 @@ pub const UnionLayout = struct { | ... | @@ -3441,7 +3442,7 @@ pub const UnionLayout = struct { |
| 3441 | }; | 3442 | }; |
| 3442 | | 3443 | |
| 3443 | /// Returns the index of the active field, given the current tag value | 3444 | /// Returns the index of the active field, given the current tag value |
| 3444 | pub fn unionTagFieldIndex(mod: *Module, loaded_union: InternPool.LoadedUnionType, enum_tag: Value) ?u32 { | 3445 | pub 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); |