From c4c7282aa6b84b47e7ab41a202eeb934b44a96a4 Mon Sep 17 00:00:00 2001 From: Matt D'Souza Date: Fri, 5 Jul 2024 11:28:29 -0400 Subject: [PATCH] Remove BytecodeLocal argument from TryCatch/FinallyTryCatch --- .../bytecode_dsl/RootNodeCompiler.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java index 7c1bfdc80f..9ff6ebc9f5 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java @@ -2263,8 +2263,7 @@ public void emitYieldFrom(Runnable generatorOrCoroutineProducer) { b.beginBlock(); BytecodeLabel loopEnd = b.createLabel(); // Step 2: yield yieldValue to the caller - BytecodeLocal thrownException = b.createLocal(); - b.beginTryCatch(thrownException); + b.beginTryCatch(); // try clause: yield b.beginStoreLocal(sentValue); @@ -2275,7 +2274,7 @@ public void emitYieldFrom(Runnable generatorOrCoroutineProducer) { b.beginIfThenElse(); b.beginYieldFromThrow(yieldValue, returnValue); b.emitLoadLocal(generator); - b.emitLoadLocal(thrownException); + b.emitLoadException(); b.endYieldFromThrow(); // StopIteration was raised; go to the end. @@ -4043,9 +4042,7 @@ public Void visit(StmtTy.Try node) { * reraise uncaught_ex * } */ - BytecodeLocal uncaughtException = b.createLocal(); - BytecodeLocal handlerException = b.createLocal(); - b.beginFinallyTryCatch(uncaughtException, () -> { + b.beginFinallyTryCatch(() -> { b.beginBlock(); // finally visitSequence(node.finalBody); b.endBlock(); @@ -4056,32 +4053,32 @@ public Void visit(StmtTy.Try node) { b.beginBlock(); // catch BytecodeLocal savedException = b.createLocal(); emitSaveCurrentException(savedException); - emitSetCurrentException(uncaughtException); + emitSetCurrentException(); // Mark this location for the stack trace. b.beginMarkExceptionAsCaught(); - b.emitLoadLocal(uncaughtException); + b.emitLoadException(); b.endMarkExceptionAsCaught(); - b.beginFinallyTryCatch(handlerException, () -> emitSetCurrentException(savedException)); + b.beginFinallyTryCatch(() -> emitRestoreCurrentException(savedException)); b.beginBlock(); // try visitSequence(node.finalBody); b.endBlock(); // try b.beginBlock(); // catch - emitSetCurrentException(savedException); + emitRestoreCurrentException(savedException); b.beginMarkExceptionAsCaught(); - b.emitLoadLocal(handlerException); + b.emitLoadException(); b.endMarkExceptionAsCaught(); b.beginReraise(); - b.emitLoadLocal(handlerException); + b.emitLoadException(); b.endReraise(); b.endBlock(); // catch b.endFinallyTryCatch(); b.beginReraise(); - b.emitLoadLocal(uncaughtException); + b.emitLoadException(); b.endReraise(); b.endBlock(); // catch b.endFinallyTryCatch(); @@ -4130,11 +4127,11 @@ private void emitTryExceptElse(StmtTy.Try node) { * handler_1_body * } finally { * unbind handler_1_name - * } catch handler_ex { + * } catch handler_1_ex { * unbind handler_1_name * // Freeze the bci before it gets rethrown. * markCaught(handler_ex) - * throw handler_ex + * throw handler_1_ex * } * goto afterElse * } @@ -4160,11 +4157,10 @@ private void emitTryExceptElse(StmtTy.Try node) { */ b.beginBlock(); // outermost block - BytecodeLocal exception = b.createLocal(); BytecodeLocal savedException = b.createLocal(); BytecodeLabel afterElse = b.createLabel(); - b.beginTryCatch(exception); + b.beginTryCatch(); b.beginBlock(); // try visitSequence(node.body); @@ -4172,14 +4168,13 @@ private void emitTryExceptElse(StmtTy.Try node) { b.beginBlock(); // catch emitSaveCurrentException(savedException); - emitSetCurrentException(exception); + emitSetCurrentException(); // Mark this location for the stack trace. b.beginMarkExceptionAsCaught(); - b.emitLoadLocal(exception); + b.emitLoadException(); // ex b.endMarkExceptionAsCaught(); - BytecodeLocal handlerException = b.createLocal(); - b.beginFinallyTryCatch(handlerException, () -> emitSetCurrentException(savedException)); + b.beginFinallyTryCatch(() -> emitRestoreCurrentException(savedException)); b.beginBlock(); // try SourceRange bareExceptRange = null; for (ExceptHandlerTy h : node.handlers) { @@ -4192,7 +4187,7 @@ private void emitTryExceptElse(StmtTy.Try node) { if (handler.type != null) { b.beginIfThen(); b.beginExceptMatch(); - b.emitLoadLocal(exception); + b.emitLoadException(); // ex handler.type.accept(this); b.endExceptMatch(); } else { @@ -4205,11 +4200,11 @@ private void emitTryExceptElse(StmtTy.Try node) { // Assign exception to handler name. beginStoreLocal(handler.name, b); b.beginUnwrapException(); - b.emitLoadLocal(exception); + b.emitLoadException(); // ex b.endUnwrapException(); endStoreLocal(handler.name, b); - b.beginFinallyTryCatch(handlerException, () -> emitUnbindHandlerVariable(handler)); + b.beginFinallyTryCatch(() -> emitUnbindHandlerVariable(handler)); b.beginBlock(); // try visitSequence(handler.body); b.endBlock(); // try @@ -4218,11 +4213,11 @@ private void emitTryExceptElse(StmtTy.Try node) { emitUnbindHandlerVariable(handler); b.beginMarkExceptionAsCaught(); - b.emitLoadLocal(handlerException); + b.emitLoadException(); // handler_i_ex b.endMarkExceptionAsCaught(); b.beginThrow(); - b.emitLoadLocal(handlerException); + b.emitLoadException(); // handler_i_ex b.endThrow(); b.endBlock(); // catch b.endFinallyTryCatch(); @@ -4245,14 +4240,14 @@ private void emitTryExceptElse(StmtTy.Try node) { b.endBlock(); // try b.beginBlock(); // catch - emitSetCurrentException(savedException); + emitRestoreCurrentException(savedException); b.beginMarkExceptionAsCaught(); - b.emitLoadLocal(handlerException); + b.emitLoadException(); // handler_ex b.endMarkExceptionAsCaught(); b.beginReraise(); - b.emitLoadLocal(handlerException); + b.emitLoadException(); // handler_ex b.endReraise(); b.endBlock(); // catch b.endFinallyTryCatch(); @@ -4265,7 +4260,7 @@ private void emitTryExceptElse(StmtTy.Try node) { */ if (bareExceptRange == null) { b.beginReraise(); - b.emitLoadLocal(exception); + b.emitLoadException(); // ex b.endReraise(); } @@ -4295,9 +4290,15 @@ private void emitSaveCurrentException(BytecodeLocal savedException) { b.endStoreLocal(); } - private void emitSetCurrentException(BytecodeLocal newException) { + private void emitSetCurrentException() { b.beginSetCurrentException(); - b.emitLoadLocal(newException); + b.emitLoadException(); + b.endSetCurrentException(); + } + + private void emitRestoreCurrentException(BytecodeLocal savedException) { + b.beginSetCurrentException(); + b.emitLoadLocal(savedException); b.endSetCurrentException(); } @@ -4410,7 +4411,6 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool b.endContextManagerEnter(); } - BytecodeLocal ex = b.createLocal(); Runnable finallyHandler; if (async) { finallyHandler = () -> emitAwait(() -> { @@ -4430,7 +4430,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool b.endContextManagerExit(); }; } - b.beginFinallyTryCatch(ex, finallyHandler); + b.beginFinallyTryCatch(finallyHandler); b.beginBlock(); // try if (item.optionalVars != null) { item.optionalVars.accept(new StoreVisitor(() -> b.emitLoadLocal(value))); @@ -4446,17 +4446,17 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool // Mark this location for the stack trace. b.beginMarkExceptionAsCaught(); - b.emitLoadLocal(ex); + b.emitLoadException(); b.endMarkExceptionAsCaught(); // exceptional exit if (async) { // call, await, and handle result of __aexit__ b.beginAsyncContextManagerExit(); - b.emitLoadLocal(ex); + b.emitLoadException(); emitAwait(() -> { b.beginAsyncContextManagerCallExit(); - b.emitLoadLocal(ex); + b.emitLoadException(); b.emitLoadLocal(exit); b.emitLoadLocal(contextManager); b.endAsyncContextManagerCallExit(); @@ -4465,7 +4465,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool } else { // call __exit__ b.beginContextManagerExit(); - b.emitLoadLocal(ex); + b.emitLoadException(); b.emitLoadLocal(exit); b.emitLoadLocal(contextManager); b.endContextManagerExit();