Skip to content

Commit c4c7282

Browse files
committed
Remove BytecodeLocal argument from TryCatch/FinallyTryCatch
1 parent 4b9c74e commit c4c7282

File tree

1 file changed

+38
-38
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl

1 file changed

+38
-38
lines changed

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

+38-38
Original file line numberDiff line numberDiff line change
@@ -2263,8 +2263,7 @@ public void emitYieldFrom(Runnable generatorOrCoroutineProducer) {
22632263
b.beginBlock();
22642264
BytecodeLabel loopEnd = b.createLabel();
22652265
// Step 2: yield yieldValue to the caller
2266-
BytecodeLocal thrownException = b.createLocal();
2267-
b.beginTryCatch(thrownException);
2266+
b.beginTryCatch();
22682267

22692268
// try clause: yield
22702269
b.beginStoreLocal(sentValue);
@@ -2275,7 +2274,7 @@ public void emitYieldFrom(Runnable generatorOrCoroutineProducer) {
22752274
b.beginIfThenElse();
22762275
b.beginYieldFromThrow(yieldValue, returnValue);
22772276
b.emitLoadLocal(generator);
2278-
b.emitLoadLocal(thrownException);
2277+
b.emitLoadException();
22792278
b.endYieldFromThrow();
22802279

22812280
// StopIteration was raised; go to the end.
@@ -4043,9 +4042,7 @@ public Void visit(StmtTy.Try node) {
40434042
* reraise uncaught_ex
40444043
* }
40454044
*/
4046-
BytecodeLocal uncaughtException = b.createLocal();
4047-
BytecodeLocal handlerException = b.createLocal();
4048-
b.beginFinallyTryCatch(uncaughtException, () -> {
4045+
b.beginFinallyTryCatch(() -> {
40494046
b.beginBlock(); // finally
40504047
visitSequence(node.finalBody);
40514048
b.endBlock();
@@ -4056,32 +4053,32 @@ public Void visit(StmtTy.Try node) {
40564053
b.beginBlock(); // catch
40574054
BytecodeLocal savedException = b.createLocal();
40584055
emitSaveCurrentException(savedException);
4059-
emitSetCurrentException(uncaughtException);
4056+
emitSetCurrentException();
40604057
// Mark this location for the stack trace.
40614058
b.beginMarkExceptionAsCaught();
4062-
b.emitLoadLocal(uncaughtException);
4059+
b.emitLoadException();
40634060
b.endMarkExceptionAsCaught();
40644061

4065-
b.beginFinallyTryCatch(handlerException, () -> emitSetCurrentException(savedException));
4062+
b.beginFinallyTryCatch(() -> emitRestoreCurrentException(savedException));
40664063
b.beginBlock(); // try
40674064
visitSequence(node.finalBody);
40684065
b.endBlock(); // try
40694066

40704067
b.beginBlock(); // catch
4071-
emitSetCurrentException(savedException);
4068+
emitRestoreCurrentException(savedException);
40724069

40734070
b.beginMarkExceptionAsCaught();
4074-
b.emitLoadLocal(handlerException);
4071+
b.emitLoadException();
40754072
b.endMarkExceptionAsCaught();
40764073

40774074
b.beginReraise();
4078-
b.emitLoadLocal(handlerException);
4075+
b.emitLoadException();
40794076
b.endReraise();
40804077
b.endBlock(); // catch
40814078
b.endFinallyTryCatch();
40824079

40834080
b.beginReraise();
4084-
b.emitLoadLocal(uncaughtException);
4081+
b.emitLoadException();
40854082
b.endReraise();
40864083
b.endBlock(); // catch
40874084
b.endFinallyTryCatch();
@@ -4130,11 +4127,11 @@ private void emitTryExceptElse(StmtTy.Try node) {
41304127
* handler_1_body
41314128
* } finally {
41324129
* unbind handler_1_name
4133-
* } catch handler_ex {
4130+
* } catch handler_1_ex {
41344131
* unbind handler_1_name
41354132
* // Freeze the bci before it gets rethrown.
41364133
* markCaught(handler_ex)
4137-
* throw handler_ex
4134+
* throw handler_1_ex
41384135
* }
41394136
* goto afterElse
41404137
* }
@@ -4160,26 +4157,24 @@ private void emitTryExceptElse(StmtTy.Try node) {
41604157
*/
41614158
b.beginBlock(); // outermost block
41624159

4163-
BytecodeLocal exception = b.createLocal();
41644160
BytecodeLocal savedException = b.createLocal();
41654161
BytecodeLabel afterElse = b.createLabel();
41664162

4167-
b.beginTryCatch(exception);
4163+
b.beginTryCatch();
41684164

41694165
b.beginBlock(); // try
41704166
visitSequence(node.body);
41714167
b.endBlock(); // try
41724168

41734169
b.beginBlock(); // catch
41744170
emitSaveCurrentException(savedException);
4175-
emitSetCurrentException(exception);
4171+
emitSetCurrentException();
41764172
// Mark this location for the stack trace.
41774173
b.beginMarkExceptionAsCaught();
4178-
b.emitLoadLocal(exception);
4174+
b.emitLoadException(); // ex
41794175
b.endMarkExceptionAsCaught();
41804176

4181-
BytecodeLocal handlerException = b.createLocal();
4182-
b.beginFinallyTryCatch(handlerException, () -> emitSetCurrentException(savedException));
4177+
b.beginFinallyTryCatch(() -> emitRestoreCurrentException(savedException));
41834178
b.beginBlock(); // try
41844179
SourceRange bareExceptRange = null;
41854180
for (ExceptHandlerTy h : node.handlers) {
@@ -4192,7 +4187,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
41924187
if (handler.type != null) {
41934188
b.beginIfThen();
41944189
b.beginExceptMatch();
4195-
b.emitLoadLocal(exception);
4190+
b.emitLoadException(); // ex
41964191
handler.type.accept(this);
41974192
b.endExceptMatch();
41984193
} else {
@@ -4205,11 +4200,11 @@ private void emitTryExceptElse(StmtTy.Try node) {
42054200
// Assign exception to handler name.
42064201
beginStoreLocal(handler.name, b);
42074202
b.beginUnwrapException();
4208-
b.emitLoadLocal(exception);
4203+
b.emitLoadException(); // ex
42094204
b.endUnwrapException();
42104205
endStoreLocal(handler.name, b);
42114206

4212-
b.beginFinallyTryCatch(handlerException, () -> emitUnbindHandlerVariable(handler));
4207+
b.beginFinallyTryCatch(() -> emitUnbindHandlerVariable(handler));
42134208
b.beginBlock(); // try
42144209
visitSequence(handler.body);
42154210
b.endBlock(); // try
@@ -4218,11 +4213,11 @@ private void emitTryExceptElse(StmtTy.Try node) {
42184213
emitUnbindHandlerVariable(handler);
42194214

42204215
b.beginMarkExceptionAsCaught();
4221-
b.emitLoadLocal(handlerException);
4216+
b.emitLoadException(); // handler_i_ex
42224217
b.endMarkExceptionAsCaught();
42234218

42244219
b.beginThrow();
4225-
b.emitLoadLocal(handlerException);
4220+
b.emitLoadException(); // handler_i_ex
42264221
b.endThrow();
42274222
b.endBlock(); // catch
42284223
b.endFinallyTryCatch();
@@ -4245,14 +4240,14 @@ private void emitTryExceptElse(StmtTy.Try node) {
42454240
b.endBlock(); // try
42464241

42474242
b.beginBlock(); // catch
4248-
emitSetCurrentException(savedException);
4243+
emitRestoreCurrentException(savedException);
42494244

42504245
b.beginMarkExceptionAsCaught();
4251-
b.emitLoadLocal(handlerException);
4246+
b.emitLoadException(); // handler_ex
42524247
b.endMarkExceptionAsCaught();
42534248

42544249
b.beginReraise();
4255-
b.emitLoadLocal(handlerException);
4250+
b.emitLoadException(); // handler_ex
42564251
b.endReraise();
42574252
b.endBlock(); // catch
42584253
b.endFinallyTryCatch();
@@ -4265,7 +4260,7 @@ private void emitTryExceptElse(StmtTy.Try node) {
42654260
*/
42664261
if (bareExceptRange == null) {
42674262
b.beginReraise();
4268-
b.emitLoadLocal(exception);
4263+
b.emitLoadException(); // ex
42694264
b.endReraise();
42704265
}
42714266

@@ -4295,9 +4290,15 @@ private void emitSaveCurrentException(BytecodeLocal savedException) {
42954290
b.endStoreLocal();
42964291
}
42974292

4298-
private void emitSetCurrentException(BytecodeLocal newException) {
4293+
private void emitSetCurrentException() {
42994294
b.beginSetCurrentException();
4300-
b.emitLoadLocal(newException);
4295+
b.emitLoadException();
4296+
b.endSetCurrentException();
4297+
}
4298+
4299+
private void emitRestoreCurrentException(BytecodeLocal savedException) {
4300+
b.beginSetCurrentException();
4301+
b.emitLoadLocal(savedException);
43014302
b.endSetCurrentException();
43024303
}
43034304

@@ -4410,7 +4411,6 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
44104411
b.endContextManagerEnter();
44114412
}
44124413

4413-
BytecodeLocal ex = b.createLocal();
44144414
Runnable finallyHandler;
44154415
if (async) {
44164416
finallyHandler = () -> emitAwait(() -> {
@@ -4430,7 +4430,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
44304430
b.endContextManagerExit();
44314431
};
44324432
}
4433-
b.beginFinallyTryCatch(ex, finallyHandler);
4433+
b.beginFinallyTryCatch(finallyHandler);
44344434
b.beginBlock(); // try
44354435
if (item.optionalVars != null) {
44364436
item.optionalVars.accept(new StoreVisitor(() -> b.emitLoadLocal(value)));
@@ -4446,17 +4446,17 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
44464446

44474447
// Mark this location for the stack trace.
44484448
b.beginMarkExceptionAsCaught();
4449-
b.emitLoadLocal(ex);
4449+
b.emitLoadException();
44504450
b.endMarkExceptionAsCaught();
44514451

44524452
// exceptional exit
44534453
if (async) {
44544454
// call, await, and handle result of __aexit__
44554455
b.beginAsyncContextManagerExit();
4456-
b.emitLoadLocal(ex);
4456+
b.emitLoadException();
44574457
emitAwait(() -> {
44584458
b.beginAsyncContextManagerCallExit();
4459-
b.emitLoadLocal(ex);
4459+
b.emitLoadException();
44604460
b.emitLoadLocal(exit);
44614461
b.emitLoadLocal(contextManager);
44624462
b.endAsyncContextManagerCallExit();
@@ -4465,7 +4465,7 @@ private void visitWithRecurse(WithItemTy[] items, int index, StmtTy[] body, bool
44654465
} else {
44664466
// call __exit__
44674467
b.beginContextManagerExit();
4468-
b.emitLoadLocal(ex);
4468+
b.emitLoadException();
44694469
b.emitLoadLocal(exit);
44704470
b.emitLoadLocal(contextManager);
44714471
b.endContextManagerExit();

0 commit comments

Comments
 (0)