Skip to content

Commit fd0b141

Browse files
committed
Refactor SingletonMethodsNode to support DSL inlining
1 parent 7427120 commit fd0b141

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.oracle.truffle.api.dsl.Bind;
2121
import com.oracle.truffle.api.dsl.Cached.Shared;
2222
import com.oracle.truffle.api.dsl.Fallback;
23+
import com.oracle.truffle.api.dsl.GenerateCached;
24+
import com.oracle.truffle.api.dsl.GenerateInline;
2325
import com.oracle.truffle.api.dsl.NeverDefault;
2426
import com.oracle.truffle.api.frame.Frame;
2527
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -69,7 +71,6 @@
6971
import org.truffleruby.core.hash.library.PackedHashStoreLibrary;
7072
import org.truffleruby.core.inlined.AlwaysInlinedMethodNode;
7173
import org.truffleruby.core.kernel.KernelNodesFactory.SameOrEqualNodeFactory;
72-
import org.truffleruby.core.kernel.KernelNodesFactory.SingletonMethodsNodeFactory;
7374
import org.truffleruby.core.klass.RubyClass;
7475
import org.truffleruby.core.method.MethodFilter;
7576
import org.truffleruby.core.method.RubyMethod;
@@ -1270,9 +1271,9 @@ protected RubyArray methodsRegular(Object self, boolean regular,
12701271
}
12711272

12721273
@Specialization(guards = "!regular")
1273-
protected RubyArray methodsSingleton(VirtualFrame frame, Object self, boolean regular,
1274+
protected RubyArray methodsSingleton(Object self, boolean regular,
12741275
@Cached SingletonMethodsNode singletonMethodsNode) {
1275-
return singletonMethodsNode.executeSingletonMethods(frame, self, false);
1276+
return singletonMethodsNode.execute(this, self, false);
12761277
}
12771278

12781279
}
@@ -1554,34 +1555,40 @@ protected RubyMethod singletonMethod(Object self, Object nameObject,
15541555
@CoreMethod(names = "singleton_methods", optional = 1)
15551556
@NodeChild(value = "object", type = RubyNode.class)
15561557
@NodeChild(value = "includeAncestors", type = RubyBaseNodeWithExecute.class)
1557-
public abstract static class SingletonMethodsNode extends CoreMethodNode {
1558-
1559-
@NeverDefault
1560-
public static SingletonMethodsNode create() {
1561-
return SingletonMethodsNodeFactory.create(null, null);
1562-
}
1563-
1564-
public abstract RubyArray executeSingletonMethods(VirtualFrame frame, Object self, boolean includeAncestors);
1558+
public abstract static class KernelSingletonMethodsNode extends CoreMethodNode {
15651559

15661560
@CreateCast("includeAncestors")
15671561
protected RubyBaseNodeWithExecute coerceToBoolean(RubyBaseNodeWithExecute includeAncestors) {
15681562
return BooleanCastWithDefaultNode.create(true, includeAncestors);
15691563
}
15701564

1571-
@TruffleBoundary
15721565
@Specialization
15731566
protected RubyArray singletonMethods(Object self, boolean includeAncestors,
1567+
@Cached SingletonMethodsNode singletonMethodsNode) {
1568+
return singletonMethodsNode.execute(this, self, includeAncestors);
1569+
}
1570+
}
1571+
1572+
@GenerateCached(false)
1573+
@GenerateInline
1574+
public abstract static class SingletonMethodsNode extends RubyBaseNode {
1575+
1576+
public abstract RubyArray execute(Node node, Object self, boolean includeAncestors);
1577+
1578+
@TruffleBoundary
1579+
@Specialization
1580+
protected static RubyArray singletonMethods(Node node, Object self, boolean includeAncestors,
15741581
@Cached MetaClassNode metaClassNode) {
1575-
final RubyClass metaClass = metaClassNode.execute(this, self);
1582+
final RubyClass metaClass = metaClassNode.execute(node, self);
15761583

15771584
if (!metaClass.isSingleton) {
1578-
return createEmptyArray();
1585+
return createEmptyArray(node);
15791586
}
15801587

15811588
Object[] objects = metaClass.fields
1582-
.filterSingletonMethods(getLanguage(), includeAncestors, MethodFilter.PUBLIC_PROTECTED)
1589+
.filterSingletonMethods(getLanguage(node), includeAncestors, MethodFilter.PUBLIC_PROTECTED)
15831590
.toArray();
1584-
return createArray(objects);
1591+
return createArray(node, objects);
15851592
}
15861593

15871594
}

0 commit comments

Comments
 (0)