Skip to content

Refactor CIR regions to be in a separate array #7954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ test "NodeStore cache round-trip" {
.data_1 = 42,
.data_2 = 100,
.data_3 = 200,
.region = .{ .start = .{ .offset = 0 }, .end = .{ .offset = 10 } },
.tag = .expr_string,
};
const expr_idx = store.nodes.append(store.gpa, expr_node);
const region = base.Region{ .start = .{ .offset = 0 }, .end = .{ .offset = 10 } };
_ = store.regions.append(store.gpa, region);

try store.extra_data.append(store.gpa, 1234);
try store.extra_data.append(store.gpa, 5678);
Expand Down
118 changes: 41 additions & 77 deletions src/check/canonicalize.zig

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/check/canonicalize/CIR.zig
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ fn formatPatternIdxNode(gpa: std.mem.Allocator, pattern_idx: Pattern.Idx) SExpr
return node;
}

test "Node is 24 bytes" {
try testing.expectEqual(24, @sizeOf(Node));
test "Node is 16 bytes" {
try testing.expectEqual(16, @sizeOf(Node));
}

/// A working representation of a record field
Expand Down Expand Up @@ -710,7 +710,7 @@ pub const Def = struct {

var node = SExpr.init(gpa, kind);

var pattern_node = ir.store.getPattern(self.pattern).toSExpr(ir);
var pattern_node = ir.store.getPattern(self.pattern).toSExpr(ir, self.pattern);
node.appendNode(gpa, &pattern_node);

var expr_node = ir.store.getExpr(self.expr).toSExpr(ir);
Expand Down Expand Up @@ -1075,10 +1075,10 @@ pub fn toSexprTypes(ir: *CIR, maybe_expr_idx: ?Expr.Idx, source: []const u8) SEx
// Extract identifier name from the pattern (assuming it's an assign pattern)
const pattern = ir.store.getPattern(def.pattern);
switch (pattern) {
.assign => |assign_pat| {
.assign => |_| {
var def_node = SExpr.init(gpa, "patt");

ir.appendRegionInfoToSexprNodeFromRegion(&def_node, assign_pat.region);
ir.appendRegionInfoToSexprNode(&def_node, def_idx);

// Get the type variable for this definition
// Each definition has a type_var at its node index which represents the type of the definition
Expand Down
4 changes: 2 additions & 2 deletions src/check/canonicalize/Expression.zig
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ pub const Expr = union(enum) {
// Handle args span
var args_node = SExpr.init(gpa, "args");
for (ir.store.slicePatterns(lambda_expr.args)) |arg_idx| {
var pattern_node = ir.store.getPattern(arg_idx).toSExpr(ir);
var pattern_node = ir.store.getPattern(arg_idx).toSExpr(ir, arg_idx);
args_node.appendNode(gpa, &pattern_node);
}
node.appendNode(gpa, &args_node);
Expand Down Expand Up @@ -837,7 +837,7 @@ pub const Expr = union(enum) {
for (patterns_slice) |branch_pat_idx| {
const branch_pat = ir.store.getMatchBranchPattern(branch_pat_idx);
const pattern = ir.store.getPattern(branch_pat.pattern);
var pattern_sexpr = pattern.toSExpr(ir);
var pattern_sexpr = pattern.toSExpr(ir, branch_pat.pattern);
pattern_sexpr.appendBoolAttr(gpa, "degenerate", branch_pat.degenerate);
patterns_node.appendNode(gpa, &pattern_sexpr);
}
Expand Down
1 change: 0 additions & 1 deletion src/check/canonicalize/Node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const collections = @import("../../collections.zig");
data_1: u32,
data_2: u32,
data_3: u32,
region: base.Region,
tag: Tag,

/// A list of nodes.
Expand Down
Loading
Loading