Skip to content

Commit f2be31a

Browse files
committed
[GR-28711] Do not store the declarationFrame for define_method(&block) in multi-contexts
PullRequest: truffleruby/3289
2 parents 7810a98 + e77385d commit f2be31a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/main/java/org/truffleruby/core/module/ModuleNodes.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,8 @@ private RubySymbol defineMethod(RubyModule module, String name, RubyProc proc,
13281328
final RubyLambdaRootNode rootNode = RubyLambdaRootNode.of(callTargetForLambda);
13291329
final SharedMethodInfo info = proc.sharedMethodInfo.forDefineMethod(module, name);
13301330
final RubyNode body = rootNode.copyBody();
1331-
final RubyNode newBody = new CallMethodWithLambdaBody(proc.declarationFrame, body);
1331+
final RubyNode newBody = new CallMethodWithLambdaBody(isSingleContext() ? proc : null,
1332+
callTargetForLambda, body);
13321333

13331334
final RubyLambdaRootNode newRootNode = rootNode.copyRootNode(info, newBody);
13341335
final RootCallTarget newCallTarget = newRootNode.getCallTarget();
@@ -1347,17 +1348,28 @@ private RubySymbol defineMethod(RubyModule module, String name, RubyProc proc,
13471348

13481349
private static class CallMethodWithLambdaBody extends RubyContextSourceNode {
13491350

1350-
private final MaterializedFrame declarationFrame;
1351+
private final RubyProc proc;
1352+
private final RootCallTarget lambdaCallTarget;
13511353
@Child private RubyNode lambdaBody;
13521354

1353-
public CallMethodWithLambdaBody(MaterializedFrame declarationFrame, RubyNode lambdaBody) {
1354-
this.declarationFrame = declarationFrame;
1355+
public CallMethodWithLambdaBody(RubyProc proc, RootCallTarget lambdaCallTarget, RubyNode lambdaBody) {
1356+
this.proc = proc;
1357+
this.lambdaCallTarget = lambdaCallTarget;
13551358
this.lambdaBody = lambdaBody;
13561359
}
13571360

13581361
@Override
13591362
public Object execute(VirtualFrame frame) {
1360-
RubyArguments.setDeclarationFrame(frame, declarationFrame);
1363+
final RubyProc proc;
1364+
if (this.proc == null) {
1365+
proc = RubyArguments.getMethod(frame).getProc();
1366+
assert proc.callTargets.getCallTargetForLambda() == lambdaCallTarget;
1367+
} else {
1368+
assert RubyArguments.getMethod(frame).getProc() == this.proc;
1369+
proc = this.proc;
1370+
}
1371+
1372+
RubyArguments.setDeclarationFrame(frame, proc.declarationFrame);
13611373
return lambdaBody.execute(frame);
13621374
}
13631375

src/main/java/org/truffleruby/language/methods/InternalMethod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ public int getArityNumber() {
217217
return sharedMethodInfo.getArity().getMethodArityNumber();
218218
}
219219

220+
public RubyProc getProc() {
221+
return proc;
222+
}
223+
220224
public RootCallTarget getCallTarget() {
221225
if (callTarget == null) {
222226
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)