Skip to content

Commit 049b954

Browse files
committed
SetMethodVisibilityNode is DSL inlinable node
1 parent 0b486a6 commit 049b954

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,11 +1104,10 @@ protected int getCacheLimit() {
11041104
@CoreMethod(names = "cext_module_function", onSingleton = true, required = 2)
11051105
public abstract static class CextModuleFunctionNode extends CoreMethodArrayArgumentsNode {
11061106

1107-
@Child SetMethodVisibilityNode setMethodVisibilityNode = SetMethodVisibilityNode.create();
1108-
11091107
@Specialization
1110-
protected RubyModule cextModuleFunction(RubyModule module, RubySymbol name) {
1111-
setMethodVisibilityNode.execute(module, name, Visibility.MODULE_FUNCTION);
1108+
protected RubyModule cextModuleFunction(RubyModule module, RubySymbol name,
1109+
@Cached SetMethodVisibilityNode setMethodVisibilityNode) {
1110+
setMethodVisibilityNode.execute(this, module, name, Visibility.MODULE_FUNCTION);
11121111
return module;
11131112
}
11141113

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

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
import org.truffleruby.core.module.ModuleNodesFactory.GeneratedReaderNodeFactory;
7171
import org.truffleruby.core.module.ModuleNodesFactory.GeneratedWriterNodeFactory;
7272
import org.truffleruby.core.module.ModuleNodesFactory.IsSubclassOfOrEqualToNodeFactory;
73-
import org.truffleruby.core.module.ModuleNodesFactory.SetMethodVisibilityNodeGen;
7473
import org.truffleruby.core.proc.RubyProc;
7574
import org.truffleruby.core.string.RubyString;
7675
import org.truffleruby.core.string.StringHelperNodes;
@@ -1643,7 +1642,7 @@ protected static Object methods(Frame callerFrame, RubyModule module, Object[] r
16431642
int i = 0;
16441643
try {
16451644
for (; loopProfile.inject(node, i < names.length); ++i) {
1646-
setMethodVisibilityNode.execute(module, names[i], Visibility.MODULE_FUNCTION);
1645+
setMethodVisibilityNode.execute(node, module, names[i], Visibility.MODULE_FUNCTION);
16471646
TruffleSafepoint.poll(node);
16481647
}
16491648
} finally {
@@ -1719,29 +1718,29 @@ protected Object frame(Frame callerFrame, RubyModule module, Object[] rubyArgs,
17191718
}
17201719

17211720
@Specialization(guards = "names.length > 0")
1722-
protected Object methods(Frame callerFrame, RubyModule module, Object[] rubyArgs, RootCallTarget target,
1721+
protected static Object methods(Frame callerFrame, RubyModule module, Object[] rubyArgs, RootCallTarget target,
17231722
@Bind("getPositionalArguments(rubyArgs)") Object[] names,
17241723
@Cached SetMethodVisibilityNode setMethodVisibilityNode,
1725-
@Cached SingleValueCastNode singleValueCastNode) {
1724+
@Cached SingleValueCastNode singleValueCastNode,
1725+
@Bind("this") Node node) {
17261726
for (Object name : names) {
1727-
setMethodVisibilityNode.execute(module, name, Visibility.PUBLIC);
1727+
setMethodVisibilityNode.execute(node, module, name, Visibility.PUBLIC);
17281728
}
1729-
return singleValueCastNode.execute(this, names);
1729+
return singleValueCastNode.execute(node, names);
17301730
}
17311731
}
17321732

17331733
@CoreMethod(names = "public_class_method", rest = true)
17341734
public abstract static class PublicClassMethodNode extends CoreMethodArrayArgumentsNode {
17351735

1736-
@Child private SetMethodVisibilityNode setMethodVisibilityNode = SetMethodVisibilityNode.create();
1737-
17381736
@Specialization
17391737
protected RubyModule publicClassMethod(RubyModule module, Object[] names,
1738+
@Cached SetMethodVisibilityNode setMethodVisibilityNode,
17401739
@Cached SingletonClassNode singletonClassNode) {
17411740
final RubyClass singletonClass = singletonClassNode.execute(module);
17421741

17431742
for (Object name : names) {
1744-
setMethodVisibilityNode.execute(singletonClass, name, Visibility.PUBLIC);
1743+
setMethodVisibilityNode.execute(this, singletonClass, name, Visibility.PUBLIC);
17451744
}
17461745

17471746
return module;
@@ -1761,14 +1760,15 @@ protected Object frame(Frame callerFrame, RubyModule module, Object[] rubyArgs,
17611760
}
17621761

17631762
@Specialization(guards = "names.length > 0")
1764-
protected Object methods(Frame callerFrame, RubyModule module, Object[] rubyArgs, RootCallTarget target,
1763+
protected static Object methods(Frame callerFrame, RubyModule module, Object[] rubyArgs, RootCallTarget target,
17651764
@Bind("getPositionalArguments(rubyArgs)") Object[] names,
17661765
@Cached SetMethodVisibilityNode setMethodVisibilityNode,
1767-
@Cached SingleValueCastNode singleValueCastNode) {
1766+
@Cached SingleValueCastNode singleValueCastNode,
1767+
@Bind("this") Node node) {
17681768
for (Object name : names) {
1769-
setMethodVisibilityNode.execute(module, name, Visibility.PRIVATE);
1769+
setMethodVisibilityNode.execute(node, module, name, Visibility.PRIVATE);
17701770
}
1771-
return singleValueCastNode.execute(this, names);
1771+
return singleValueCastNode.execute(node, names);
17721772
}
17731773
}
17741774

@@ -1792,15 +1792,14 @@ protected Object prependFeatures(RubyModule features, RubyModule target,
17921792
@CoreMethod(names = "private_class_method", rest = true)
17931793
public abstract static class PrivateClassMethodNode extends CoreMethodArrayArgumentsNode {
17941794

1795-
@Child private SetMethodVisibilityNode setMethodVisibilityNode = SetMethodVisibilityNode.create();
1796-
17971795
@Specialization
17981796
protected RubyModule privateClassMethod(VirtualFrame frame, RubyModule module, Object[] names,
1797+
@Cached SetMethodVisibilityNode setMethodVisibilityNode,
17991798
@Cached SingletonClassNode singletonClassNode) {
18001799
final RubyClass singletonClass = singletonClassNode.execute(module);
18011800

18021801
for (Object name : names) {
1803-
setMethodVisibilityNode.execute(singletonClass, name, Visibility.PRIVATE);
1802+
setMethodVisibilityNode.execute(this, singletonClass, name, Visibility.PRIVATE);
18041803
}
18051804

18061805
return module;
@@ -2047,14 +2046,15 @@ protected Object frame(Frame callerFrame, RubyModule module, Object[] rubyArgs,
20472046
}
20482047

20492048
@Specialization(guards = "names.length > 0")
2050-
protected Object methods(Frame callerFrame, RubyModule module, Object[] rubyArgs, RootCallTarget target,
2049+
protected static Object methods(Frame callerFrame, RubyModule module, Object[] rubyArgs, RootCallTarget target,
20512050
@Bind("getPositionalArguments(rubyArgs)") Object[] names,
20522051
@Cached SetMethodVisibilityNode setMethodVisibilityNode,
2053-
@Cached SingleValueCastNode singleValueCastNode) {
2052+
@Cached SingleValueCastNode singleValueCastNode,
2053+
@Bind("this") Node node) {
20542054
for (Object name : names) {
2055-
setMethodVisibilityNode.execute(module, name, Visibility.PROTECTED);
2055+
setMethodVisibilityNode.execute(node, module, name, Visibility.PROTECTED);
20562056
}
2057-
return singleValueCastNode.execute(this, names);
2057+
return singleValueCastNode.execute(node, names);
20582058
}
20592059
}
20602060

@@ -2231,28 +2231,25 @@ protected RubyArray refinements(RubyModule self) {
22312231
}
22322232

22332233
@GenerateUncached
2234+
@GenerateCached(false)
2235+
@GenerateInline
22342236
@ImportStatic(ArrayGuards.class)
22352237
public abstract static class SetMethodVisibilityNode extends RubyBaseNode {
22362238

2237-
@NeverDefault
2238-
public static SetMethodVisibilityNode create() {
2239-
return SetMethodVisibilityNodeGen.create();
2240-
}
2241-
2242-
public abstract void execute(RubyModule module, Object name, Visibility visibility);
2239+
public abstract void execute(Node node, RubyModule module, Object name, Visibility visibility);
22432240

22442241
@TruffleBoundary
22452242
@Specialization(guards = "!isRubyArray(name)")
2246-
protected void setMethodVisibility(RubyModule module, Object name, Visibility visibility,
2243+
protected static void setMethodVisibility(Node node, RubyModule module, Object name, Visibility visibility,
22472244
@Cached @Shared NameToJavaStringNode nameToJavaStringNode) {
2248-
final String methodName = nameToJavaStringNode.execute(this, name);
2245+
final String methodName = nameToJavaStringNode.execute(node, name);
22492246

2250-
final InternalMethod method = module.fields.deepMethodSearch(getContext(), methodName);
2247+
final InternalMethod method = module.fields.deepMethodSearch(getContext(node), methodName);
22512248

22522249
if (method == null) {
22532250
throw new RaiseException(
2254-
getContext(),
2255-
coreExceptions().nameErrorUndefinedMethod(methodName, module, this));
2251+
getContext(node),
2252+
coreExceptions(node).nameErrorUndefinedMethod(methodName, module, node));
22562253
}
22572254

22582255
// Do nothing if the method already exists with the same visibility, like MRI
@@ -2262,20 +2259,22 @@ protected void setMethodVisibility(RubyModule module, Object name, Visibility vi
22622259

22632260
/* If the method was already defined in this class, that's fine {@link addMethod} will overwrite it,
22642261
* otherwise we do actually want to add a copy of the method with a different visibility to this module. */
2265-
module.addMethodIgnoreNameVisibility(getContext(), method, visibility, this);
2262+
module.addMethodIgnoreNameVisibility(getContext(node), method, visibility, node);
22662263
}
22672264

22682265
@TruffleBoundary
22692266
@Specialization
2270-
protected void setMethodVisibilityArray(RubyModule module, RubyArray array, Visibility visibility,
2267+
protected static void setMethodVisibilityArray(
2268+
Node node, RubyModule module, RubyArray array, Visibility visibility,
22712269
@Cached @Shared NameToJavaStringNode nameToJavaStringNode) {
22722270
for (Object name : ArrayOperations.toIterable(array)) {
22732271
setMethodVisibility(
2272+
node,
22742273
module,
22752274
name,
22762275
visibility,
22772276
nameToJavaStringNode);
2278-
TruffleSafepoint.poll(this);
2277+
TruffleSafepoint.poll(node);
22792278
}
22802279
}
22812280

0 commit comments

Comments
 (0)