| author | |
| committer | |
| log | 260c610708451624eab783bc4e99388e2b28a3ba |
| tree | 1ef81a5625b822807037d5044b1afac2df961054 |
| parent | 50010447bde42ca96aff63e0a620f941464f2eae |
Idea here is to prefer un_node to un_tok in order to avoid unnecessary
calls to `tree.firstToken`.3 files changed, 57 insertions(+), 66 deletions(-)
src/Sema.zig+9-9| ... | ... | @@ -1212,7 +1212,7 @@ fn zirOptionalType(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner |
| 1212 | 1212 | const tracy = trace(@src()); |
| 1213 | 1213 | defer tracy.end(); |
| 1214 | 1214 | |
| 1215 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 1215 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 1216 | 1216 | const src = inst_data.src(); |
| 1217 | 1217 | const child_type = try sema.resolveType(block, src, inst_data.operand); |
| 1218 | 1218 | const opt_type = try sema.mod.optionalType(sema.arena, child_type); |
| ... | ... | @@ -1224,7 +1224,7 @@ fn zirOptionalTypeFromPtrElem(sema: *Sema, block: *Scope.Block, inst: zir.Inst.I |
| 1224 | 1224 | const tracy = trace(@src()); |
| 1225 | 1225 | defer tracy.end(); |
| 1226 | 1226 | |
| 1227 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 1227 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 1228 | 1228 | const ptr = try sema.resolveInst(inst_data.operand); |
| 1229 | 1229 | const elem_ty = ptr.ty.elemType(); |
| 1230 | 1230 | const opt_ty = try sema.mod.optionalType(sema.arena, elem_ty); |
| ... | ... | @@ -1459,7 +1459,7 @@ fn zirOptionalPayloadPtr( |
| 1459 | 1459 | const tracy = trace(@src()); |
| 1460 | 1460 | defer tracy.end(); |
| 1461 | 1461 | |
| 1462 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 1462 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 1463 | 1463 | const optional_ptr = try sema.resolveInst(inst_data.operand); |
| 1464 | 1464 | assert(optional_ptr.ty.zigTypeTag() == .Pointer); |
| 1465 | 1465 | const src = inst_data.src(); |
| ... | ... | @@ -1502,7 +1502,7 @@ fn zirOptionalPayload( |
| 1502 | 1502 | const tracy = trace(@src()); |
| 1503 | 1503 | defer tracy.end(); |
| 1504 | 1504 | |
| 1505 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 1505 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 1506 | 1506 | const src = inst_data.src(); |
| 1507 | 1507 | const operand = try sema.resolveInst(inst_data.operand); |
| 1508 | 1508 | const opt_type = operand.ty; |
| ... | ... | @@ -1540,7 +1540,7 @@ fn zirErrUnionPayload( |
| 1540 | 1540 | const tracy = trace(@src()); |
| 1541 | 1541 | defer tracy.end(); |
| 1542 | 1542 | |
| 1543 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 1543 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 1544 | 1544 | const src = inst_data.src(); |
| 1545 | 1545 | const operand = try sema.resolveInst(inst_data.operand); |
| 1546 | 1546 | if (operand.ty.zigTypeTag() != .ErrorUnion) |
| ... | ... | @@ -1574,7 +1574,7 @@ fn zirErrUnionPayloadPtr( |
| 1574 | 1574 | const tracy = trace(@src()); |
| 1575 | 1575 | defer tracy.end(); |
| 1576 | 1576 | |
| 1577 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 1577 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 1578 | 1578 | const src = inst_data.src(); |
| 1579 | 1579 | const operand = try sema.resolveInst(inst_data.operand); |
| 1580 | 1580 | assert(operand.ty.zigTypeTag() == .Pointer); |
| ... | ... | @@ -1613,7 +1613,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inner |
| 1613 | 1613 | const tracy = trace(@src()); |
| 1614 | 1614 | defer tracy.end(); |
| 1615 | 1615 | |
| 1616 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 1616 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 1617 | 1617 | const src = inst_data.src(); |
| 1618 | 1618 | const operand = try sema.resolveInst(inst_data.operand); |
| 1619 | 1619 | if (operand.ty.zigTypeTag() != .ErrorUnion) |
| ... | ... | @@ -1637,7 +1637,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In |
| 1637 | 1637 | const tracy = trace(@src()); |
| 1638 | 1638 | defer tracy.end(); |
| 1639 | 1639 | |
| 1640 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 1640 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 1641 | 1641 | const src = inst_data.src(); |
| 1642 | 1642 | const operand = try sema.resolveInst(inst_data.operand); |
| 1643 | 1643 | assert(operand.ty.zigTypeTag() == .Pointer); |
| ... | ... | @@ -2710,7 +2710,7 @@ fn zirBoolNot(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError |
| 2710 | 2710 | const tracy = trace(@src()); |
| 2711 | 2711 | defer tracy.end(); |
| 2712 | 2712 | |
| 2713 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 2713 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 2714 | 2714 | const src = inst_data.src(); |
| 2715 | 2715 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 2716 | 2716 |
src/astgen.zig+21-30| ... | ... | @@ -376,8 +376,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 376 | 376 | |
| 377 | 377 | .negation => @panic("TODO"), |
| 378 | 378 | .negation_wrap => @panic("TODO"), |
| 379 | .bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node), node), | |
| 380 | .bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node), node), | |
| 379 | .bool_not => return boolNot(mod, scope, rl, node), | |
| 380 | .bit_not => return bitNot(mod, scope, rl, node), | |
| 381 | 381 | //.negation => return rvalue(mod, scope, rl, try negation(mod, scope, node, .sub)), |
| 382 | 382 | //.negation_wrap => return rvalue(mod, scope, rl, try negation(mod, scope, node, .subwrap)), |
| 383 | 383 | |
| ... | ... | @@ -466,27 +466,21 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 466 | 466 | return rvalue(mod, scope, rl, result, node); |
| 467 | 467 | }, |
| 468 | 468 | .optional_type => { |
| 469 | const src_token = tree.firstToken(node); | |
| 470 | ||
| 471 | 469 | const operand = try typeExpr(mod, scope, node_datas[node].lhs); |
| 472 | const result = try gz.addUnTok(.optional_type, operand, src_token); | |
| 470 | const result = try gz.addUnNode(.optional_type, operand, node); | |
| 473 | 471 | return rvalue(mod, scope, rl, result, node); |
| 474 | 472 | }, |
| 475 | .unwrap_optional => { | |
| 476 | const src_token = tree.firstToken(node); | |
| 477 | ||
| 478 | switch (rl) { | |
| 479 | .ref => return gz.addUnTok( | |
| 480 | .optional_payload_safe_ptr, | |
| 481 | try expr(mod, scope, .ref, node_datas[node].lhs), | |
| 482 | src_token, | |
| 483 | ), | |
| 484 | else => return rvalue(mod, scope, rl, try gz.addUnTok( | |
| 485 | .optional_payload_safe, | |
| 486 | try expr(mod, scope, .none, node_datas[node].lhs), | |
| 487 | src_token, | |
| 488 | ), node), | |
| 489 | } | |
| 473 | .unwrap_optional => switch (rl) { | |
| 474 | .ref => return gz.addUnNode( | |
| 475 | .optional_payload_safe_ptr, | |
| 476 | try expr(mod, scope, .ref, node_datas[node].lhs), | |
| 477 | node, | |
| 478 | ), | |
| 479 | else => return rvalue(mod, scope, rl, try gz.addUnNode( | |
| 480 | .optional_payload_safe, | |
| 481 | try expr(mod, scope, .none, node_datas[node].lhs), | |
| 482 | node, | |
| 483 | ), node), | |
| 490 | 484 | }, |
| 491 | 485 | .block_two, .block_two_semicolon => { |
| 492 | 486 | const statements = [2]ast.Node.Index{ node_datas[node].lhs, node_datas[node].rhs }; |
| ... | ... | @@ -1315,27 +1309,24 @@ fn assignOp( |
| 1315 | 1309 | _ = try addZIRBinOp(mod, scope, src, .store, lhs_ptr, result); |
| 1316 | 1310 | } |
| 1317 | 1311 | |
| 1318 | fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { | |
| 1312 | fn boolNot(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { | |
| 1319 | 1313 | const tree = scope.tree(); |
| 1320 | 1314 | const node_datas = tree.nodes.items(.data); |
| 1321 | const src_token = tree.firstToken(node); | |
| 1322 | ||
| 1323 | const gz = scope.getGenZir(); | |
| 1324 | 1315 | |
| 1325 | 1316 | const operand = try expr(mod, scope, .{ .ty = @enumToInt(zir.Const.bool_type) }, node_datas[node].lhs); |
| 1326 | ||
| 1327 | return gz.addUnTok(.bool_not, operand, src_token); | |
| 1317 | const gz = scope.getGenZir(); | |
| 1318 | const result = try gz.addUnNode(.bool_not, operand, node); | |
| 1319 | return rvalue(mod, scope, rl, result, node); | |
| 1328 | 1320 | } |
| 1329 | 1321 | |
| 1330 | fn bitNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { | |
| 1322 | fn bitNot(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { | |
| 1331 | 1323 | const tree = scope.tree(); |
| 1332 | 1324 | const node_datas = tree.nodes.items(.data); |
| 1333 | const src_token = tree.firstToken(node); | |
| 1334 | 1325 | |
| 1335 | 1326 | const gz = scope.getGenZir(); |
| 1336 | ||
| 1337 | 1327 | const operand = try expr(mod, scope, .none, node_datas[node].lhs); |
| 1338 | return gz.addUnTok(.bit_not, operand, src_token); | |
| 1328 | const result = try gz.addUnTok(.bit_not, operand, node); | |
| 1329 | return rvalue(mod, scope, rl, result, node); | |
| 1339 | 1330 | } |
| 1340 | 1331 | |
| 1341 | 1332 | fn negation( |
src/zir.zig+27-27| ... | ... | @@ -445,7 +445,7 @@ pub const Inst = struct { |
| 445 | 445 | /// The new result location pointer has an inferred type. |
| 446 | 446 | bitcast_result_ptr, |
| 447 | 447 | /// Bitwise NOT. `~` |
| 448 | /// uses `un_tok` | |
| 448 | /// Uses `un_node`. | |
| 449 | 449 | bit_not, |
| 450 | 450 | /// Bitwise OR. `|` |
| 451 | 451 | bit_or, |
| ... | ... | @@ -464,7 +464,7 @@ pub const Inst = struct { |
| 464 | 464 | /// Uses the `bin` field. |
| 465 | 465 | bool_and, |
| 466 | 466 | /// Boolean NOT. See also `bit_not`. |
| 467 | /// Uses the `un_tok` field. | |
| 467 | /// Uses the `un_node` field. | |
| 468 | 468 | bool_not, |
| 469 | 469 | /// Boolean OR. See also `bit_or`. |
| 470 | 470 | /// Uses the `bin` field. |
| ... | ... | @@ -749,57 +749,57 @@ pub const Inst = struct { |
| 749 | 749 | /// Bitwise XOR. `^` |
| 750 | 750 | xor, |
| 751 | 751 | /// Create an optional type '?T' |
| 752 | /// Uses the `un_tok` field. | |
| 752 | /// Uses the `un_node` field. | |
| 753 | 753 | optional_type, |
| 754 | 754 | /// Create an optional type '?T'. The operand is a pointer value. The optional type will |
| 755 | 755 | /// be the type of the pointer element, wrapped in an optional. |
| 756 | /// Uses the `un_tok` field. | |
| 756 | /// Uses the `un_node` field. | |
| 757 | 757 | optional_type_from_ptr_elem, |
| 758 | 758 | /// ?T => T with safety. |
| 759 | 759 | /// Given an optional value, returns the payload value, with a safety check that |
| 760 | 760 | /// the value is non-null. Used for `orelse`, `if` and `while`. |
| 761 | /// Uses the `un_tok` field. | |
| 761 | /// Uses the `un_node` field. | |
| 762 | 762 | optional_payload_safe, |
| 763 | 763 | /// ?T => T without safety. |
| 764 | 764 | /// Given an optional value, returns the payload value. No safety checks. |
| 765 | /// Uses the `un_tok` field. | |
| 765 | /// Uses the `un_node` field. | |
| 766 | 766 | optional_payload_unsafe, |
| 767 | 767 | /// *?T => *T with safety. |
| 768 | 768 | /// Given a pointer to an optional value, returns a pointer to the payload value, |
| 769 | 769 | /// with a safety check that the value is non-null. Used for `orelse`, `if` and `while`. |
| 770 | /// Uses the `un_tok` field. | |
| 770 | /// Uses the `un_node` field. | |
| 771 | 771 | optional_payload_safe_ptr, |
| 772 | 772 | /// *?T => *T without safety. |
| 773 | 773 | /// Given a pointer to an optional value, returns a pointer to the payload value. |
| 774 | 774 | /// No safety checks. |
| 775 | /// Uses the `un_tok` field. | |
| 775 | /// Uses the `un_node` field. | |
| 776 | 776 | optional_payload_unsafe_ptr, |
| 777 | 777 | /// E!T => T with safety. |
| 778 | 778 | /// Given an error union value, returns the payload value, with a safety check |
| 779 | 779 | /// that the value is not an error. Used for catch, if, and while. |
| 780 | /// Uses the `un_tok` field. | |
| 780 | /// Uses the `un_node` field. | |
| 781 | 781 | err_union_payload_safe, |
| 782 | 782 | /// E!T => T without safety. |
| 783 | 783 | /// Given an error union value, returns the payload value. No safety checks. |
| 784 | /// Uses the `un_tok` field. | |
| 784 | /// Uses the `un_node` field. | |
| 785 | 785 | err_union_payload_unsafe, |
| 786 | 786 | /// *E!T => *T with safety. |
| 787 | 787 | /// Given a pointer to an error union value, returns a pointer to the payload value, |
| 788 | 788 | /// with a safety check that the value is not an error. Used for catch, if, and while. |
| 789 | /// Uses the `un_tok` field. | |
| 789 | /// Uses the `un_node` field. | |
| 790 | 790 | err_union_payload_safe_ptr, |
| 791 | 791 | /// *E!T => *T without safety. |
| 792 | 792 | /// Given a pointer to a error union value, returns a pointer to the payload value. |
| 793 | 793 | /// No safety checks. |
| 794 | /// Uses the `un_tok` field. | |
| 794 | /// Uses the `un_node` field. | |
| 795 | 795 | err_union_payload_unsafe_ptr, |
| 796 | 796 | /// E!T => E without safety. |
| 797 | 797 | /// Given an error union value, returns the error code. No safety checks. |
| 798 | /// Uses the `un_tok` field. | |
| 798 | /// Uses the `un_node` field. | |
| 799 | 799 | err_union_code, |
| 800 | 800 | /// *E!T => E without safety. |
| 801 | 801 | /// Given a pointer to an error union value, returns the error code. No safety checks. |
| 802 | /// Uses the `un_tok` field. | |
| 802 | /// Uses the `un_node` field. | |
| 803 | 803 | err_union_code_ptr, |
| 804 | 804 | /// Takes a *E!T and raises a compiler error if T != void |
| 805 | 805 | /// Uses the `un_tok` field. |
| ... | ... | @@ -1326,6 +1326,7 @@ const Writer = struct { |
| 1326 | 1326 | .indexable_ptr_len, |
| 1327 | 1327 | .@"await", |
| 1328 | 1328 | .bit_not, |
| 1329 | .bool_not, | |
| 1329 | 1330 | .call_none, |
| 1330 | 1331 | .compile_error, |
| 1331 | 1332 | .deref_node, |
| ... | ... | @@ -1337,9 +1338,20 @@ const Writer = struct { |
| 1337 | 1338 | .set_eval_branch_quota, |
| 1338 | 1339 | .resolve_inferred_alloc, |
| 1339 | 1340 | .suspend_block_one, |
| 1341 | .optional_type, | |
| 1342 | .optional_type_from_ptr_elem, | |
| 1343 | .optional_payload_safe, | |
| 1344 | .optional_payload_unsafe, | |
| 1345 | .optional_payload_safe_ptr, | |
| 1346 | .optional_payload_unsafe_ptr, | |
| 1347 | .err_union_payload_safe, | |
| 1348 | .err_union_payload_unsafe, | |
| 1349 | .err_union_payload_safe_ptr, | |
| 1350 | .err_union_payload_unsafe_ptr, | |
| 1351 | .err_union_code, | |
| 1352 | .err_union_code_ptr, | |
| 1340 | 1353 | => try self.writeUnNode(stream, inst), |
| 1341 | 1354 | |
| 1342 | .bool_not, | |
| 1343 | 1355 | .break_void_tok, |
| 1344 | 1356 | .is_non_null, |
| 1345 | 1357 | .is_null, |
| ... | ... | @@ -1351,18 +1363,6 @@ const Writer = struct { |
| 1351 | 1363 | .ret_tok, |
| 1352 | 1364 | .ret_coerce, |
| 1353 | 1365 | .typeof, |
| 1354 | .optional_type, | |
| 1355 | .optional_type_from_ptr_elem, | |
| 1356 | .optional_payload_safe, | |
| 1357 | .optional_payload_unsafe, | |
| 1358 | .optional_payload_safe_ptr, | |
| 1359 | .optional_payload_unsafe_ptr, | |
| 1360 | .err_union_payload_safe, | |
| 1361 | .err_union_payload_unsafe, | |
| 1362 | .err_union_payload_safe_ptr, | |
| 1363 | .err_union_payload_unsafe_ptr, | |
| 1364 | .err_union_code, | |
| 1365 | .err_union_code_ptr, | |
| 1366 | 1366 | .ensure_err_payload_void, |
| 1367 | 1367 | => try self.writeUnTok(stream, inst), |
| 1368 | 1368 |