Skip to content

Commit 450a57c

Browse files
committed
Update TryFinallyCatch to TryCatchOtherwise; fix StoreRange PE bug
1 parent e9ca64d commit 450a57c

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -4072,25 +4072,25 @@ public Void visit(StmtTy.Try node) {
40724072
* @formatter:off
40734073
* try {
40744074
* try_catch_else
4075-
* } finally {
4076-
* finally_body
40774075
* } catch uncaught_ex {
40784076
* save current exception
40794077
* set the current exception to uncaught_ex
40804078
* markCaught(uncaught_ex)
40814079
* try {
40824080
* finally_body
4083-
* } finally {
4084-
* restore current exception
40854081
* } catch handler_ex {
40864082
* restore current exception
40874083
* markCaught(handler_ex)
40884084
* reraise handler_ex
4085+
* } otherwise {
4086+
* restore current exception
40894087
* }
40904088
* reraise uncaught_ex
4089+
* } otherwise {
4090+
* finally_body
40914091
* }
40924092
*/
4093-
b.beginTryFinallyCatch(() -> {
4093+
b.beginTryCatchOtherwise(() -> {
40944094
b.beginBlock(); // finally
40954095
visitSequence(node.finalBody);
40964096
b.endBlock();
@@ -4107,7 +4107,7 @@ public Void visit(StmtTy.Try node) {
41074107
b.emitLoadException();
41084108
b.endMarkExceptionAsCaught();
41094109

4110-
b.beginTryFinallyCatch(() -> emitRestoreCurrentException(savedException));
4110+
b.beginTryCatchOtherwise(() -> emitRestoreCurrentException(savedException));
41114111
b.beginBlock(); // try
41124112
visitSequence(node.finalBody);
41134113
b.endBlock(); // try
@@ -4123,13 +4123,13 @@ public Void visit(StmtTy.Try node) {
41234123
b.emitLoadException();
41244124
b.endReraise();
41254125
b.endBlock(); // catch
4126-
b.endTryFinallyCatch();
4126+
b.endTryCatchOtherwise();
41274127

41284128
b.beginReraise();
41294129
b.emitLoadException();
41304130
b.endReraise();
41314131
b.endBlock(); // catch
4132-
b.endTryFinallyCatch();
4132+
b.endTryCatchOtherwise();
41334133
// @formatter:on
41344134
} else {
41354135
emitTryExceptElse(node);
@@ -4173,13 +4173,13 @@ private void emitTryExceptElse(StmtTy.Try node) {
41734173
* assign ex to handler_1_name
41744174
* try {
41754175
* handler_1_body
4176-
* } finally {
4177-
* unbind handler_1_name
41784176
* } catch handler_1_ex {
41794177
* unbind handler_1_name
41804178
* // Freeze the bci before it gets rethrown.
41814179
* markCaught(handler_ex)
41824180
* throw handler_1_ex
4181+
* } otherwise {
4182+
* unbind handler_1_name
41834183
* }
41844184
* goto afterElse
41854185
* }
@@ -4188,14 +4188,14 @@ private void emitTryExceptElse(StmtTy.Try node) {
41884188
* // case 1: bare except
41894189
* bare_except_body
41904190
* goto afterElse
4191-
* } finally {
4192-
* // Exception handled. Restore the exception state.
4193-
* restore current exception
41944191
* } catch handler_ex {
41954192
* // A handler raised or no handler was found. Restore exception state and reraise.
41964193
* restore current exception
41974194
* markCaught(handler_ex) // (no-op if handler_ex is the original exception)
41984195
* reraise handler_ex
4196+
* } otherwise {
4197+
* // Exception handled. Restore the exception state.
4198+
* restore current exception
41994199
* }
42004200
* // case 2: no bare except (we only reach this point if no handler matched/threw)
42014201
* reraise ex
@@ -4222,7 +4222,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
42224222
b.emitLoadException(); // ex
42234223
b.endMarkExceptionAsCaught();
42244224

4225-
b.beginTryFinallyCatch(() -> emitRestoreCurrentException(savedException));
4225+
b.beginTryCatchOtherwise(() -> emitRestoreCurrentException(savedException));
42264226
b.beginBlock(); // try
42274227
SourceRange bareExceptRange = null;
42284228
for (ExceptHandlerTy h : node.handlers) {
@@ -4252,7 +4252,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
42524252
b.endUnwrapException();
42534253
endStoreLocal(handler.name, b);
42544254

4255-
b.beginTryFinallyCatch(() -> emitUnbindHandlerVariable(handler));
4255+
b.beginTryCatchOtherwise(() -> emitUnbindHandlerVariable(handler));
42564256
b.beginBlock(); // try
42574257
visitSequence(handler.body);
42584258
b.endBlock(); // try
@@ -4268,7 +4268,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
42684268
b.emitLoadException(); // handler_i_ex
42694269
b.endThrow();
42704270
b.endBlock(); // catch
4271-
b.endTryFinallyCatch();
4271+
b.endTryCatchOtherwise();
42724272
} else { // bare except
42734273
b.beginBlock();
42744274
visitSequence(handler.body);
@@ -4298,7 +4298,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
42984298
b.emitLoadException(); // handler_ex
42994299
b.endReraise();
43004300
b.endBlock(); // catch
4301-
b.endTryFinallyCatch();
4301+
b.endTryCatchOtherwise();
43024302

43034303
/**
43044304
* Each handler branches to afterElse. If we reach this point and there was not a
@@ -4423,11 +4423,11 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
44234423
* try {
44244424
* x = value
44254425
* bar
4426-
* } finally {
4427-
* call __exit__(None, None, None)
44284426
* } catch ex {
44294427
* if not __exit__(...):
44304428
* raise
4429+
* } otherwise {
4430+
* call __exit__(None, None, None)
44314431
* }
44324432
* @formatter:on
44334433
*
@@ -4478,7 +4478,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
44784478
b.endContextManagerExit();
44794479
};
44804480
}
4481-
b.beginTryFinallyCatch(finallyHandler);
4481+
b.beginTryCatchOtherwise(finallyHandler);
44824482
b.beginBlock(); // try
44834483
if (item.optionalVars != null) {
44844484
item.optionalVars.accept(new StoreVisitor(() -> b.emitLoadLocal(value)));
@@ -4520,7 +4520,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
45204520
}
45214521
b.endBlock(); // catch
45224522

4523-
b.endTryFinallyCatch();
4523+
b.endTryCatchOtherwise();
45244524
b.endBlock();
45254525
endSourceSection(b, newStatement);
45264526
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3168,17 +3168,17 @@ public static void perform(VirtualFrame frame, LocalSetterRange locals, Object[]
31683168
@ExplodeLoop
31693169
private static void doExploded(VirtualFrame frame, LocalSetterRange locals, Object[] values,
31703170
BytecodeNode bytecode, int bci) {
3171-
CompilerAsserts.partialEvaluationConstant(values.length);
3171+
CompilerAsserts.partialEvaluationConstant(locals.getLength());
31723172
assert values.length == locals.getLength();
3173-
for (int i = 0; i < values.length; i++) {
3173+
for (int i = 0; i < locals.getLength(); i++) {
31743174
locals.setObject(bytecode, bci, frame, i, values[i]);
31753175
}
31763176
}
31773177

31783178
private static void doRegular(VirtualFrame frame, LocalSetterRange locals, Object[] values,
31793179
BytecodeNode bytecode, int bci) {
31803180
assert values.length == locals.getLength();
3181-
for (int i = 0; i < values.length; i++) {
3181+
for (int i = 0; i < locals.getLength(); i++) {
31823182
locals.setObject(bytecode, bci, frame, i, values[i]);
31833183
}
31843184
}

0 commit comments

Comments
 (0)