@@ -28,6 +28,7 @@ span2_data: collections.SafeList(Span2), // Typed storage for (start, len) span
2828span_with_node_data : collections .SafeList (SpanWithNode ), // Typed storage for (start, len, node) triples
2929method_call_data : collections .SafeList (MethodCallData ), // Typed storage for method args plus method-token source region
3030match_data : collections .SafeList (MatchData ), // Typed storage for match expression data
31+ if_data : collections .SafeList (IfData ), // Typed storage for if expression data
3132match_branch_data : collections .SafeList (MatchBranchData ), // Typed storage for match branch data
3233closure_data : collections .SafeList (ClosureData ), // Typed storage for closure expressions
3334zero_arg_tag_data : collections .SafeList (ZeroArgTagData ), // Typed storage for zero-argument tags
@@ -73,6 +74,15 @@ pub const MatchData = extern struct {
7374 skip_exhaustiveness : u32 ,
7475};
7576
77+ /// If expression data.
78+ /// Stores branches span, final else, and whether to warn for untaken compile-time branches.
79+ pub const IfData = extern struct {
80+ branches_start : u32 ,
81+ branches_len : u32 ,
82+ final_else : u32 ,
83+ warn_unused_branches : u32 ,
84+ };
85+
7686/// Match branch data.
7787/// Stores patterns span, value, guard, and redundant flag.
7888pub const MatchBranchData = extern struct {
@@ -257,6 +267,8 @@ pub fn initCapacity(gpa: Allocator, capacity: usize) Allocator.Error!NodeStore {
257267 errdefer method_call_data .deinit (gpa );
258268 var match_data = try collections .SafeList (MatchData ).initCapacity (gpa , capacity / 8 );
259269 errdefer match_data .deinit (gpa );
270+ var if_data = try collections .SafeList (IfData ).initCapacity (gpa , capacity / 8 );
271+ errdefer if_data .deinit (gpa );
260272 var match_branch_data = try collections .SafeList (MatchBranchData ).initCapacity (gpa , capacity / 8 );
261273 errdefer match_branch_data .deinit (gpa );
262274 var closure_data = try collections .SafeList (ClosureData ).initCapacity (gpa , capacity / 16 );
@@ -285,6 +297,7 @@ pub fn initCapacity(gpa: Allocator, capacity: usize) Allocator.Error!NodeStore {
285297 .span_with_node_data = span_with_node_data ,
286298 .method_call_data = method_call_data ,
287299 .match_data = match_data ,
300+ .if_data = if_data ,
288301 .match_branch_data = match_branch_data ,
289302 .closure_data = closure_data ,
290303 .zero_arg_tag_data = zero_arg_tag_data ,
@@ -308,6 +321,7 @@ pub fn clone(self: *const NodeStore, gpa: Allocator) Allocator.Error!NodeStore {
308321 .span_with_node_data = try self .span_with_node_data .clone (gpa ),
309322 .method_call_data = try self .method_call_data .clone (gpa ),
310323 .match_data = try self .match_data .clone (gpa ),
324+ .if_data = try self .if_data .clone (gpa ),
311325 .match_branch_data = try self .match_branch_data .clone (gpa ),
312326 .closure_data = try self .closure_data .clone (gpa ),
313327 .zero_arg_tag_data = try self .zero_arg_tag_data .clone (gpa ),
@@ -331,6 +345,7 @@ pub fn deinit(store: *NodeStore) void {
331345 store .span_with_node_data .deinit (store .gpa );
332346 store .method_call_data .deinit (store .gpa );
333347 store .match_data .deinit (store .gpa );
348+ store .if_data .deinit (store .gpa );
334349 store .match_branch_data .deinit (store .gpa );
335350 store .closure_data .deinit (store .gpa );
336351 store .zero_arg_tag_data .deinit (store .gpa );
@@ -354,6 +369,7 @@ pub fn relocate(store: *NodeStore, offset: isize) void {
354369 store .span_with_node_data .relocate (offset );
355370 store .method_call_data .relocate (offset );
356371 store .match_data .relocate (offset );
372+ store .if_data .relocate (offset );
357373 store .match_branch_data .relocate (offset );
358374 store .closure_data .relocate (offset );
359375 store .zero_arg_tag_data .relocate (offset );
@@ -1034,12 +1050,12 @@ pub fn getExpr(store: *const NodeStore, expr: CIR.Expr.Idx) CIR.Expr {
10341050 },
10351051 .expr_if_then_else = > {
10361052 const p = payload .expr_if_then_else ;
1037- // Retrieve branches span and final_else from span_with_node_data
1038- const branches_else = store .span_with_node_data .items .items [p .branches_else_idx ];
1053+ const if_data = store .if_data .items .items [p .branches_else_idx ];
10391054
10401055 return CIR.Expr { .e_if = .{
1041- .branches = .{ .span = .{ .start = branches_else .start , .len = branches_else .len } },
1042- .final_else = @enumFromInt (branches_else .node ),
1056+ .branches = .{ .span = .{ .start = if_data .branches_start , .len = if_data .branches_len } },
1057+ .final_else = @enumFromInt (if_data .final_else ),
1058+ .warn_unused_branches = if_data .warn_unused_branches != 0 ,
10431059 } };
10441060 },
10451061 .expr_field_access = > {
@@ -2454,15 +2470,16 @@ pub fn addExpr(store: *NodeStore, expr: CIR.Expr, region: base.Region) Allocator
24542470 },
24552471 .e_if = > | e | {
24562472 node .tag = .expr_if_then_else ;
2457- const branches_else_idx : u32 = @intCast (store .span_with_node_data .len ());
2458- _ = try store .span_with_node_data .append (store .gpa , .{
2459- .start = e .branches .span .start ,
2460- .len = e .branches .span .len ,
2461- .node = @intFromEnum (e .final_else ),
2473+ const if_data_idx : u32 = @intCast (store .if_data .len ());
2474+ _ = try store .if_data .append (store .gpa , .{
2475+ .branches_start = e .branches .span .start ,
2476+ .branches_len = e .branches .span .len ,
2477+ .final_else = @intFromEnum (e .final_else ),
2478+ .warn_unused_branches = @intFromBool (e .warn_unused_branches ),
24622479 });
24632480
24642481 node .setPayload (.{ .expr_if_then_else = .{
2465- .branches_else_idx = branches_else_idx ,
2482+ .branches_else_idx = if_data_idx ,
24662483 } });
24672484 },
24682485 .e_call = > | e | {
@@ -4603,6 +4620,7 @@ pub const Serialized = extern struct {
46034620 span_with_node_data : collections .SafeList (SpanWithNode ).Serialized ,
46044621 method_call_data : collections .SafeList (MethodCallData ).Serialized ,
46054622 match_data : collections .SafeList (MatchData ).Serialized ,
4623+ if_data : collections .SafeList (IfData ).Serialized ,
46064624 match_branch_data : collections .SafeList (MatchBranchData ).Serialized ,
46074625 closure_data : collections .SafeList (ClosureData ).Serialized ,
46084626 zero_arg_tag_data : collections .SafeList (ZeroArgTagData ).Serialized ,
@@ -4634,6 +4652,8 @@ pub const Serialized = extern struct {
46344652 try self .method_call_data .serialize (& store .method_call_data , allocator , writer );
46354653 // Serialize match_data
46364654 try self .match_data .serialize (& store .match_data , allocator , writer );
4655+ // Serialize if_data
4656+ try self .if_data .serialize (& store .if_data , allocator , writer );
46374657 // Serialize match_branch_data
46384658 try self .match_branch_data .serialize (& store .match_branch_data , allocator , writer );
46394659 // Serialize closure_data
@@ -4666,6 +4686,7 @@ pub const Serialized = extern struct {
46664686 .span_with_node_data = self .span_with_node_data .deserializeInto (base_addr ),
46674687 .method_call_data = self .method_call_data .deserializeInto (base_addr ),
46684688 .match_data = self .match_data .deserializeInto (base_addr ),
4689+ .if_data = self .if_data .deserializeInto (base_addr ),
46694690 .match_branch_data = self .match_branch_data .deserializeInto (base_addr ),
46704691 .closure_data = self .closure_data .deserializeInto (base_addr ),
46714692 .zero_arg_tag_data = self .zero_arg_tag_data .deserializeInto (base_addr ),
@@ -4691,6 +4712,7 @@ pub const Serialized = extern struct {
46914712 .span_with_node_data = self .span_with_node_data .deserializeInto (base_addr ),
46924713 .method_call_data = self .method_call_data .deserializeInto (base_addr ),
46934714 .match_data = self .match_data .deserializeInto (base_addr ),
4715+ .if_data = self .if_data .deserializeInto (base_addr ),
46944716 .match_branch_data = self .match_branch_data .deserializeInto (base_addr ),
46954717 .closure_data = self .closure_data .deserializeInto (base_addr ),
46964718 .zero_arg_tag_data = self .zero_arg_tag_data .deserializeInto (base_addr ),
0 commit comments