Skip to content

Commit

Permalink
compiler: move RuntimeIndex to Sema
Browse files Browse the repository at this point in the history
Just a small refactor.
  • Loading branch information
mlugg committed Dec 18, 2024
1 parent 12d64c4 commit 0722f86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
12 changes: 0 additions & 12 deletions src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -9788,7 +9778,6 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
OptionalNamespaceIndex,
MapIndex,
OptionalMapIndex,
RuntimeIndex,
String,
NullTerminatedString,
OptionalNullTerminatedString,
Expand Down Expand Up @@ -9852,7 +9841,6 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat
OptionalNamespaceIndex,
MapIndex,
OptionalMapIndex,
RuntimeIndex,
String,
NullTerminatedString,
OptionalNullTerminatedString,
Expand Down
16 changes: 13 additions & 3 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/Value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0722f86

Please sign in to comment.