20
20
import org .truffleruby .builtins .PrimitiveArrayArgumentsNode ;
21
21
import org .truffleruby .core .array .RubyArray ;
22
22
import org .truffleruby .core .cast .SingleValueCastNode ;
23
- import org .truffleruby .core .cast .SingleValueCastNodeGen ;
24
23
import org .truffleruby .core .encoding .Encodings ;
25
24
import org .truffleruby .core .exception .RubyException ;
26
- import org .truffleruby .core .fiber .FiberNodesFactory .FiberTransferNodeFactory ;
27
25
import org .truffleruby .core .fiber .RubyFiber .FiberStatus ;
28
26
import org .truffleruby .core .klass .RubyClass ;
29
27
import org .truffleruby .core .proc .RubyProc ;
30
28
import org .truffleruby .core .string .RubyString ;
31
29
import org .truffleruby .core .thread .RubyThread ;
32
30
import org .truffleruby .language .Nil ;
33
31
import org .truffleruby .annotations .Visibility ;
32
+ import org .truffleruby .language .RubyBaseNode ;
34
33
import org .truffleruby .language .arguments .ArgumentsDescriptor ;
35
34
import org .truffleruby .language .arguments .EmptyArgumentsDescriptor ;
36
35
import org .truffleruby .language .arguments .RubyArguments ;
45
44
@ CoreModule (value = "Fiber" , isClass = true )
46
45
public abstract class FiberNodes {
47
46
48
- public abstract static class FiberTransferNode extends CoreMethodArrayArgumentsNode {
47
+ public abstract static class FiberTransferNodeAST extends CoreMethodArrayArgumentsNode {
49
48
50
- public static FiberTransferNode create () {
51
- return FiberTransferNodeFactory .create (null );
49
+ @ Specialization
50
+ protected Object transfer (
51
+ RubyFiber currentFiber ,
52
+ RubyFiber toFiber ,
53
+ FiberOperation operation ,
54
+ ArgumentsDescriptor descriptor ,
55
+ Object [] args ,
56
+ @ Cached FiberTransferNode fiberTransferNode ) {
57
+ return fiberTransferNode .execute (currentFiber , toFiber , operation , descriptor , args );
52
58
}
53
59
54
- @ Child private SingleValueCastNode singleValueCastNode ;
60
+ }
55
61
56
- public Object singleValue (Object [] args ) {
57
- if (singleValueCastNode == null ) {
58
- CompilerDirectives .transferToInterpreterAndInvalidate ();
59
- singleValueCastNode = insert (SingleValueCastNodeGen .create ());
60
- }
61
- return singleValueCastNode .executeSingleValue (args );
62
- }
62
+ public abstract static class FiberTransferNode extends RubyBaseNode {
63
63
64
64
public abstract Object execute (RubyFiber currentFiber , RubyFiber toFiber , FiberOperation operation ,
65
65
ArgumentsDescriptor descriptor , Object [] args );
@@ -71,6 +71,7 @@ protected Object transfer(
71
71
FiberOperation operation ,
72
72
ArgumentsDescriptor descriptor ,
73
73
Object [] args ,
74
+ @ Cached SingleValueCastNode singleValueCastNode ,
74
75
@ Cached InlinedBranchProfile errorProfile ) {
75
76
76
77
if (toFiber .isTerminated ()) {
@@ -88,7 +89,7 @@ protected Object transfer(
88
89
var descriptorAndArgs = getContext ().fiberManager .transferControlTo (currentFiber , toFiber , operation ,
89
90
descriptor , args , this );
90
91
// Ignore the descriptor like CRuby here, see https://bugs.ruby-lang.org/issues/18621
91
- return singleValue (descriptorAndArgs .args );
92
+ return singleValueCastNode . executeSingleValue (descriptorAndArgs .args );
92
93
}
93
94
94
95
}
@@ -143,10 +144,10 @@ protected Object noBlock(RubyFiber fiber, boolean blocking, Nil block) {
143
144
@ CoreMethod (names = "transfer" , rest = true )
144
145
public abstract static class TransferNode extends CoreMethodArrayArgumentsNode {
145
146
146
- @ Child private FiberTransferNode fiberTransferNode = FiberTransferNodeFactory .create (null );
147
-
148
147
@ Specialization
149
148
protected Object transfer (VirtualFrame frame , RubyFiber toFiber , Object [] rawArgs ,
149
+ @ Cached FiberTransferNode fiberTransferNode ,
150
+ @ Cached SingleValueCastNode singleValueCastNode ,
150
151
@ Cached InlinedConditionProfile sameFiberProfile ,
151
152
@ Cached InlinedBranchProfile errorProfile ) {
152
153
@@ -166,7 +167,7 @@ protected Object transfer(VirtualFrame frame, RubyFiber toFiber, Object[] rawArg
166
167
167
168
if (sameFiberProfile .profile (this , currentFiber == toFiber )) {
168
169
// A Fiber can transfer to itself
169
- return fiberTransferNode . singleValue (rawArgs );
170
+ return singleValueCastNode . executeSingleValue (rawArgs );
170
171
}
171
172
172
173
return fiberTransferNode .execute (currentFiber , toFiber , FiberOperation .TRANSFER ,
@@ -185,11 +186,10 @@ public static FiberResumeNode create() {
185
186
public abstract Object executeResume (FiberOperation operation , RubyFiber fiber , ArgumentsDescriptor descriptor ,
186
187
Object [] args );
187
188
188
- @ Child private FiberTransferNode fiberTransferNode = FiberTransferNodeFactory .create (null );
189
-
190
189
@ Specialization
191
190
protected Object resume (
192
191
FiberOperation operation , RubyFiber toFiber , ArgumentsDescriptor descriptor , Object [] args ,
192
+ @ Cached FiberTransferNode fiberTransferNode ,
193
193
@ Cached InlinedBranchProfile errorProfile ) {
194
194
195
195
final RubyFiber currentFiber = getLanguage ().getCurrentFiber ();
@@ -232,10 +232,10 @@ protected Object resume(
232
232
public abstract static class FiberRaiseNode extends PrimitiveArrayArgumentsNode {
233
233
234
234
@ Child private FiberResumeNode fiberResumeNode ;
235
- @ Child private FiberTransferNode fiberTransferNode ;
236
235
237
236
@ Specialization
238
237
protected Object raise (RubyFiber fiber , RubyException exception ,
238
+ @ Cached FiberTransferNode fiberTransferNode ,
239
239
@ Cached InlinedBranchProfile errorProfile ) {
240
240
if (fiber .resumingFiber != null ) {
241
241
errorProfile .enter (this );
@@ -251,7 +251,7 @@ protected Object raise(RubyFiber fiber, RubyException exception,
251
251
252
252
if (fiber .status == FiberStatus .SUSPENDED && !fiber .yielding ) {
253
253
final RubyFiber currentFiber = getLanguage ().getCurrentFiber ();
254
- return getTransferNode () .execute (
254
+ return fiberTransferNode .execute (
255
255
currentFiber ,
256
256
fiber ,
257
257
FiberOperation .RAISE ,
@@ -271,14 +271,6 @@ private FiberResumeNode getResumeNode() {
271
271
return fiberResumeNode ;
272
272
}
273
273
274
- private FiberTransferNode getTransferNode () {
275
- if (fiberTransferNode == null ) {
276
- CompilerDirectives .transferToInterpreterAndInvalidate ();
277
- fiberTransferNode = insert (FiberTransferNode .create ());
278
- }
279
- return fiberTransferNode ;
280
- }
281
-
282
274
}
283
275
284
276
@ CoreMethod (names = "resume" , rest = true )
@@ -297,10 +289,10 @@ protected Object resume(VirtualFrame frame, RubyFiber fiber, Object[] rawArgs) {
297
289
@ CoreMethod (names = "yield" , onSingleton = true , rest = true )
298
290
public abstract static class YieldNode extends CoreMethodArrayArgumentsNode {
299
291
300
- @ Child private FiberTransferNode fiberTransferNode = FiberTransferNodeFactory .create (null );
301
292
302
293
@ Specialization
303
294
protected Object fiberYield (VirtualFrame frame , Object [] rawArgs ,
295
+ @ Cached FiberTransferNode fiberTransferNode ,
304
296
@ Cached InlinedBranchProfile errorProfile ) {
305
297
306
298
final RubyFiber currentFiber = getLanguage ().getCurrentFiber ();
0 commit comments