@@ -812,7 +812,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr
812
812
813
813
.deref = > {
814
814
const lhs = try expr (gz , scope , .none , node_datas [node ].lhs );
815
- _ = try gz .addUnTok (.validate_deref , lhs , main_tokens [ node ] );
815
+ _ = try gz .addUnNode (.validate_deref , lhs , node );
816
816
switch (rl ) {
817
817
.ref = > return lhs ,
818
818
else = > {
@@ -1320,7 +1320,10 @@ fn arrayInitExpr(
1320
1320
const len_inst = try gz .addInt (array_init .ast .elements .len );
1321
1321
const elem_type = try typeExpr (gz , scope , array_type .ast .elem_type );
1322
1322
if (array_type .ast .sentinel == 0 ) {
1323
- const array_type_inst = try gz .addBin (.array_type , len_inst , elem_type );
1323
+ const array_type_inst = try gz .addPlNode (.array_type , array_init .ast .type_expr , Zir.Inst.Bin {
1324
+ .lhs = len_inst ,
1325
+ .rhs = elem_type ,
1326
+ });
1324
1327
break :inst .{
1325
1328
.array = array_type_inst ,
1326
1329
.elem = elem_type ,
@@ -1553,7 +1556,10 @@ fn structInitExpr(
1553
1556
if (is_inferred_array_len ) {
1554
1557
const elem_type = try typeExpr (gz , scope , array_type .ast .elem_type );
1555
1558
const array_type_inst = if (array_type .ast .sentinel == 0 ) blk : {
1556
- break :blk try gz .addBin (.array_type , .zero_usize , elem_type );
1559
+ break :blk try gz .addPlNode (.array_type , struct_init .ast .type_expr , Zir.Inst.Bin {
1560
+ .lhs = .zero_usize ,
1561
+ .rhs = elem_type ,
1562
+ });
1557
1563
} else blk : {
1558
1564
const sentinel = try comptimeExpr (gz , scope , .{ .ty = elem_type }, array_type .ast .sentinel );
1559
1565
break :blk try gz .addPlNode (
@@ -2332,8 +2338,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2332
2338
.error_union_type ,
2333
2339
.bit_not ,
2334
2340
.error_value ,
2335
- .error_to_int ,
2336
- .int_to_error ,
2337
2341
.slice_start ,
2338
2342
.slice_end ,
2339
2343
.slice_sentinel ,
@@ -2420,7 +2424,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2420
2424
.splat ,
2421
2425
.reduce ,
2422
2426
.shuffle ,
2423
- .select ,
2424
2427
.atomic_load ,
2425
2428
.atomic_rmw ,
2426
2429
.mul_add ,
@@ -2467,6 +2470,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2467
2470
.repeat ,
2468
2471
.repeat_inline ,
2469
2472
.panic ,
2473
+ .panic_comptime ,
2470
2474
= > {
2471
2475
noreturn_src_node = statement ;
2472
2476
break :b true ;
@@ -3100,6 +3104,10 @@ fn ptrType(
3100
3104
node : Ast.Node.Index ,
3101
3105
ptr_info : Ast.full.PtrType ,
3102
3106
) InnerError ! Zir.Inst.Ref {
3107
+ if (ptr_info .size == .C and ptr_info .allowzero_token != null ) {
3108
+ return gz .astgen .failTok (ptr_info .allowzero_token .? , "C pointers always allow address zero" , .{});
3109
+ }
3110
+
3103
3111
const elem_type = try typeExpr (gz , scope , ptr_info .ast .child_type );
3104
3112
3105
3113
const simple = ptr_info .ast .align_node == 0 and
@@ -3205,7 +3213,10 @@ fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) !Z
3205
3213
const len = try expr (gz , scope , .{ .coerced_ty = .usize_type }, len_node );
3206
3214
const elem_type = try typeExpr (gz , scope , node_datas [node ].rhs );
3207
3215
3208
- const result = try gz .addBin (.array_type , len , elem_type );
3216
+ const result = try gz .addPlNode (.array_type , node , Zir.Inst.Bin {
3217
+ .lhs = len ,
3218
+ .rhs = elem_type ,
3219
+ });
3209
3220
return rvalue (gz , rl , result , node );
3210
3221
}
3211
3222
@@ -7359,15 +7370,13 @@ fn builtinCall(
7359
7370
.align_of = > return simpleUnOpType (gz , scope , rl , node , params [0 ], .align_of ),
7360
7371
7361
7372
.ptr_to_int = > return simpleUnOp (gz , scope , rl , node , .none , params [0 ], .ptr_to_int ),
7362
- .error_to_int = > return simpleUnOp (gz , scope , rl , node , .none , params [0 ], .error_to_int ),
7363
- .int_to_error = > return simpleUnOp (gz , scope , rl , node , .{ .coerced_ty = .u16_type }, params [0 ], .int_to_error ),
7364
7373
.compile_error = > return simpleUnOp (gz , scope , rl , node , .{ .ty = .const_slice_u8_type }, params [0 ], .compile_error ),
7365
7374
.set_eval_branch_quota = > return simpleUnOp (gz , scope , rl , node , .{ .coerced_ty = .u32_type }, params [0 ], .set_eval_branch_quota ),
7366
7375
.enum_to_int = > return simpleUnOp (gz , scope , rl , node , .none , params [0 ], .enum_to_int ),
7367
7376
.bool_to_int = > return simpleUnOp (gz , scope , rl , node , bool_rl , params [0 ], .bool_to_int ),
7368
7377
.embed_file = > return simpleUnOp (gz , scope , rl , node , .{ .ty = .const_slice_u8_type }, params [0 ], .embed_file ),
7369
7378
.error_name = > return simpleUnOp (gz , scope , rl , node , .{ .ty = .anyerror_type }, params [0 ], .error_name ),
7370
- .panic = > return simpleUnOp (gz , scope , rl , node , .{ .ty = .const_slice_u8_type }, params [0 ], .panic ),
7379
+ .panic = > return simpleUnOp (gz , scope , rl , node , .{ .ty = .const_slice_u8_type }, params [0 ], if ( gz . force_comptime ) .panic_comptime else .panic ),
7371
7380
.set_cold = > return simpleUnOp (gz , scope , rl , node , bool_rl , params [0 ], .set_cold ),
7372
7381
.set_runtime_safety = > return simpleUnOp (gz , scope , rl , node , bool_rl , params [0 ], .set_runtime_safety ),
7373
7382
.sqrt = > return simpleUnOp (gz , scope , rl , node , .none , params [0 ], .sqrt ),
@@ -7400,6 +7409,22 @@ fn builtinCall(
7400
7409
.truncate = > return typeCast (gz , scope , rl , node , params [0 ], params [1 ], .truncate ),
7401
7410
// zig fmt: on
7402
7411
7412
+ .error_to_int = > {
7413
+ const operand = try expr (gz , scope , .none , params [0 ]);
7414
+ const result = try gz .addExtendedPayload (.error_to_int , Zir.Inst.UnNode {
7415
+ .node = gz .nodeIndexToRelative (node ),
7416
+ .operand = operand ,
7417
+ });
7418
+ return rvalue (gz , rl , result , node );
7419
+ },
7420
+ .int_to_error = > {
7421
+ const operand = try expr (gz , scope , .{ .coerced_ty = .u16_type }, params [0 ]);
7422
+ const result = try gz .addExtendedPayload (.int_to_error , Zir.Inst.UnNode {
7423
+ .node = gz .nodeIndexToRelative (node ),
7424
+ .operand = operand ,
7425
+ });
7426
+ return rvalue (gz , rl , result , node );
7427
+ },
7403
7428
.align_cast = > {
7404
7429
const dest_align = try comptimeExpr (gz , scope , align_rl , params [0 ]);
7405
7430
const rhs = try expr (gz , scope , .none , params [1 ]);
@@ -7639,7 +7664,8 @@ fn builtinCall(
7639
7664
return rvalue (gz , rl , result , node );
7640
7665
},
7641
7666
.select = > {
7642
- const result = try gz .addPlNode (.select , node , Zir.Inst.Select {
7667
+ const result = try gz .addExtendedPayload (.select , Zir.Inst.Select {
7668
+ .node = gz .nodeIndexToRelative (node ),
7643
7669
.elem_type = try typeExpr (gz , scope , params [0 ]),
7644
7670
.pred = try expr (gz , scope , .none , params [1 ]),
7645
7671
.a = try expr (gz , scope , .none , params [2 ]),
0 commit comments