@@ -285,30 +285,18 @@ RubyUnboundMethod unbind(RubyMethod method,
285
285
@ CoreMethod (names = "to_proc" )
286
286
public abstract static class ToProcNode extends CoreMethodArrayArgumentsNode {
287
287
288
- @ Specialization (guards = { "isSingleContext()" , "methodObject == cachedMethodObject" },
289
- limit = "getCacheLimit()" )
290
- RubyProc toProcCachedSingleContext (RubyMethod methodObject ,
291
- @ Cached ("methodObject" ) RubyMethod cachedMethodObject ,
292
- @ Cached ("toProcUncached(cachedMethodObject)" ) RubyProc proc ) {
293
- return proc ;
294
- }
295
-
296
- @ Specialization (
297
- guards = "methodObject.method.getCallTarget() == methodCallTarget" ,
298
- limit = "getCacheLimit()" ,
299
- replaces = "toProcCachedSingleContext" )
300
- RubyProc toProcCachedTarget (RubyMethod methodObject ,
301
- @ Cached ("methodObject.method.getCallTarget()" ) RootCallTarget methodCallTarget ,
302
- @ Cached ("procCallTargetToCallRubyMethod(methodCallTarget)" ) RootCallTarget procCallTarget ) {
303
- return createProc (procCallTarget , methodObject .method , methodObject .receiver );
304
- }
305
-
306
- @ Specialization (replaces = { "toProcCachedSingleContext" , "toProcCachedTarget" })
307
- RubyProc toProcUncached (RubyMethod methodObject ) {
288
+ @ Specialization
289
+ RubyProc toProc (RubyMethod methodObject ) {
308
290
final InternalMethod method = methodObject .method ;
309
291
final Object receiver = methodObject .receiver ;
310
- final RootCallTarget callTarget = procCallTargetToCallRubyMethod (method .getCallTarget ());
311
- return createProc (callTarget , method , receiver );
292
+ RootCallTarget toProcCallTarget = method .toProcCallTarget ;
293
+
294
+ if (toProcCallTarget == null ) {
295
+ toProcCallTarget = createToProcCallTarget (method .getCallTarget ());
296
+ method .toProcCallTarget = toProcCallTarget ;
297
+ }
298
+
299
+ return createProc (toProcCallTarget , method , receiver );
312
300
}
313
301
314
302
private RubyProc createProc (RootCallTarget callTarget , InternalMethod method , Object receiver ) {
@@ -331,7 +319,7 @@ private RubyProc createProc(RootCallTarget callTarget, InternalMethod method, Ob
331
319
}
332
320
333
321
@ TruffleBoundary
334
- protected RootCallTarget procCallTargetToCallRubyMethod (RootCallTarget callTarget ) {
322
+ protected RootCallTarget createToProcCallTarget (RootCallTarget callTarget ) {
335
323
// translate to something like:
336
324
// lambda { |same args list| method.call(args) }
337
325
// We need to preserve the method receiver and we want to have the same argument list.
@@ -354,10 +342,6 @@ protected RootCallTarget procCallTargetToCallRubyMethod(RootCallTarget callTarge
354
342
return wrapRootNode .getCallTarget ();
355
343
}
356
344
357
- protected int getCacheLimit () {
358
- return getLanguage ().options .METHOD_TO_PROC_CACHE ;
359
- }
360
-
361
345
private static final class CallWithRubyMethodReceiverNode extends RubyContextSourceNode {
362
346
@ Child private CallInternalMethodNode callInternalMethodNode = CallInternalMethodNode .create ();
363
347
0 commit comments