authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-02 13:32:06+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:09+00:00
loga9bfc94ee65f1dafe5c67bb8fbd58cd2372cfd28
tree83a4587f67d719c3eb262177984029d0ba62735f
parentb8997f871fc63cee28d94168330d84f177543f2c
signaturelock-open Commit is signed but in an unrecognized format.

compiler: small misc cleanups


4 files changed, 94 insertions(+), 123 deletions(-)

lib/std/zig.zig+2-2
......@@ -868,7 +868,7 @@ pub const SimpleComptimeReason = enum(u32) {
868868 casted_to_comptime_enum,
869869 casted_to_comptime_int,
870870 casted_to_comptime_float,
871 panic_handler,
871 std_builtin_decl,
872872
873873 pub fn message(r: SimpleComptimeReason) []const u8 {
874874 return switch (r) {
......@@ -957,7 +957,7 @@ pub const SimpleComptimeReason = enum(u32) {
957957 .casted_to_comptime_enum => "value casted to enum with 'comptime_int' tag type must be comptime-known",
958958 .casted_to_comptime_int => "value casted to 'comptime_int' must be comptime-known",
959959 .casted_to_comptime_float => "value casted to 'comptime_float' must be comptime-known",
960 .panic_handler => "panic handler must be comptime-known",
960 .std_builtin_decl => "'std.builtin' declaration values must be comptime-known",
961961 // zig fmt: on
962962 };
963963 }
src/Compilation.zig+12-11
......@@ -986,7 +986,9 @@ const Job = union(enum) {
986986 /// If the unit is a *test* function, an `analyze_func` job will also be queued.
987987 analyze_unit: InternPool.AnalUnit,
988988 /// The main source file for the module needs to be analyzed.
989 analyze_mod: *Package.Module,
989 /// For every module which is an analysis root, analyze the main struct type of the module's
990 /// root source file. This is how semantic analysis begins.
991 analyze_roots,
990992
991993 /// The value is the index into `windows_libs`.
992994 windows_import_lib: usize,
......@@ -1396,7 +1398,6 @@ pub const MiscTask = enum {
13961398 wasi_libc_crt_file,
13971399 compiler_rt,
13981400 libzigc,
1399 analyze_mod,
14001401 link_depfile,
14011402 docs_copy,
14021403 docs_wasm,
......@@ -4840,9 +4841,7 @@ fn performAllTheWork(
48404841 try zcu.flushRetryableFailures();
48414842
48424843 // It's analysis time! Queue up our initial analysis.
4843 for (zcu.analysisRoots()) |mod| {
4844 try comp.queueJob(.{ .analyze_mod = mod });
4845 }
4844 try comp.queueJob(.analyze_roots);
48464845
48474846 zcu.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
48484847 if (comp.bin_file != null) {
......@@ -5275,15 +5274,17 @@ fn processOneJob(tid: Zcu.PerThread.Id, comp: *Compilation, job: Job) JobError!v
52755274 try pt.zcu.ensureFuncBodyAnalysisQueued(ip.getNav(nav).status.fully_resolved.val);
52765275 }
52775276 },
5278 .analyze_mod => |mod| {
5279 const tracy_trace = traceNamed(@src(), "analyze_mod");
5277 .analyze_roots => {
5278 const tracy_trace = traceNamed(@src(), "analyze_roots");
52805279 defer tracy_trace.end();
52815280
5282 const pt: Zcu.PerThread = .activate(comp.zcu.?, tid);
5281 const zcu = comp.zcu.?;
5282 const pt: Zcu.PerThread = .activate(zcu, tid);
52835283 defer pt.deactivate();
5284
5285 const mod_root_file = pt.zcu.module_roots.get(mod).?.unwrap().?;
5286 try pt.ensureFileAnalyzed(mod_root_file);
5284 for (zcu.analysisRoots()) |analysis_root_mod| {
5285 const analysis_root_file = zcu.module_roots.get(analysis_root_mod).?.unwrap().?;
5286 try pt.ensureFileAnalyzed(analysis_root_file);
5287 }
52875288 },
52885289 .windows_import_lib => |index| {
52895290 const tracy_trace = traceNamed(@src(), "windows_import_lib");
src/Sema.zig+76-64
......@@ -2308,6 +2308,7 @@ pub fn resolveConstValue(
23082308 /// being comptime-resolved is that the block is being comptime-evaluated.
23092309 reason: ?ComptimeReason,
23102310) CompileError!Value {
2311 assert(reason != null or block.isComptime());
23112312 return sema.resolveValue(inst) orelse {
23122313 return sema.failWithNeededComptime(block, src, reason);
23132314 };
......@@ -12927,6 +12928,8 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1292712928 try pt.ensureFileAnalyzed(file_index);
1292812929 const ty: Type = .fromInterned(zcu.fileRootType(file_index));
1292912930 try sema.addTypeReferenceEntry(operand_src, ty);
12931 // No need for `ensureNamespaceUpToDate`, because `Zcu.PerThread.updateFileNamespace`
12932 // already made sure that all root file structs have up-to-date namespaces.
1293012933 return .fromType(ty);
1293112934 },
1293212935 .zon => {
......@@ -16342,7 +16345,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1634216345 const alignment_val = try pt.intValue(.comptime_int, bytes: {
1634316346 if (info.flags.alignment.toByteUnits()) |b| break :bytes b;
1634416347 const elem_ty: Type = .fromInterned(info.child);
16345 // MLUGG TODO: this resolution is sus, but i doubt i'll solve it in this branch
1634616348 try sema.ensureLayoutResolved(elem_ty, src);
1634716349 break :bytes elem_ty.abiAlignment(zcu).toByteUnits().?;
1634816350 });
......@@ -18942,12 +18944,13 @@ fn structInitAnon(
1894218944 .file_scope = block.getFileScopeIndex(zcu),
1894318945 .generation = zcu.generation,
1894418946 });
18947 errdefer pt.destroyNamespace(new_namespace_index);
1894518948 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
18946
1894718949 break :ty .fromInterned(wip.finish(ip, new_namespace_index));
1894818950 },
1894918951 };
1895018952 try sema.addTypeReferenceEntry(src, struct_ty);
18953 // No need for `ensureNamespaceUpToDate` because this type's namespace is always empty.
1895118954 try sema.ensureLayoutResolved(struct_ty, src);
1895218955
1895318956 _ = opt_runtime_index orelse {
......@@ -20150,6 +20153,7 @@ fn zirReifyStruct(
2015020153 })) {
2015120154 .existing => |ty| {
2015220155 try sema.addTypeReferenceEntry(src, .fromInterned(ty));
20156 // No need for `ensureNamespaceUpToDate` because this type's namespace is always empty.
2015320157 return .fromIntern(ty);
2015420158 },
2015520159 .wip => |wip| {
......@@ -20210,9 +20214,9 @@ fn zirReifyStruct(
2021020214 .file_scope = block.getFileScopeIndex(zcu),
2021120215 .generation = zcu.generation,
2021220216 });
20213 try sema.addTypeReferenceEntry(src, .fromInterned(wip.index));
20217 errdefer pt.destroyNamespace(new_namespace_index);
2021420218 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
20215
20219 try sema.addTypeReferenceEntry(src, .fromInterned(wip.index));
2021620220 return .fromIntern(wip.finish(ip, new_namespace_index));
2021720221 },
2021820222 }
......@@ -20393,6 +20397,7 @@ fn zirReifyUnion(
2039320397 })) {
2039420398 .existing => |ty| {
2039520399 try sema.addTypeReferenceEntry(src, .fromInterned(ty));
20400 // No need for `ensureNamespaceUpToDate` because this type's namespace is always empty.
2039620401 return .fromIntern(ty);
2039720402 },
2039820403 .wip => |wip| {
......@@ -20430,9 +20435,9 @@ fn zirReifyUnion(
2043020435 .file_scope = block.getFileScopeIndex(zcu),
2043120436 .generation = zcu.generation,
2043220437 });
20438 errdefer pt.destroyNamespace(new_namespace_index);
2043320439 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
2043420440 try sema.addTypeReferenceEntry(src, .fromInterned(wip.index));
20435
2043620441 return .fromIntern(wip.finish(ip, new_namespace_index));
2043720442 },
2043820443 }
......@@ -20557,6 +20562,7 @@ fn zirReifyEnum(
2055720562 })) {
2055820563 .existing => |ty| {
2055920564 try sema.addTypeReferenceEntry(src, .fromInterned(ty));
20565 // No need for `ensureNamespaceUpToDate` because this type's namespace is always empty.
2056020566 return .fromIntern(ty);
2056120567 },
2056220568 .wip => |wip| {
......@@ -20581,10 +20587,9 @@ fn zirReifyEnum(
2058120587 .file_scope = block.getFileScopeIndex(zcu),
2058220588 .generation = zcu.generation,
2058320589 });
20584
20585 try sema.addTypeReferenceEntry(src, .fromInterned(wip.index));
20590 errdefer pt.destroyNamespace(new_namespace_index);
2058620591 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
20587
20592 try sema.addTypeReferenceEntry(src, .fromInterned(wip.index));
2058820593 return .fromIntern(wip.finish(ip, new_namespace_index));
2058920594 },
2059020595 }
......@@ -33861,7 +33866,7 @@ pub fn resolveNavPtrModifiers(
3386133866 };
3386233867}
3386333868
33864pub fn analyzeMemoizedState(sema: *Sema, block: *Block, simple_src: LazySrcLoc, builtin_namespace: InternPool.NamespaceIndex, stage: InternPool.MemoizedStateStage) CompileError!bool {
33869pub fn analyzeMemoizedState(sema: *Sema, stage: InternPool.MemoizedStateStage) CompileError!bool {
3386533870 const pt = sema.pt;
3386633871 const zcu = pt.zcu;
3386733872 const comp = zcu.comp;
......@@ -33869,53 +33874,87 @@ pub fn analyzeMemoizedState(sema: *Sema, block: *Block, simple_src: LazySrcLoc,
3386933874 const io = comp.io;
3387033875 const ip = &zcu.intern_pool;
3387133876
33877 // This `Block` acts kind of like it's evaluating a `comptime` declaration in the root source
33878 // file of the standard library. In particular, its namespace is the root std namespace.
33879 var block: Block = block: {
33880 // Get the main struct type of the root source file of `std`. No need for a reference entry
33881 // because `std` is always an analysis root.
33882 const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?;
33883 try pt.ensureFileAnalyzed(std_file_index);
33884 const std_type: Type = .fromInterned(zcu.fileRootType(std_file_index));
33885 break :block .{
33886 .parent = null,
33887 .sema = sema,
33888 .namespace = std_type.getNamespaceIndex(zcu),
33889 .instructions = .empty,
33890 .inlining = null,
33891 .comptime_reason = null,
33892 .src_base_inst = std_type.typeDeclInst(zcu).?,
33893 .type_name_ctx = .empty,
33894 };
33895 };
33896 defer block.instructions.deinit(gpa);
33897
33898 const std_builtin_ty: Type = ty: {
33899 const std_src = block.nodeOffset(.zero);
33900 const decl_name = try ip.getOrPutString(gpa, io, pt.tid, "builtin", .no_embedded_nulls);
33901 const nav = try sema.namespaceLookup(&block, std_src, block.namespace, decl_name) orelse {
33902 return sema.fail(&block, std_src, "'std' missing 'builtin'", .{});
33903 };
33904 const uncoerced_val = try sema.analyzeNavVal(&block, std_src, nav);
33905 const decl_src: LazySrcLoc = .{
33906 .base_node_inst = ip.getNav(nav).srcInst(ip),
33907 .offset = .nodeOffset(.zero),
33908 };
33909 break :ty try sema.analyzeAsType(&block, decl_src, .std_builtin_decl, uncoerced_val);
33910 };
33911
3387233912 var any_changed = false;
3387333913
3387433914 inline for (comptime std.enums.values(Zcu.BuiltinDecl)) |builtin_decl| {
3387533915 if (stage == comptime builtin_decl.stage()) {
33876 const parent_ns: Zcu.Namespace.Index, const parent_name: []const u8, const name: []const u8 = switch (comptime builtin_decl.access()) {
33877 .direct => |name| .{ builtin_namespace, "std.builtin", name },
33916 const parent_ns_ty: Type, const parent_name: []const u8, const name: []const u8 = switch (comptime builtin_decl.access()) {
33917 .direct => |name| .{ std_builtin_ty, "std.builtin", name },
3387833918 .nested => |nested| access: {
33879 const parent_ty: Type = .fromInterned(zcu.builtin_decl_values.get(nested[0]));
33880 const parent_ns = parent_ty.getNamespace(zcu).unwrap() orelse {
33881 return sema.fail(block, simple_src, "std.builtin.{s} is not a container type", .{@tagName(nested[0])});
33882 };
33883 break :access .{ parent_ns, "std.builtin." ++ @tagName(nested[0]), nested[1] };
33919 const parent_decl, const name = nested;
33920 const parent_ty: Type = .fromInterned(zcu.builtin_decl_values.get(parent_decl));
33921 break :access .{ parent_ty, "std.builtin." ++ @tagName(parent_decl), name };
3388433922 },
3388533923 };
3388633924
33925 const parent_ns = parent_ns_ty.getNamespace(zcu).unwrap() orelse {
33926 return sema.fail(&block, block.nodeOffset(.zero), "'{s}' is not a container type", .{parent_name});
33927 };
33928 const parent_ty_src = parent_ns_ty.srcLoc(zcu);
3388733929 const name_nts = try ip.getOrPutString(gpa, io, pt.tid, name, .no_embedded_nulls);
33888 const nav = try sema.namespaceLookup(block, simple_src, parent_ns, name_nts) orelse
33889 return sema.fail(block, simple_src, "{s} missing {s}", .{ parent_name, name });
33930 const nav = try sema.namespaceLookup(&block, parent_ty_src, parent_ns, name_nts) orelse {
33931 return sema.fail(&block, parent_ty_src, "'{s}' missing '{s}'", .{ parent_name, name });
33932 };
33933 const uncoerced_val = try sema.analyzeNavVal(&block, parent_ty_src, nav);
3389033934
33891 const src: LazySrcLoc = .{
33935 const decl_src: LazySrcLoc = .{
3389233936 .base_node_inst = ip.getNav(nav).srcInst(ip),
3389333937 .offset = .nodeOffset(.zero),
3389433938 };
3389533939
33896 const result = try sema.analyzeNavVal(block, src, nav);
33897
33898 const uncoerced_val = try sema.resolveConstDefinedValue(block, src, result, null);
3389933940 const val: Value = switch (builtin_decl.kind()) {
33900 .type => if (uncoerced_val.typeOf(zcu).zigTypeTag(zcu) != .type) {
33901 return sema.fail(block, src, "{s}.{s} is not a type", .{ parent_name, name });
33902 } else val: {
33903 try sema.ensureLayoutResolved(uncoerced_val.toType(), src);
33904 break :val uncoerced_val;
33941 .type => val: {
33942 const ty = try sema.analyzeAsType(&block, decl_src, .std_builtin_decl, uncoerced_val);
33943 try sema.ensureLayoutResolved(ty, decl_src);
33944 break :val ty.toValue();
3390533945 },
3390633946 .func => val: {
3390733947 const func_ty = try sema.getExpectedBuiltinFnType(builtin_decl);
33908 const coerced = try sema.coerce(block, func_ty, Air.internedToRef(uncoerced_val.toIntern()), src);
33909 break :val .fromInterned(coerced.toInterned().?);
33948 const coerced = try sema.coerce(&block, func_ty, uncoerced_val, decl_src);
33949 break :val try sema.resolveConstDefinedValue(&block, decl_src, coerced, .{ .simple = .std_builtin_decl });
3391033950 },
3391133951 .string => val: {
33912 const coerced = try sema.coerce(block, .slice_const_u8, Air.internedToRef(uncoerced_val.toIntern()), src);
33913 break :val .fromInterned(coerced.toInterned().?);
33952 const coerced = try sema.coerce(&block, .slice_const_u8, uncoerced_val, decl_src);
33953 break :val try sema.resolveConstDefinedValue(&block, decl_src, coerced, .{ .simple = .std_builtin_decl });
3391433954 },
3391533955 };
3391633956
33917 const prev = zcu.builtin_decl_values.get(builtin_decl);
33918 if (val.toIntern() != prev) {
33957 if (zcu.builtin_decl_values.get(builtin_decl) != val.toIntern()) {
3391933958 zcu.builtin_decl_values.set(builtin_decl, val.toIntern());
3392033959 any_changed = true;
3392133960 }
......@@ -34147,21 +34186,15 @@ fn zirStructDecl(
3414734186 });
3414834187 errdefer pt.destroyNamespace(new_namespace_index);
3414934188 try pt.scanNamespace(new_namespace_index, struct_decl.decls);
34150
3415134189 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
34152
3415334190 break :ty .fromInterned(wip.finish(ip, new_namespace_index));
3415434191 },
3415534192 };
3415634193
3415734194 try sema.addTypeReferenceEntry(src, ty);
34158
34159 // Make sure we update the namespace if the declaration is re-analyzed, to pick
34160 // up on e.g. changed comptime decls.
34161 // TODO MLUGG: me no likey, maybe model namespaces less badly idk
3416234195 try pt.ensureNamespaceUpToDate(ty.getNamespaceIndex(zcu));
3416334196
34164 return .fromIntern(ty.toIntern());
34197 return .fromType(ty);
3416534198}
3416634199fn zirUnionDecl(
3416734200 sema: *Sema,
......@@ -34218,7 +34251,6 @@ fn zirUnionDecl(
3421834251 .wip => |wip| ty: {
3421934252 errdefer wip.cancel(ip, pt.tid);
3422034253 try sema.setTypeName(block, &wip, union_decl.name_strategy, "union", inst);
34221
3422234254 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
3422334255 .parent = block.namespace.toOptional(),
3422434256 .owner_type = wip.index,
......@@ -34226,23 +34258,16 @@ fn zirUnionDecl(
3422634258 .generation = zcu.generation,
3422734259 });
3422834260 errdefer pt.destroyNamespace(new_namespace_index);
34229
3423034261 try pt.scanNamespace(new_namespace_index, union_decl.decls);
34231
3423234262 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
34233
3423434263 break :ty .fromInterned(wip.finish(ip, new_namespace_index));
3423534264 },
3423634265 };
3423734266
3423834267 try sema.addTypeReferenceEntry(src, ty);
34239
34240 // Make sure we update the namespace if the declaration is re-analyzed, to pick
34241 // up on e.g. changed comptime decls.
34242 // TODO MLUGG: me no likey, maybe model namespaces less badly idk
3424334268 try pt.ensureNamespaceUpToDate(ty.getNamespaceIndex(zcu));
3424434269
34245 return .fromIntern(ty.toIntern());
34270 return .fromType(ty);
3424634271}
3424734272fn zirEnumDecl(
3424834273 sema: *Sema,
......@@ -34277,9 +34302,7 @@ fn zirEnumDecl(
3427734302 .existing => |ty| .fromInterned(ty),
3427834303 .wip => |wip| ty: {
3427934304 errdefer wip.cancel(ip, pt.tid);
34280
3428134305 try sema.setTypeName(block, &wip, enum_decl.name_strategy, "enum", inst);
34282
3428334306 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
3428434307 .parent = block.namespace.toOptional(),
3428534308 .owner_type = wip.index,
......@@ -34287,23 +34310,16 @@ fn zirEnumDecl(
3428734310 .generation = zcu.generation,
3428834311 });
3428934312 errdefer pt.destroyNamespace(new_namespace_index);
34290
3429134313 try pt.scanNamespace(new_namespace_index, enum_decl.decls);
34292
3429334314 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
34294
3429534315 break :ty .fromInterned(wip.finish(ip, new_namespace_index));
3429634316 },
3429734317 };
3429834318
3429934319 try sema.addTypeReferenceEntry(src, ty);
34300
34301 // Make sure we update the namespace if the declaration is re-analyzed, to pick
34302 // up on e.g. changed comptime decls.
34303 // TODO MLUGG: me no likey, maybe model namespaces less badly idk
3430434320 try pt.ensureNamespaceUpToDate(ty.getNamespaceIndex(zcu));
3430534321
34306 return .fromIntern(ty.toIntern());
34322 return .fromType(ty);
3430734323}
3430834324fn zirOpaqueDecl(
3430934325 sema: *Sema,
......@@ -34350,11 +34366,7 @@ fn zirOpaqueDecl(
3435034366 };
3435134367
3435234368 try sema.addTypeReferenceEntry(src, ty);
34353
34354 // Make sure we update the namespace if the declaration is re-analyzed, to pick
34355 // up on e.g. changed comptime decls.
34356 // TODO MLUGG: me no likey, maybe model namespaces less badly idk
3435734369 try pt.ensureNamespaceUpToDate(ty.getNamespaceIndex(zcu));
3435834370
34359 return .fromIntern(ty.toIntern());
34371 return .fromType(ty);
3436034372}
src/Zcu/PerThread.zig+4-46
......@@ -688,6 +688,8 @@ pub fn ensureFileAnalyzed(pt: Zcu.PerThread, file_index: Zcu.File.Index) (Alloca
688688
689689 if (zcu.fileRootType(file_index) != .none) return; // already good
690690
691 if (zcu.comp.time_report) |*tr| tr.stats.n_imported_files += 1;
692
691693 const file = zcu.fileByIndex(file_index);
692694 assert(file.getMode() == .zig);
693695 const struct_decl = file.zir.?.getStructDecl(.main_struct_inst);
......@@ -719,13 +721,8 @@ pub fn ensureFileAnalyzed(pt: Zcu.PerThread, file_index: Zcu.File.Index) (Alloca
719721 });
720722 errdefer pt.destroyNamespace(new_namespace_index);
721723 try pt.scanNamespace(new_namespace_index, struct_decl.decls);
722
723724 if (zcu.comp.debugIncremental()) try zcu.incremental_debug_state.newType(zcu, wip.index);
724
725 const file_root_type: Type = .fromInterned(wip.finish(ip, new_namespace_index));
726
727 zcu.setFileRootType(file_index, file_root_type.toIntern());
728 if (zcu.comp.time_report) |*tr| tr.stats.n_imported_files += 1;
725 zcu.setFileRootType(file_index, wip.finish(ip, new_namespace_index));
729726}
730727
731728/// Ensures that all memoized state on `Zcu` is up-to-date, performing re-analysis if necessary.
......@@ -810,37 +807,14 @@ pub fn ensureMemoizedStateUpToDate(pt: Zcu.PerThread, stage: InternPool.Memoized
810807
811808fn analyzeMemoizedState(pt: Zcu.PerThread, stage: InternPool.MemoizedStateStage) Zcu.CompileError!bool {
812809 const zcu = pt.zcu;
813 const ip = &zcu.intern_pool;
814810 const comp = zcu.comp;
815811 const gpa = comp.gpa;
816 const io = comp.io;
817812
818813 const unit: AnalUnit = .wrap(.{ .memoized_state = stage });
819814
820815 try zcu.analysis_in_progress.putNoClobber(gpa, unit, {});
821816 defer assert(zcu.analysis_in_progress.swapRemove(unit));
822817
823 // Before we begin, collect:
824 // * The type `std`, and its namespace
825 // * The type `std.builtin`, and its namespace
826 // * A semi-reasonable source location
827 const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?;
828 try pt.ensureFileAnalyzed(std_file_index);
829 const std_type: Type = .fromInterned(zcu.fileRootType(std_file_index));
830 const std_namespace = std_type.getNamespaceIndex(zcu);
831 try pt.ensureNamespaceUpToDate(std_namespace);
832 const builtin_str = try ip.getOrPutString(gpa, io, pt.tid, "builtin", .no_embedded_nulls);
833 const builtin_nav = zcu.namespacePtr(std_namespace).pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse
834 @panic("lib/std.zig is corrupt and missing 'builtin'");
835 try pt.ensureNavValUpToDate(builtin_nav);
836 const builtin_type: Type = .fromInterned(ip.getNav(builtin_nav).status.fully_resolved.val);
837 const builtin_namespace = builtin_type.getNamespaceIndex(zcu);
838 try pt.ensureNamespaceUpToDate(builtin_namespace);
839 const src: Zcu.LazySrcLoc = .{
840 .base_node_inst = builtin_type.typeDeclInst(zcu).?,
841 .offset = .{ .byte_abs = 0 },
842 };
843
844818 var analysis_arena: std.heap.ArenaAllocator = .init(gpa);
845819 defer analysis_arena.deinit();
846820
......@@ -861,22 +835,7 @@ fn analyzeMemoizedState(pt: Zcu.PerThread, stage: InternPool.MemoizedStateStage)
861835 };
862836 defer sema.deinit();
863837
864 var block: Sema.Block = .{
865 .parent = null,
866 .sema = &sema,
867 .namespace = std_namespace,
868 .instructions = .empty,
869 .inlining = null,
870 .comptime_reason = .{ .reason = .{
871 .src = src,
872 .r = .{ .simple = .type },
873 } },
874 .src_base_inst = src.base_node_inst,
875 .type_name_ctx = .empty,
876 };
877 defer block.instructions.deinit(gpa);
878
879 return sema.analyzeMemoizedState(&block, src, builtin_namespace, stage);
838 return sema.analyzeMemoizedState(stage);
880839}
881840
882841/// Ensures that the state of the given `ComptimeUnit` is fully up-to-date, performing re-analysis
......@@ -1966,7 +1925,6 @@ fn analyzeFuncBody(
19661925/// If the file's root struct type is not populated (the file is unreferenced), nothing is done.
19671926/// This is called by `updateZirRefs` for all updated files before the main work loop.
19681927/// This function does not perform any semantic analysis.
1969/// MLUGG TODO: mmmmm i have no idea if this makes sense... tbhwy i just want to update all *changed* namespaces at the start of an update or something lol
19701928fn updateFileNamespace(pt: Zcu.PerThread, file_index: Zcu.File.Index) Allocator.Error!void {
19711929 const zcu = pt.zcu;
19721930