Skip to content

Commit e1fe7ac

Browse files
committed
BooleanCastWithDefaultNode supports DSL inlining
1 parent 0fca157 commit e1fe7ac

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

src/main/java/org/truffleruby/core/cast/BooleanCastWithDefaultNode.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@
1111

1212
import com.oracle.truffle.api.dsl.Cached;
1313
import com.oracle.truffle.api.dsl.Fallback;
14+
import com.oracle.truffle.api.dsl.GenerateCached;
15+
import com.oracle.truffle.api.dsl.GenerateInline;
16+
import com.oracle.truffle.api.nodes.Node;
1417
import org.truffleruby.language.RubyBaseNode;
1518
import org.truffleruby.language.NotProvided;
1619

1720
import com.oracle.truffle.api.dsl.Specialization;
1821

1922
/** Casts a value into a boolean and defaults to the given value if not provided. */
23+
@GenerateCached(false)
24+
@GenerateInline
2025
public abstract class BooleanCastWithDefaultNode extends RubyBaseNode {
2126

22-
public abstract boolean execute(Object value, boolean defaultValue);
27+
public abstract boolean execute(Node node, Object value, boolean defaultValue);
2328

2429
@Specialization
25-
protected boolean doDefault(NotProvided value, boolean defaultValue) {
30+
protected static boolean doDefault(NotProvided value, boolean defaultValue) {
2631
return defaultValue;
2732
}
2833

2934
@Fallback
30-
protected boolean fallback(Object value, boolean defaultValue,
35+
protected static boolean fallback(Object value, boolean defaultValue,
3136
@Cached BooleanCastNode booleanCastNode) {
3237
return booleanCastNode.execute(value);
3338
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ public abstract static class KernelMethodsNode extends CoreMethodNode {
12561256
protected RubyArray doMethods(Object self, Object maybeRegular,
12571257
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
12581258
@Cached MethodsNode methodsNode) {
1259-
final boolean regular = booleanCastWithDefaultNode.execute(maybeRegular, true);
1259+
final boolean regular = booleanCastWithDefaultNode.execute(this, maybeRegular, true);
12601260
return methodsNode.execute(this, self, regular);
12611261

12621262
}
@@ -1327,7 +1327,7 @@ public abstract static class PrivateMethodsNode extends CoreMethodNode {
13271327
protected RubyArray privateMethods(Object self, Object maybeIncludeAncestors,
13281328
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
13291329
@Cached MetaClassNode metaClassNode) {
1330-
final boolean includeAncestors = booleanCastWithDefaultNode.execute(maybeIncludeAncestors, true);
1330+
final boolean includeAncestors = booleanCastWithDefaultNode.execute(this, maybeIncludeAncestors, true);
13311331
RubyClass metaClass = metaClassNode.execute(this, self);
13321332

13331333
Object[] objects = metaClass.fields
@@ -1359,7 +1359,7 @@ public abstract static class ProtectedMethodsNode extends CoreMethodNode {
13591359
protected RubyArray protectedMethods(Object self, Object maybeIncludeAncestors,
13601360
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
13611361
@Cached MetaClassNode metaClassNode) {
1362-
final boolean includeAncestors = booleanCastWithDefaultNode.execute(maybeIncludeAncestors, true);
1362+
final boolean includeAncestors = booleanCastWithDefaultNode.execute(this, maybeIncludeAncestors, true);
13631363
final RubyClass metaClass = metaClassNode.execute(this, self);
13641364

13651365
Object[] objects = metaClass.fields
@@ -1396,7 +1396,7 @@ protected RubyArray publicMethods(Object self, Object maybeIncludeAncestors,
13961396
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
13971397
@Cached MetaClassNode metaClassNode) {
13981398
final RubyModule metaClass = metaClassNode.execute(this, self);
1399-
final boolean includeAncestors = booleanCastWithDefaultNode.execute(maybeIncludeAncestors, true);
1399+
final boolean includeAncestors = booleanCastWithDefaultNode.execute(this, maybeIncludeAncestors, true);
14001400

14011401
Object[] objects = metaClass.fields
14021402
.filterMethodsOnObject(getLanguage(), includeAncestors, MethodFilter.PUBLIC)
@@ -1562,7 +1562,7 @@ public abstract static class KernelSingletonMethodsNode extends CoreMethodNode {
15621562
protected RubyArray singletonMethods(Object self, Object maybeIncludeAncestors,
15631563
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
15641564
@Cached SingletonMethodsNode singletonMethodsNode) {
1565-
final boolean includeAncestors = booleanCastWithDefaultNode.execute(maybeIncludeAncestors, true);
1565+
final boolean includeAncestors = booleanCastWithDefaultNode.execute(this, maybeIncludeAncestors, true);
15661566
return singletonMethodsNode.execute(this, self, includeAncestors);
15671567
}
15681568
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ protected Object isAutoload(RubyModule module, Object nameObject, Object maybeIn
671671
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
672672
@Cached NameToJavaStringNode nameToJavaStringNode) {
673673
final var name = nameToJavaStringNode.execute(this, nameObject);
674-
final var inherit = booleanCastWithDefaultNode.execute(maybeInherit, true);
674+
final var inherit = booleanCastWithDefaultNode.execute(this, maybeInherit, true);
675675
final ConstantLookupResult constant = ModuleOperations.lookupConstantWithInherit(
676676
getContext(),
677677
module,
@@ -895,7 +895,7 @@ public abstract static class ClassVariablesNode extends CoreMethodNode {
895895
@Specialization
896896
protected RubyArray getClassVariables(RubyModule module, Object maybeInherit,
897897
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode) {
898-
final boolean inherit = booleanCastWithDefaultNode.execute(maybeInherit, true);
898+
final boolean inherit = booleanCastWithDefaultNode.execute(this, maybeInherit, true);
899899
final Set<Object> variables = new LinkedHashSet<>();
900900

901901
ModuleOperations.classVariableLookup(module, inherit, m -> {
@@ -919,7 +919,7 @@ public abstract static class ConstantsNode extends CoreMethodNode {
919919
@Specialization
920920
protected RubyArray constants(RubyModule module, Object maybeInherit,
921921
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode) {
922-
final boolean inherit = booleanCastWithDefaultNode.execute(maybeInherit, true);
922+
final boolean inherit = booleanCastWithDefaultNode.execute(this, maybeInherit, true);
923923
final List<RubySymbol> constantsArray = new ArrayList<>();
924924

925925
final Iterable<Entry<String, ConstantEntry>> constants;
@@ -951,7 +951,7 @@ protected boolean isConstDefined(
951951
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
952952
@Cached NameToJavaStringNode nameToJavaStringNode) {
953953
final var fullName = nameToJavaStringNode.execute(this, fullNameObject);
954-
final boolean inherit = booleanCastWithDefaultNode.execute(inheritObject, true);
954+
final boolean inherit = booleanCastWithDefaultNode.execute(this, inheritObject, true);
955955
final ConstantLookupResult constant = ModuleOperations
956956
.lookupScopedConstant(getContext(), module, fullName, inherit, this, checkName);
957957
return constant.isFound();
@@ -1144,7 +1144,7 @@ protected Object constSourceLocation(RubyModule module, Object nameObject, Objec
11441144
@Cached ConstSourceLocationNode constSourceLocationNode,
11451145
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
11461146
@Cached ToStringOrSymbolNode toStringOrSymbolNode) {
1147-
final boolean inherit = booleanCastWithDefaultNode.execute(maybeInherit, true);
1147+
final boolean inherit = booleanCastWithDefaultNode.execute(this, maybeInherit, true);
11481148
final var name = toStringOrSymbolNode.execute(nameObject);
11491149
return constSourceLocationNode.execute(this, module, name, inherit);
11501150
}
@@ -1605,7 +1605,7 @@ protected boolean isMethodDefined(RubyModule module, Object nameObject, Object m
16051605
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
16061606
@Cached NameToJavaStringNode nameToJavaStringNode) {
16071607
final var name = nameToJavaStringNode.execute(this, nameObject);
1608-
final var inherit = booleanCastWithDefaultNode.execute(maybeInherit, true);
1608+
final var inherit = booleanCastWithDefaultNode.execute(this, maybeInherit, true);
16091609
final InternalMethod method;
16101610
if (inherit) {
16111611
method = ModuleOperations.lookupMethodUncached(module, name, null);
@@ -1854,7 +1854,7 @@ public AbstractInstanceMethodsNode(Visibility visibility) {
18541854
@TruffleBoundary
18551855
protected RubyArray getInstanceMethods(RubyModule module, Object maybeIncludeAncestors,
18561856
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode) {
1857-
final boolean includeAncestors = booleanCastWithDefaultNode.execute(maybeIncludeAncestors, true);
1857+
final boolean includeAncestors = booleanCastWithDefaultNode.execute(this, maybeIncludeAncestors, true);
18581858
Object[] objects = module.fields
18591859
.filterMethods(getLanguage(), includeAncestors, MethodFilter.by(visibility))
18601860
.toArray();
@@ -1909,7 +1909,7 @@ protected boolean isMethodDefined(RubyModule module, Object nameObject, Object m
19091909
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
19101910
@Cached NameToJavaStringNode nameToJavaStringNode,
19111911
@Cached InlinedConditionProfile inheritProfile) {
1912-
final var inherit = booleanCastWithDefaultNode.execute(maybeInheritObject, true);
1912+
final var inherit = booleanCastWithDefaultNode.execute(this, maybeInheritObject, true);
19131913
final var name = nameToJavaStringNode.execute(this, nameObject);
19141914
final InternalMethod method;
19151915
if (inheritProfile.profile(this, inherit)) {
@@ -1953,7 +1953,7 @@ public abstract static class InstanceMethodsNode extends CoreMethodNode {
19531953
@Specialization
19541954
protected RubyArray instanceMethods(RubyModule module, Object maybeIncludeAncestors,
19551955
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode) {
1956-
final boolean includeAncestors = booleanCastWithDefaultNode.execute(maybeIncludeAncestors, true);
1956+
final boolean includeAncestors = booleanCastWithDefaultNode.execute(this, maybeIncludeAncestors, true);
19571957
Object[] objects = module.fields
19581958
.filterMethods(getLanguage(), includeAncestors, MethodFilter.PUBLIC_PROTECTED)
19591959
.toArray();

src/main/java/org/truffleruby/core/queue/SizedQueueNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public abstract static class SizedQueuePushNode extends CoreMethodNode {
114114
protected RubySizedQueue doPush(RubySizedQueue self, final Object value, Object maybeNonBlocking,
115115
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
116116
@Cached PushNode pushNode) {
117-
final boolean nonBlocking = booleanCastWithDefaultNode.execute(maybeNonBlocking, false);
117+
final boolean nonBlocking = booleanCastWithDefaultNode.execute(this, maybeNonBlocking, false);
118118
return pushNode.execute(this, self, value, nonBlocking);
119119
}
120120
}

src/main/java/org/truffleruby/core/range/RangeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public abstract static class NewNode extends CoreMethodNode {
390390
protected Object newRange(RubyClass rubyClass, Object begin, Object end, Object maybeExcludeEnd,
391391
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode,
392392
@Cached NewRangeNode newRangeNode) {
393-
final boolean excludeEnd = booleanCastWithDefaultNode.execute(maybeExcludeEnd, false);
393+
final boolean excludeEnd = booleanCastWithDefaultNode.execute(this, maybeExcludeEnd, false);
394394
return newRangeNode.execute(rubyClass, begin, end, excludeEnd);
395395
}
396396
}

src/main/java/org/truffleruby/stdlib/readline/ReadlineNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected RubyNode coercePromptToJavaString(RubyNode prompt) {
136136
protected Object readline(String prompt, Object maybeAddToHistory,
137137
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
138138
@Cached BooleanCastWithDefaultNode booleanCastWithDefaultNode) {
139-
final boolean addToHistory = booleanCastWithDefaultNode.execute(maybeAddToHistory, false);
139+
final boolean addToHistory = booleanCastWithDefaultNode.execute(this, maybeAddToHistory, false);
140140
final LineReader readline = getContext().getConsoleHolder().getReadline();
141141

142142
// Use a Memo as readLine() can return null on Ctrl+D and we should not retry

0 commit comments

Comments
 (0)