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) {...@@ -1462,16 +1462,6 @@ pub const MapIndex = enum(u32) {
1462 }1462 }
1463};1463};
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
1475pub const ComptimeAllocIndex = enum(u32) { _ };1465pub const ComptimeAllocIndex = enum(u32) { _ };
14761466
1477pub const NamespaceIndex = enum(u32) {1467pub const NamespaceIndex = enum(u32) {
...@@ -9788,7 +9778,6 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {...@@ -9788,7 +9778,6 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
9788 OptionalNamespaceIndex,9778 OptionalNamespaceIndex,
9789 MapIndex,9779 MapIndex,
9790 OptionalMapIndex,9780 OptionalMapIndex,
9791 RuntimeIndex,
9792 String,9781 String,
9793 NullTerminatedString,9782 NullTerminatedString,
9794 OptionalNullTerminatedString,9783 OptionalNullTerminatedString,
...@@ -9852,7 +9841,6 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat...@@ -9852,7 +9841,6 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat
9852 OptionalNamespaceIndex,9841 OptionalNamespaceIndex,
9853 MapIndex,9842 MapIndex,
9854 OptionalMapIndex,9843 OptionalMapIndex,
9855 RuntimeIndex,
9856 String,9844 String,
9857 NullTerminatedString,9845 NullTerminatedString,
9858 OptionalNullTerminatedString,9846 OptionalNullTerminatedString,
src/Sema.zig+13-3
...@@ -122,9 +122,19 @@ allow_memoize: bool = true,...@@ -122,9 +122,19 @@ allow_memoize: bool = true,
122/// This state is on `Sema` so that `cold` hints can be propagated up through blocks with less special handling.122/// This state is on `Sema` so that `cold` hints can be propagated up through blocks with less special handling.
123branch_hint: ?std.builtin.BranchHint = null,123branch_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
125const MaybeComptimeAlloc = struct {135const MaybeComptimeAlloc = struct {
126 /// The runtime index of the `alloc` instruction.136 /// The runtime index of the `alloc` instruction.
127 runtime_index: Value.RuntimeIndex,137 runtime_index: RuntimeIndex,
128 /// Backed by sema.arena. Tracks all comptime-known stores to this `alloc`. Due to138 /// Backed by sema.arena. Tracks all comptime-known stores to this `alloc`. Due to
129 /// RLS, a single comptime-known allocation may have arbitrarily many stores.139 /// RLS, a single comptime-known allocation may have arbitrarily many stores.
130 /// This list also contains `set_union_tag`, `optional_payload_ptr_set`, and140 /// This list also contains `set_union_tag`, `optional_payload_ptr_set`, and
...@@ -144,7 +154,7 @@ const ComptimeAlloc = struct {...@@ -144,7 +154,7 @@ const ComptimeAlloc = struct {
144 /// This is the `runtime_index` at the point of this allocation. If an store154 /// This is the `runtime_index` at the point of this allocation. If an store
145 /// to this alloc ever occurs with a runtime index greater than this one, it155 /// to this alloc ever occurs with a runtime index greater than this one, it
146 /// is behind a runtime condition, so a compile error will be emitted.156 /// is behind a runtime condition, so a compile error will be emitted.
147 runtime_index: Value.RuntimeIndex,157 runtime_index: RuntimeIndex,
148};158};
149159
150fn newComptimeAlloc(sema: *Sema, block: *Block, ty: Type, alignment: Alignment) !ComptimeAllocIndex {160fn newComptimeAlloc(sema: *Sema, block: *Block, ty: Type, alignment: Alignment) !ComptimeAllocIndex {
...@@ -364,7 +374,7 @@ pub const Block = struct {...@@ -364,7 +374,7 @@ pub const Block = struct {
364 runtime_loop: ?LazySrcLoc = null,374 runtime_loop: ?LazySrcLoc = null,
365 /// Non zero if a non-inline loop or a runtime conditional have been encountered.375 /// Non zero if a non-inline loop or a runtime conditional have been encountered.
366 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.376 /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index.
367 runtime_index: Value.RuntimeIndex = .zero,377 runtime_index: RuntimeIndex = .zero,
368 inline_block: Zir.Inst.OptionalIndex = .none,378 inline_block: Zir.Inst.OptionalIndex = .none,
369379
370 comptime_reason: ?*const ComptimeReason = null,380 comptime_reason: ?*const ComptimeReason = null,
src/Value.zig-2
...@@ -3710,8 +3710,6 @@ pub fn makeBool(x: bool) Value {...@@ -3710,8 +3710,6 @@ pub fn makeBool(x: bool) Value {
3710 return if (x) Value.true else Value.false;3710 return if (x) Value.true else Value.false;
3711}3711}
37123712
3713pub const RuntimeIndex = InternPool.RuntimeIndex;
3714
3715/// `parent_ptr` must be a single-pointer to some optional.3713/// `parent_ptr` must be a single-pointer to some optional.
3716/// Returns a pointer to the payload of the optional.3714/// Returns a pointer to the payload of the optional.
3717/// May perform type resolution.3715/// May perform type resolution.