|
283 | 283 | import com.oracle.truffle.api.exception.AbstractTruffleException; |
284 | 284 | import com.oracle.truffle.api.frame.Frame; |
285 | 285 | import com.oracle.truffle.api.frame.FrameDescriptor; |
| 286 | +import com.oracle.truffle.api.frame.FrameSlotTypeException; |
286 | 287 | import com.oracle.truffle.api.frame.MaterializedFrame; |
287 | 288 | import com.oracle.truffle.api.frame.VirtualFrame; |
288 | 289 | import com.oracle.truffle.api.nodes.DirectCallNode; |
@@ -3537,72 +3538,57 @@ static void doInteropException(AbstractTruffleException exception) { |
3537 | 3538 | * This operation makes use of Truffle's boxing overloads. When an operation tries to quicken |
3538 | 3539 | * this one for boxing elimination, the correct overload will be selected. |
3539 | 3540 | */ |
3540 | | - @Operation(storeBytecodeIndex = true) |
| 3541 | + @Operation(storeBytecodeIndex = false) |
3541 | 3542 | @ConstantOperand(type = LocalAccessor.class) |
3542 | 3543 | @ConstantOperand(type = int.class) |
3543 | 3544 | public static final class CheckAndLoadLocal { |
3544 | | - @Specialization(rewriteOn = UnexpectedResultException.class) |
| 3545 | + @Specialization(rewriteOn = {FrameSlotTypeException.class, UnexpectedResultException.class}) |
3545 | 3546 | public static int doInt(VirtualFrame frame, LocalAccessor accessor, int index, |
3546 | | - @Bind PBytecodeDSLRootNode rootNode, |
3547 | | - @Bind BytecodeNode bytecodeNode, |
3548 | | - @Bind Node inliningTarget, |
3549 | | - @Shared @Cached InlinedBranchProfile localUnboundProfile) throws UnexpectedResultException { |
3550 | | - if (accessor.isCleared(bytecodeNode, frame)) { |
3551 | | - localUnboundProfile.enter(inliningTarget); |
3552 | | - throw raiseUnbound(rootNode, inliningTarget, index); |
3553 | | - } |
| 3547 | + @Bind BytecodeNode bytecodeNode) throws UnexpectedResultException { |
3554 | 3548 | return accessor.getInt(bytecodeNode, frame); |
3555 | 3549 | } |
3556 | 3550 |
|
3557 | | - @Specialization(rewriteOn = UnexpectedResultException.class) |
3558 | | - public static boolean doBoolean(VirtualFrame frame, LocalAccessor accessor, int index, |
3559 | | - @Bind PBytecodeDSLRootNode rootNode, |
3560 | | - @Bind BytecodeNode bytecodeNode, |
3561 | | - @Bind Node inliningTarget, |
3562 | | - @Shared @Cached InlinedBranchProfile localUnboundProfile) throws UnexpectedResultException { |
3563 | | - if (accessor.isCleared(bytecodeNode, frame)) { |
3564 | | - localUnboundProfile.enter(inliningTarget); |
3565 | | - throw raiseUnbound(rootNode, inliningTarget, index); |
3566 | | - } |
3567 | | - return accessor.getBoolean(bytecodeNode, frame); |
| 3551 | + @Specialization(replaces = "doInt", rewriteOn = FrameSlotTypeException.class) |
| 3552 | + public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int index, |
| 3553 | + @Bind BytecodeNode bytecodeNode) { |
| 3554 | + return accessor.getObject(bytecodeNode, frame); |
3568 | 3555 | } |
3569 | 3556 |
|
3570 | | - @Specialization(replaces = {"doInt", "doBoolean"}) |
3571 | | - public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int index, |
3572 | | - @Bind PBytecodeDSLRootNode rootNode, |
3573 | | - @Bind BytecodeNode bytecodeNode, |
3574 | | - @Bind Node inliningTarget, |
3575 | | - @Shared @Cached InlinedBranchProfile localUnboundProfile) { |
3576 | | - if (accessor.isCleared(bytecodeNode, frame)) { |
3577 | | - localUnboundProfile.enter(inliningTarget); |
3578 | | - throw raiseUnbound(rootNode, inliningTarget, index); |
| 3557 | + @StoreBytecodeIndex |
| 3558 | + @Specialization(replaces = "doObject") |
| 3559 | + public static Object doObjectOrUnbound(VirtualFrame frame, LocalAccessor accessor, int index, |
| 3560 | + @Bind BytecodeNode bytecodeNode) { |
| 3561 | + try { |
| 3562 | + return accessor.getObject(bytecodeNode, frame); |
| 3563 | + } catch (FrameSlotTypeException e) { |
| 3564 | + throw raiseUnbound(bytecodeNode, index); |
3579 | 3565 | } |
3580 | | - return accessor.getObject(bytecodeNode, frame); |
3581 | 3566 | } |
3582 | 3567 | } |
3583 | 3568 |
|
3584 | | - @Operation(storeBytecodeIndex = true) |
| 3569 | + @Operation(storeBytecodeIndex = false) |
3585 | 3570 | @ConstantOperand(type = LocalAccessor.class) |
3586 | 3571 | @ConstantOperand(type = int.class) |
3587 | 3572 | public static final class DeleteLocal { |
3588 | | - @Specialization |
| 3573 | + |
| 3574 | + @Specialization(guards = "!accessor.isCleared(bytecodeNode, frame)") |
3589 | 3575 | public static void doObject(VirtualFrame frame, LocalAccessor accessor, int index, |
3590 | | - @Bind PBytecodeDSLRootNode rootNode, |
3591 | | - @Bind BytecodeNode bytecodeNode, |
3592 | | - @Bind Node inliningTarget, |
3593 | | - @Cached InlinedBranchProfile localUnboundProfile) { |
3594 | | - if (accessor.isCleared(bytecodeNode, frame)) { |
3595 | | - localUnboundProfile.enter(inliningTarget); |
3596 | | - throw raiseUnbound(rootNode, inliningTarget, index); |
3597 | | - } |
| 3576 | + @Bind BytecodeNode bytecodeNode) { |
3598 | 3577 | accessor.clear(bytecodeNode, frame); |
3599 | 3578 | } |
| 3579 | + |
| 3580 | + @StoreBytecodeIndex |
| 3581 | + @Fallback |
| 3582 | + public static void doFallback(VirtualFrame frame, LocalAccessor accessor, int index, |
| 3583 | + @Bind BytecodeNode bytecodeNode) { |
| 3584 | + throw raiseUnbound(bytecodeNode, index); |
| 3585 | + } |
3600 | 3586 | } |
3601 | 3587 |
|
3602 | 3588 | @TruffleBoundary |
3603 | | - private static PException raiseUnbound(PBytecodeDSLRootNode rootNode, Node inliningTarget, int index) { |
3604 | | - TruffleString localName = rootNode.getCodeUnit().varnames[index]; |
3605 | | - throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, localName); |
| 3589 | + private static PException raiseUnbound(BytecodeNode bytecodeNode, int index) { |
| 3590 | + TruffleString localName = ((PBytecodeDSLRootNode) bytecodeNode.getRootNode()).getCodeUnit().varnames[index]; |
| 3591 | + throw PRaiseNode.raiseStatic(bytecodeNode, PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, localName); |
3606 | 3592 | } |
3607 | 3593 |
|
3608 | 3594 | @Operation(storeBytecodeIndex = true) |
|
0 commit comments