Skip to content

Commit

Permalink
Update TryFinallyCatch to TryCatchOtherwise; fix StoreRange PE bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DSouzaM committed Sep 30, 2024
1 parent e9ca64d commit 450a57c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4072,25 +4072,25 @@ public Void visit(StmtTy.Try node) {
* @formatter:off
* try {
* try_catch_else
* } finally {
* finally_body
* } catch uncaught_ex {
* save current exception
* set the current exception to uncaught_ex
* markCaught(uncaught_ex)
* try {
* finally_body
* } finally {
* restore current exception
* } catch handler_ex {
* restore current exception
* markCaught(handler_ex)
* reraise handler_ex
* } otherwise {
* restore current exception
* }
* reraise uncaught_ex
* } otherwise {
* finally_body
* }
*/
b.beginTryFinallyCatch(() -> {
b.beginTryCatchOtherwise(() -> {
b.beginBlock(); // finally
visitSequence(node.finalBody);
b.endBlock();
Expand All @@ -4107,7 +4107,7 @@ public Void visit(StmtTy.Try node) {
b.emitLoadException();
b.endMarkExceptionAsCaught();

b.beginTryFinallyCatch(() -> emitRestoreCurrentException(savedException));
b.beginTryCatchOtherwise(() -> emitRestoreCurrentException(savedException));
b.beginBlock(); // try
visitSequence(node.finalBody);
b.endBlock(); // try
Expand All @@ -4123,13 +4123,13 @@ public Void visit(StmtTy.Try node) {
b.emitLoadException();
b.endReraise();
b.endBlock(); // catch
b.endTryFinallyCatch();
b.endTryCatchOtherwise();

b.beginReraise();
b.emitLoadException();
b.endReraise();
b.endBlock(); // catch
b.endTryFinallyCatch();
b.endTryCatchOtherwise();
// @formatter:on
} else {
emitTryExceptElse(node);
Expand Down Expand Up @@ -4173,13 +4173,13 @@ private void emitTryExceptElse(StmtTy.Try node) {
* assign ex to handler_1_name
* try {
* handler_1_body
* } finally {
* unbind handler_1_name
* } catch handler_1_ex {
* unbind handler_1_name
* // Freeze the bci before it gets rethrown.
* markCaught(handler_ex)
* throw handler_1_ex
* } otherwise {
* unbind handler_1_name
* }
* goto afterElse
* }
Expand All @@ -4188,14 +4188,14 @@ private void emitTryExceptElse(StmtTy.Try node) {
* // case 1: bare except
* bare_except_body
* goto afterElse
* } finally {
* // Exception handled. Restore the exception state.
* restore current exception
* } catch handler_ex {
* // A handler raised or no handler was found. Restore exception state and reraise.
* restore current exception
* markCaught(handler_ex) // (no-op if handler_ex is the original exception)
* reraise handler_ex
* } otherwise {
* // Exception handled. Restore the exception state.
* restore current exception
* }
* // case 2: no bare except (we only reach this point if no handler matched/threw)
* reraise ex
Expand All @@ -4222,7 +4222,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
b.emitLoadException(); // ex
b.endMarkExceptionAsCaught();

b.beginTryFinallyCatch(() -> emitRestoreCurrentException(savedException));
b.beginTryCatchOtherwise(() -> emitRestoreCurrentException(savedException));
b.beginBlock(); // try
SourceRange bareExceptRange = null;
for (ExceptHandlerTy h : node.handlers) {
Expand Down Expand Up @@ -4252,7 +4252,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
b.endUnwrapException();
endStoreLocal(handler.name, b);

b.beginTryFinallyCatch(() -> emitUnbindHandlerVariable(handler));
b.beginTryCatchOtherwise(() -> emitUnbindHandlerVariable(handler));
b.beginBlock(); // try
visitSequence(handler.body);
b.endBlock(); // try
Expand All @@ -4268,7 +4268,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
b.emitLoadException(); // handler_i_ex
b.endThrow();
b.endBlock(); // catch
b.endTryFinallyCatch();
b.endTryCatchOtherwise();
} else { // bare except
b.beginBlock();
visitSequence(handler.body);
Expand Down Expand Up @@ -4298,7 +4298,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
b.emitLoadException(); // handler_ex
b.endReraise();
b.endBlock(); // catch
b.endTryFinallyCatch();
b.endTryCatchOtherwise();

/**
* Each handler branches to afterElse. If we reach this point and there was not a
Expand Down Expand Up @@ -4423,11 +4423,11 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
* try {
* x = value
* bar
* } finally {
* call __exit__(None, None, None)
* } catch ex {
* if not __exit__(...):
* raise
* } otherwise {
* call __exit__(None, None, None)
* }
* @formatter:on
*
Expand Down Expand Up @@ -4478,7 +4478,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
b.endContextManagerExit();
};
}
b.beginTryFinallyCatch(finallyHandler);
b.beginTryCatchOtherwise(finallyHandler);
b.beginBlock(); // try
if (item.optionalVars != null) {
item.optionalVars.accept(new StoreVisitor(() -> b.emitLoadLocal(value)));
Expand Down Expand Up @@ -4520,7 +4520,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
}
b.endBlock(); // catch

b.endTryFinallyCatch();
b.endTryCatchOtherwise();
b.endBlock();
endSourceSection(b, newStatement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3168,17 +3168,17 @@ public static void perform(VirtualFrame frame, LocalSetterRange locals, Object[]
@ExplodeLoop
private static void doExploded(VirtualFrame frame, LocalSetterRange locals, Object[] values,
BytecodeNode bytecode, int bci) {
CompilerAsserts.partialEvaluationConstant(values.length);
CompilerAsserts.partialEvaluationConstant(locals.getLength());
assert values.length == locals.getLength();
for (int i = 0; i < values.length; i++) {
for (int i = 0; i < locals.getLength(); i++) {
locals.setObject(bytecode, bci, frame, i, values[i]);
}
}

private static void doRegular(VirtualFrame frame, LocalSetterRange locals, Object[] values,
BytecodeNode bytecode, int bci) {
assert values.length == locals.getLength();
for (int i = 0; i < values.length; i++) {
for (int i = 0; i < locals.getLength(); i++) {
locals.setObject(bytecode, bci, frame, i, values[i]);
}
}
Expand Down

0 comments on commit 450a57c

Please sign in to comment.