Commit 242bb44695

mlugg <mlugg@mlugg.co.uk>
2024-12-18 00:59:30
compiler: move `RuntimeIndex` to `Sema`
Just a small refactor.
1 parent f857bf7
Changed files (3)
src/InternPool.zig
@@ -1462,16 +1462,6 @@ pub const MapIndex = enum(u32) {
     }
 };
 
-pub const RuntimeIndex = enum(u32) {
-    zero = 0,
-    comptime_field_ptr = std.math.maxInt(u32),
-    _,
-
-    pub fn increment(ri: *RuntimeIndex) void {
-        ri.* = @enumFromInt(@intFromEnum(ri.*) + 1);
-    }
-};
-
 pub const ComptimeAllocIndex = enum(u32) { _ };
 
 pub const NamespaceIndex = enum(u32) {
@@ -9788,7 +9778,6 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
             OptionalNamespaceIndex,
             MapIndex,
             OptionalMapIndex,
-            RuntimeIndex,
             String,
             NullTerminatedString,
             OptionalNullTerminatedString,
@@ -9852,7 +9841,6 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat
             OptionalNamespaceIndex,
             MapIndex,
             OptionalMapIndex,
-            RuntimeIndex,
             String,
             NullTerminatedString,
             OptionalNullTerminatedString,
src/Sema.zig
@@ -122,9 +122,19 @@ allow_memoize: bool = true,
 /// This state is on `Sema` so that `cold` hints can be propagated up through blocks with less special handling.
 branch_hint: ?std.builtin.BranchHint = null,
 
+const RuntimeIndex = enum(u32) {
+    zero = 0,
+    comptime_field_ptr = std.math.maxInt(u32),
+    _,
+
+    pub fn increment(ri: *RuntimeIndex) void {
+        ri.* = @enumFromInt(@intFromEnum(ri.*) + 1);
+    }
+};
+
 const MaybeComptimeAlloc = struct {
     /// The runtime index of the `alloc` instruction.
-    runtime_index: Value.RuntimeIndex,
+    runtime_index: RuntimeIndex,
     /// Backed by sema.arena. Tracks all comptime-known stores to this `alloc`. Due to
     /// RLS, a single comptime-known allocation may have arbitrarily many stores.
     /// This list also contains `set_union_tag`, `optional_payload_ptr_set`, and
@@ -144,7 +154,7 @@ const ComptimeAlloc = struct {
     /// This is the `runtime_index` at the point of this allocation. If an store
     /// to this alloc ever occurs with a runtime index greater than this one, it
     /// is behind a runtime condition, so a compile error will be emitted.
-    runtime_index: Value.RuntimeIndex,
+    runtime_index: RuntimeIndex,
 };
 
 fn newComptimeAlloc(sema: *Sema, block: *Block, ty: Type, alignment: Alignment) !ComptimeAllocIndex {
@@ -364,7 +374,7 @@ pub const Block = struct {
     runtime_loop: ?LazySrcLoc = null,
     /// Non zero if a non-inline loop or a runtime conditional have been encountered.
     /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
-    runtime_index: Value.RuntimeIndex = .zero,
+    runtime_index: RuntimeIndex = .zero,
     inline_block: Zir.Inst.OptionalIndex = .none,
 
     comptime_reason: ?*const ComptimeReason = null,
src/Value.zig
@@ -3710,8 +3710,6 @@ pub fn makeBool(x: bool) Value {
     return if (x) Value.true else Value.false;
 }
 
-pub const RuntimeIndex = InternPool.RuntimeIndex;
-
 /// `parent_ptr` must be a single-pointer to some optional.
 /// Returns a pointer to the payload of the optional.
 /// May perform type resolution.