Skip to content

Commit

Permalink
Ensure context is set before printing
Browse files Browse the repository at this point in the history
Printing may end up calling back out to Ruby, which may re-
encounter this method or block. If the context has not been set,
it will attempt to print again which will recurse forever.
  • Loading branch information
headius committed Jun 3, 2024
1 parent 9310253 commit 2ebde20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,16 @@ public ArgumentDescriptor[] getArgumentDescriptors() {
}

public InterpreterContext ensureInstrsReady() {
final InterpreterContext interpreterContext = this.interpreterContext;
InterpreterContext interpreterContext = this.interpreterContext;
if (interpreterContext == null) {
return this.interpreterContext = retrieveInterpreterContext();
}
return interpreterContext;
}
IRScope method = getIRScope();

private InterpreterContext retrieveInterpreterContext() {
IRScope method = getIRScope();
final InterpreterContext interpreterContext = method.builtInterpreterContext();

if (IRRuntimeHelpers.shouldPrintIR(implementationClass.getRuntime()) && IRRuntimeHelpers.shouldPrintScope(method)) printMethodIR();
interpreterContext = this.interpreterContext = method.builtInterpreterContext();

if (IRRuntimeHelpers.shouldPrintIR(implementationClass.getRuntime()) && IRRuntimeHelpers.shouldPrintScope(method)) {
printMethodIR();
}
}
return interpreterContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public InterpreterContext ensureInstrsReady() {
}

if (interpreterContext == null) {
interpreterContext = closure.getInterpreterContext();

if (IRRuntimeHelpers.shouldPrintIR(closure.getStaticScope().getModule().getRuntime()) && IRRuntimeHelpers.shouldPrintScope(closure)) {
ByteArrayOutputStream baos = IRDumper.printIR(closure, false);

LOG.info("Printing simple IR for " + closure.getId() + ":\n" + new String(baos.toByteArray()));
}

interpreterContext = closure.getInterpreterContext();
}
return interpreterContext;
}
Expand Down

0 comments on commit 2ebde20

Please sign in to comment.