authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-17 23:59:30+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-18 20:34:10+00:00
log242bb4469547c322081ad15a84019486aedbc74d
tree0b416f181051c9d842b7a33e9eba137b5225d17c
parentf857bf72e2239718bbbe4cba08d6961ad77fc69a
signaturelock-open Commit is signed but in an unrecognized format.

compiler: move `RuntimeIndex` to `Sema`

Just a small refactor.

3 files changed, 13 insertions(+), 17 deletions(-)

src/InternPool.zig-12
......@@ -1462,16 +1462,6 @@ pub const MapIndex = enum(u32) {
14621462 }
14631463};
14641464
1465pub const RuntimeIndex = enum(u32) {
1466 zero = 0,
1467 comptime_field_ptr = std.math.maxInt(u32),
1468 _,
1469
1470 pub fn increment(ri: *RuntimeIndex) void {
1471 ri.* = @enumFromInt(@intFromEnum(ri.*) + 1);
1472 }
1473};
1474
14751465pub const ComptimeAllocIndex = enum(u32) { _ };
14761466
14771467pub const NamespaceIndex = enum(u32) {
......@@ -9788,7 +9778,6 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
97889778 OptionalNamespaceIndex,
97899779 MapIndex,
97909780 OptionalMapIndex,
9791 RuntimeIndex,
97929781 String,
97939782 NullTerminatedString,
97949783 OptionalNullTerminatedString,
......@@ -9852,7 +9841,6 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat
98529841 OptionalNamespaceIndex,
98539842 MapIndex,
98549843 OptionalMapIndex,
9855 RuntimeIndex,
98569844 String,
98579845 NullTerminatedString,
98589846 OptionalNullTerminatedString,
src/Sema.zig+13-3
......@@ -122,9 +122,19 @@ allow_memoize: bool = true,
122122/// This state is on `Sema` so that `cold` hints can be propagated up through blocks with less special handling.
123123branch_hint: ?std.builtin.BranchHint = null,
124124
125const RuntimeIndex = enum(u32) {
126 zero = 0,
127 comptime_field_ptr = std.math.maxInt(u32),
128 _,
129
130 pub fn increment(ri: *RuntimeIndex) void {
131 ri.* = @enumFromInt(@intFromEnum(ri.*) + 1);
132 }
133};
134
125135const MaybeComptimeAlloc = struct {
126136 /// The runtime index of the `alloc` instruction.
127 runtime_index: Value.RuntimeIndex,
137 runtime_index: RuntimeIndex,
128138 /// Backed by sema.arena. Tracks all comptime-known stores to this `alloc`. Due to
129139 /// RLS, a single comptime-known allocation may have arbitrarily many stores.
130140 /// This list also contains `set_union_tag`, `optional_payload_ptr_set`, and
......@@ -144,7 +154,7 @@ const ComptimeAlloc = struct {
144154 /// This is the `runtime_index` at the point of this allocation. If an store
145155 /// to this alloc ever occurs with a runtime index greater than this one, it
146156 /// is behind a runtime condition, so a compile error will be emitted.
147 runtime_index: Value.RuntimeIndex,
157 runtime_index: RuntimeIndex,
148158};
149159
150160fn newComptimeAlloc(sema: *Sema, block: *Block, ty: Type, alignment: Alignment) !ComptimeAllocIndex {
......@@ -364,7 +374,7 @@ pub const Block = struct {
364374 runtime_loop: ?LazySrcLoc = null,
365375 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
366376 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
367 runtime_index: Value.RuntimeIndex = .zero,
377 runtime_index: RuntimeIndex = .zero,
368378 inline_block: Zir.Inst.OptionalIndex = .none,
369379
370380 comptime_reason: ?*const ComptimeReason = null,
src/Value.zig-2
......@@ -3710,8 +3710,6 @@ pub fn makeBool(x: bool) Value {
37103710 return if (x) Value.true else Value.false;
37113711}
37123712
3713pub const RuntimeIndex = InternPool.RuntimeIndex;
3714
37153713/// `parent_ptr` must be a single-pointer to some optional.
37163714/// Returns a pointer to the payload of the optional.
37173715/// May perform type resolution.