| author | |
| committer | |
| log | 252388eb28fde40f085e14cd341efdc701093fe1 |
| tree | c14f6b026b1b193b9e1034e3c705e3b9c94ab7cd |
| parent | c9006d9479c619d9ed555164831e11a04d88d382 |
4 files changed, 58 insertions(+), 53 deletions(-)
src/AstGen.zig+18-6| ... | ... | @@ -2332,8 +2332,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2332 | 2332 | .error_union_type, |
| 2333 | 2333 | .bit_not, |
| 2334 | 2334 | .error_value, |
| 2335 | .error_to_int, | |
| 2336 | .int_to_error, | |
| 2337 | 2335 | .slice_start, |
| 2338 | 2336 | .slice_end, |
| 2339 | 2337 | .slice_sentinel, |
| ... | ... | @@ -2420,7 +2418,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2420 | 2418 | .splat, |
| 2421 | 2419 | .reduce, |
| 2422 | 2420 | .shuffle, |
| 2423 | .select, | |
| 2424 | 2421 | .atomic_load, |
| 2425 | 2422 | .atomic_rmw, |
| 2426 | 2423 | .mul_add, |
| ... | ... | @@ -7355,8 +7352,6 @@ fn builtinCall( |
| 7355 | 7352 | .align_of => return simpleUnOpType(gz, scope, rl, node, params[0], .align_of), |
| 7356 | 7353 | |
| 7357 | 7354 | .ptr_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .ptr_to_int), |
| 7358 | .error_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .error_to_int), | |
| 7359 | .int_to_error => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u16_type }, params[0], .int_to_error), | |
| 7360 | 7355 | .compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error), |
| 7361 | 7356 | .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u32_type }, params[0], .set_eval_branch_quota), |
| 7362 | 7357 | .enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int), |
| ... | ... | @@ -7396,6 +7391,22 @@ fn builtinCall( |
| 7396 | 7391 | .truncate => return typeCast(gz, scope, rl, node, params[0], params[1], .truncate), |
| 7397 | 7392 | // zig fmt: on |
| 7398 | 7393 | |
| 7394 | .error_to_int => { | |
| 7395 | const operand = try expr(gz, scope, .none, params[0]); | |
| 7396 | const result = try gz.addExtendedPayload(.error_to_int, Zir.Inst.UnNode{ | |
| 7397 | .node = gz.nodeIndexToRelative(node), | |
| 7398 | .operand = operand, | |
| 7399 | }); | |
| 7400 | return rvalue(gz, rl, result, node); | |
| 7401 | }, | |
| 7402 | .int_to_error => { | |
| 7403 | const operand = try expr(gz, scope, .{ .coerced_ty = .u16_type }, params[0]); | |
| 7404 | const result = try gz.addExtendedPayload(.int_to_error, Zir.Inst.UnNode{ | |
| 7405 | .node = gz.nodeIndexToRelative(node), | |
| 7406 | .operand = operand, | |
| 7407 | }); | |
| 7408 | return rvalue(gz, rl, result, node); | |
| 7409 | }, | |
| 7399 | 7410 | .align_cast => { |
| 7400 | 7411 | const dest_align = try comptimeExpr(gz, scope, align_rl, params[0]); |
| 7401 | 7412 | const rhs = try expr(gz, scope, .none, params[1]); |
| ... | ... | @@ -7635,7 +7646,8 @@ fn builtinCall( |
| 7635 | 7646 | return rvalue(gz, rl, result, node); |
| 7636 | 7647 | }, |
| 7637 | 7648 | .select => { |
| 7638 | const result = try gz.addPlNode(.select, node, Zir.Inst.Select{ | |
| 7649 | const result = try gz.addExtendedPayload(.select, Zir.Inst.Select{ | |
| 7650 | .node = gz.nodeIndexToRelative(node), | |
| 7639 | 7651 | .elem_type = try typeExpr(gz, scope, params[0]), |
| 7640 | 7652 | .pred = try expr(gz, scope, .none, params[1]), |
| 7641 | 7653 | .a = try expr(gz, scope, .none, params[2]), |
src/Sema.zig+23-24| ... | ... | @@ -739,8 +739,6 @@ fn analyzeBodyInner( |
| 739 | 739 | .err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false), |
| 740 | 740 | .error_union_type => try sema.zirErrorUnionType(block, inst), |
| 741 | 741 | .error_value => try sema.zirErrorValue(block, inst), |
| 742 | .error_to_int => try sema.zirErrorToInt(block, inst), | |
| 743 | .int_to_error => try sema.zirIntToError(block, inst), | |
| 744 | 742 | .field_ptr => try sema.zirFieldPtr(block, inst), |
| 745 | 743 | .field_ptr_named => try sema.zirFieldPtrNamed(block, inst), |
| 746 | 744 | .field_val => try sema.zirFieldVal(block, inst), |
| ... | ... | @@ -835,7 +833,6 @@ fn analyzeBodyInner( |
| 835 | 833 | .splat => try sema.zirSplat(block, inst), |
| 836 | 834 | .reduce => try sema.zirReduce(block, inst), |
| 837 | 835 | .shuffle => try sema.zirShuffle(block, inst), |
| 838 | .select => try sema.zirSelect(block, inst), | |
| 839 | 836 | .atomic_load => try sema.zirAtomicLoad(block, inst), |
| 840 | 837 | .atomic_rmw => try sema.zirAtomicRmw(block, inst), |
| 841 | 838 | .mul_add => try sema.zirMulAdd(block, inst), |
| ... | ... | @@ -942,6 +939,9 @@ fn analyzeBodyInner( |
| 942 | 939 | .field_call_bind_named => try sema.zirFieldCallBindNamed(block, extended), |
| 943 | 940 | .err_set_cast => try sema.zirErrSetCast( block, extended), |
| 944 | 941 | .await_nosuspend => try sema.zirAwaitNosuspend( block, extended), |
| 942 | .select => try sema.zirSelect( block, extended), | |
| 943 | .error_to_int => try sema.zirErrorToInt( block, extended), | |
| 944 | .int_to_error => try sema.zirIntToError( block, extended), | |
| 945 | 945 | // zig fmt: on |
| 946 | 946 | .fence => { |
| 947 | 947 | try sema.zirFence(block, extended); |
| ... | ... | @@ -6240,18 +6240,18 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 6240 | 6240 | ); |
| 6241 | 6241 | } |
| 6242 | 6242 | |
| 6243 | fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 6243 | fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | |
| 6244 | 6244 | const tracy = trace(@src()); |
| 6245 | 6245 | defer tracy.end(); |
| 6246 | 6246 | |
| 6247 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 6248 | const src = inst_data.src(); | |
| 6249 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 6250 | const op = try sema.resolveInst(inst_data.operand); | |
| 6251 | const op_coerced = try sema.coerce(block, Type.anyerror, op, operand_src); | |
| 6247 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | |
| 6248 | const src = LazySrcLoc.nodeOffset(extra.node); | |
| 6249 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | |
| 6250 | const uncasted_operand = try sema.resolveInst(extra.operand); | |
| 6251 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); | |
| 6252 | 6252 | const result_ty = Type.u16; |
| 6253 | 6253 | |
| 6254 | if (try sema.resolveMaybeUndefVal(block, src, op_coerced)) |val| { | |
| 6254 | if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| { | |
| 6255 | 6255 | if (val.isUndef()) { |
| 6256 | 6256 | return sema.addConstUndef(result_ty); |
| 6257 | 6257 | } |
| ... | ... | @@ -6273,7 +6273,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 6273 | 6273 | } |
| 6274 | 6274 | } |
| 6275 | 6275 | |
| 6276 | const op_ty = sema.typeOf(op); | |
| 6276 | const op_ty = sema.typeOf(uncasted_operand); | |
| 6277 | 6277 | try sema.resolveInferredErrorSetTy(block, src, op_ty); |
| 6278 | 6278 | if (!op_ty.isAnyError()) { |
| 6279 | 6279 | const names = op_ty.errorSetNames(); |
| ... | ... | @@ -6285,17 +6285,17 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 6285 | 6285 | } |
| 6286 | 6286 | |
| 6287 | 6287 | try sema.requireRuntimeBlock(block, src); |
| 6288 | return block.addBitCast(result_ty, op_coerced); | |
| 6288 | return block.addBitCast(result_ty, operand); | |
| 6289 | 6289 | } |
| 6290 | 6290 | |
| 6291 | fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 6291 | fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | |
| 6292 | 6292 | const tracy = trace(@src()); |
| 6293 | 6293 | defer tracy.end(); |
| 6294 | 6294 | |
| 6295 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 6296 | const src = inst_data.src(); | |
| 6297 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 6298 | const uncasted_operand = try sema.resolveInst(inst_data.operand); | |
| 6295 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | |
| 6296 | const src = LazySrcLoc.nodeOffset(extra.node); | |
| 6297 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | |
| 6298 | const uncasted_operand = try sema.resolveInst(extra.operand); | |
| 6299 | 6299 | const operand = try sema.coerce(block, Type.u16, uncasted_operand, operand_src); |
| 6300 | 6300 | const target = sema.mod.getTarget(); |
| 6301 | 6301 | |
| ... | ... | @@ -16703,14 +16703,13 @@ fn analyzeShuffle( |
| 16703 | 16703 | }); |
| 16704 | 16704 | } |
| 16705 | 16705 | |
| 16706 | fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 16707 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 16708 | const extra = sema.code.extraData(Zir.Inst.Select, inst_data.payload_index).data; | |
| 16706 | fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | |
| 16707 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; | |
| 16709 | 16708 | |
| 16710 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 16711 | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | |
| 16712 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | |
| 16713 | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | |
| 16709 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | |
| 16710 | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | |
| 16711 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; | |
| 16712 | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node }; | |
| 16714 | 16713 | |
| 16715 | 16714 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 16716 | 16715 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
src/Zir.zig+10-16| ... | ... | @@ -778,10 +778,6 @@ pub const Inst = struct { |
| 778 | 778 | /// Implement builtin `@ptrToInt`. Uses `un_node`. |
| 779 | 779 | /// Convert a pointer to a `usize` integer. |
| 780 | 780 | ptr_to_int, |
| 781 | /// Implement builtin `@errToInt`. Uses `un_node`. | |
| 782 | error_to_int, | |
| 783 | /// Implement builtin `@intToError`. Uses `un_node`. | |
| 784 | int_to_error, | |
| 785 | 781 | /// Emit an error message and fail compilation. |
| 786 | 782 | /// Uses the `un_node` field. |
| 787 | 783 | compile_error, |
| ... | ... | @@ -916,9 +912,6 @@ pub const Inst = struct { |
| 916 | 912 | /// Implements the `@shuffle` builtin. |
| 917 | 913 | /// Uses the `pl_node` union field with payload `Shuffle`. |
| 918 | 914 | shuffle, |
| 919 | /// Implements the `@select` builtin. | |
| 920 | /// Uses the `pl_node` union field with payload `Select`. | |
| 921 | select, | |
| 922 | 915 | /// Implements the `@atomicLoad` builtin. |
| 923 | 916 | /// Uses the `pl_node` union field with payload `AtomicLoad`. |
| 924 | 917 | atomic_load, |
| ... | ... | @@ -1125,8 +1118,6 @@ pub const Inst = struct { |
| 1125 | 1118 | .err_union_payload_unsafe_ptr, |
| 1126 | 1119 | .err_union_code, |
| 1127 | 1120 | .err_union_code_ptr, |
| 1128 | .error_to_int, | |
| 1129 | .int_to_error, | |
| 1130 | 1121 | .ptr_type, |
| 1131 | 1122 | .ptr_type_simple, |
| 1132 | 1123 | .ensure_err_payload_void, |
| ... | ... | @@ -1230,7 +1221,6 @@ pub const Inst = struct { |
| 1230 | 1221 | .splat, |
| 1231 | 1222 | .reduce, |
| 1232 | 1223 | .shuffle, |
| 1233 | .select, | |
| 1234 | 1224 | .atomic_load, |
| 1235 | 1225 | .atomic_rmw, |
| 1236 | 1226 | .atomic_store, |
| ... | ... | @@ -1423,8 +1413,6 @@ pub const Inst = struct { |
| 1423 | 1413 | .err_union_payload_unsafe_ptr, |
| 1424 | 1414 | .err_union_code, |
| 1425 | 1415 | .err_union_code_ptr, |
| 1426 | .error_to_int, | |
| 1427 | .int_to_error, | |
| 1428 | 1416 | .ptr_type, |
| 1429 | 1417 | .ptr_type_simple, |
| 1430 | 1418 | .enum_literal, |
| ... | ... | @@ -1516,7 +1504,6 @@ pub const Inst = struct { |
| 1516 | 1504 | .splat, |
| 1517 | 1505 | .reduce, |
| 1518 | 1506 | .shuffle, |
| 1519 | .select, | |
| 1520 | 1507 | .atomic_load, |
| 1521 | 1508 | .atomic_rmw, |
| 1522 | 1509 | .mul_add, |
| ... | ... | @@ -1731,8 +1718,6 @@ pub const Inst = struct { |
| 1731 | 1718 | .bit_size_of = .un_node, |
| 1732 | 1719 | |
| 1733 | 1720 | .ptr_to_int = .un_node, |
| 1734 | .error_to_int = .un_node, | |
| 1735 | .int_to_error = .un_node, | |
| 1736 | 1721 | .compile_error = .un_node, |
| 1737 | 1722 | .set_eval_branch_quota = .un_node, |
| 1738 | 1723 | .enum_to_int = .un_node, |
| ... | ... | @@ -1802,7 +1787,6 @@ pub const Inst = struct { |
| 1802 | 1787 | .splat = .pl_node, |
| 1803 | 1788 | .reduce = .pl_node, |
| 1804 | 1789 | .shuffle = .pl_node, |
| 1805 | .select = .pl_node, | |
| 1806 | 1790 | .atomic_load = .pl_node, |
| 1807 | 1791 | .atomic_rmw = .pl_node, |
| 1808 | 1792 | .atomic_store = .pl_node, |
| ... | ... | @@ -1971,6 +1955,15 @@ pub const Inst = struct { |
| 1971 | 1955 | await_nosuspend, |
| 1972 | 1956 | /// `operand` is `src_node: i32`. |
| 1973 | 1957 | breakpoint, |
| 1958 | /// Implements the `@select` builtin. | |
| 1959 | /// operand` is payload index to `Select`. | |
| 1960 | select, | |
| 1961 | /// Implement builtin `@errToInt`. | |
| 1962 | /// `operand` is payload index to `UnNode`. | |
| 1963 | error_to_int, | |
| 1964 | /// Implement builtin `@intToError`. | |
| 1965 | /// `operand` is payload index to `UnNode`. | |
| 1966 | int_to_error, | |
| 1974 | 1967 | |
| 1975 | 1968 | pub const InstData = struct { |
| 1976 | 1969 | opcode: Extended, |
| ... | ... | @@ -3448,6 +3441,7 @@ pub const Inst = struct { |
| 3448 | 3441 | }; |
| 3449 | 3442 | |
| 3450 | 3443 | pub const Select = struct { |
| 3444 | node: i32, | |
| 3451 | 3445 | elem_type: Ref, |
| 3452 | 3446 | pred: Ref, |
| 3453 | 3447 | a: Ref, |
src/print_zir.zig+7-7| ... | ... | @@ -189,8 +189,6 @@ const Writer = struct { |
| 189 | 189 | .typeof_log2_int_type, |
| 190 | 190 | .log2_int_type, |
| 191 | 191 | .ptr_to_int, |
| 192 | .error_to_int, | |
| 193 | .int_to_error, | |
| 194 | 192 | .compile_error, |
| 195 | 193 | .set_eval_branch_quota, |
| 196 | 194 | .enum_to_int, |
| ... | ... | @@ -284,7 +282,6 @@ const Writer = struct { |
| 284 | 282 | .memcpy => try self.writeMemcpy(stream, inst), |
| 285 | 283 | .memset => try self.writeMemset(stream, inst), |
| 286 | 284 | .shuffle => try self.writeShuffle(stream, inst), |
| 287 | .select => try self.writeSelect(stream, inst), | |
| 288 | 285 | .mul_add => try self.writeMulAdd(stream, inst), |
| 289 | 286 | .field_parent_ptr => try self.writeFieldParentPtr(stream, inst), |
| 290 | 287 | .builtin_call => try self.writeBuiltinCall(stream, inst), |
| ... | ... | @@ -478,6 +475,8 @@ const Writer = struct { |
| 478 | 475 | .compile_log => try self.writeNodeMultiOp(stream, extended), |
| 479 | 476 | .typeof_peer => try self.writeTypeofPeer(stream, extended), |
| 480 | 477 | |
| 478 | .select => try self.writeSelect(stream, extended), | |
| 479 | ||
| 481 | 480 | .add_with_overflow, |
| 482 | 481 | .sub_with_overflow, |
| 483 | 482 | .mul_with_overflow, |
| ... | ... | @@ -496,6 +495,8 @@ const Writer = struct { |
| 496 | 495 | .set_float_mode, |
| 497 | 496 | .set_align_stack, |
| 498 | 497 | .wasm_memory_size, |
| 498 | .error_to_int, | |
| 499 | .int_to_error, | |
| 499 | 500 | => { |
| 500 | 501 | const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 501 | 502 | const src = LazySrcLoc.nodeOffset(inst_data.node); |
| ... | ... | @@ -772,9 +773,8 @@ const Writer = struct { |
| 772 | 773 | try self.writeSrc(stream, inst_data.src()); |
| 773 | 774 | } |
| 774 | 775 | |
| 775 | fn writeSelect(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | |
| 776 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; | |
| 777 | const extra = self.code.extraData(Zir.Inst.Select, inst_data.payload_index).data; | |
| 776 | fn writeSelect(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | |
| 777 | const extra = self.code.extraData(Zir.Inst.Select, extended.operand).data; | |
| 778 | 778 | try self.writeInstRef(stream, extra.elem_type); |
| 779 | 779 | try stream.writeAll(", "); |
| 780 | 780 | try self.writeInstRef(stream, extra.pred); |
| ... | ... | @@ -783,7 +783,7 @@ const Writer = struct { |
| 783 | 783 | try stream.writeAll(", "); |
| 784 | 784 | try self.writeInstRef(stream, extra.b); |
| 785 | 785 | try stream.writeAll(") "); |
| 786 | try self.writeSrc(stream, inst_data.src()); | |
| 786 | try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node)); | |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |