Skip to content

Commit b8af234

Browse files
committed
Use @StoreBytecodeIndex for specializations raising unbound local error
1 parent ee13457 commit b8af234

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
import com.oracle.truffle.api.exception.AbstractTruffleException;
284284
import com.oracle.truffle.api.frame.Frame;
285285
import com.oracle.truffle.api.frame.FrameDescriptor;
286+
import com.oracle.truffle.api.frame.FrameSlotTypeException;
286287
import com.oracle.truffle.api.frame.MaterializedFrame;
287288
import com.oracle.truffle.api.frame.VirtualFrame;
288289
import com.oracle.truffle.api.nodes.DirectCallNode;
@@ -291,6 +292,7 @@
291292
import com.oracle.truffle.api.nodes.RootNode;
292293
import com.oracle.truffle.api.nodes.UnexpectedResultException;
293294
import com.oracle.truffle.api.object.DynamicObject;
295+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
294296
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
295297
import com.oracle.truffle.api.source.Source;
296298
import com.oracle.truffle.api.source.SourceSection;
@@ -3545,59 +3547,57 @@ static void doInteropException(AbstractTruffleException exception) {
35453547
* This operation makes use of Truffle's boxing overloads. When an operation tries to quicken
35463548
* this one for boxing elimination, the correct overload will be selected.
35473549
*/
3548-
@Operation(storeBytecodeIndex = true)
3550+
@Operation(storeBytecodeIndex = false)
35493551
@ConstantOperand(type = LocalAccessor.class)
35503552
@ConstantOperand(type = int.class)
35513553
public static final class CheckAndLoadLocal {
3552-
3553-
@Specialization(rewriteOn = UnexpectedResultException.class)
3554+
@Specialization(rewriteOn = {FrameSlotTypeException.class, UnexpectedResultException.class})
35543555
public static int doInt(VirtualFrame frame, LocalAccessor accessor, int index,
35553556
@Bind BytecodeNode bytecodeNode) throws UnexpectedResultException {
35563557
return accessor.getInt(bytecodeNode, frame);
35573558
}
35583559

3559-
@Specialization(rewriteOn = UnexpectedResultException.class)
3560-
public static boolean doBoolean(VirtualFrame frame, LocalAccessor accessor, int index,
3561-
@Bind BytecodeNode bytecodeNode) throws UnexpectedResultException {
3562-
return accessor.getBoolean(bytecodeNode, frame);
3563-
}
3564-
3565-
@Specialization(replaces = {"doInt", "doBoolean"}, guards = "!accessor.isCleared(bytecodeNode, frame)")
3560+
@Specialization(replaces = "doInt", rewriteOn = FrameSlotTypeException.class)
35663561
public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int index,
35673562
@Bind BytecodeNode bytecodeNode) {
35683563
return accessor.getObject(bytecodeNode, frame);
35693564
}
35703565

3571-
@Fallback
3572-
public static Object doFallback(VirtualFrame frame, LocalAccessor accessor, int index,
3573-
@Bind BytecodeNode bytecodeNode, @Bind Node inliningTarget) {
3574-
throw raiseUnbound(bytecodeNode, inliningTarget, index);
3566+
@StoreBytecodeIndex
3567+
@Specialization(replaces = "doObject")
3568+
public static Object doObjectOrUnbound(VirtualFrame frame, LocalAccessor accessor, int index,
3569+
@Bind BytecodeNode bytecodeNode) {
3570+
try {
3571+
return accessor.getObject(bytecodeNode, frame);
3572+
} catch (FrameSlotTypeException e) {
3573+
throw raiseUnbound(bytecodeNode, index);
3574+
}
35753575
}
35763576
}
35773577

3578-
@Operation(storeBytecodeIndex = true)
3578+
@Operation(storeBytecodeIndex = false)
35793579
@ConstantOperand(type = LocalAccessor.class)
35803580
@ConstantOperand(type = int.class)
35813581
public static final class DeleteLocal {
35823582

35833583
@Specialization(guards = "!accessor.isCleared(bytecodeNode, frame)")
35843584
public static void doObject(VirtualFrame frame, LocalAccessor accessor, int index,
3585-
@Bind BytecodeNode bytecodeNode,
3586-
@Bind Node inliningTarget) {
3585+
@Bind BytecodeNode bytecodeNode) {
35873586
accessor.clear(bytecodeNode, frame);
35883587
}
35893588

3589+
@StoreBytecodeIndex
35903590
@Fallback
35913591
public static void doFallback(VirtualFrame frame, LocalAccessor accessor, int index,
3592-
@Bind BytecodeNode bytecodeNode, @Bind Node inliningTarget) {
3593-
throw raiseUnbound(bytecodeNode, inliningTarget, index);
3592+
@Bind BytecodeNode bytecodeNode) {
3593+
throw raiseUnbound(bytecodeNode, index);
35943594
}
35953595
}
35963596

35973597
@TruffleBoundary
3598-
private static PException raiseUnbound(BytecodeNode bytecodeNode, Node inliningTarget, int index) {
3598+
private static PException raiseUnbound(BytecodeNode bytecodeNode, int index) {
35993599
TruffleString localName = ((PBytecodeDSLRootNode) bytecodeNode.getRootNode()).getCodeUnit().varnames[index];
3600-
throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, localName);
3600+
throw PRaiseNode.raiseStatic(bytecodeNode, PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, localName);
36013601
}
36023602

36033603
@Operation(storeBytecodeIndex = true)

0 commit comments

Comments
 (0)