Skip to content

Commit daab02f

Browse files
committed
[GR-43903] Address new Truffle DSL warnings (idempotent and assumptions)
1 parent f70da08 commit daab02f

13 files changed

+28
-5
lines changed

src/main/java/org/truffleruby/core/binding/BindingNodes.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.oracle.truffle.api.CompilerDirectives;
1818
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
1919
import com.oracle.truffle.api.dsl.GenerateUncached;
20+
import com.oracle.truffle.api.dsl.Idempotent;
2021
import com.oracle.truffle.api.dsl.NeverDefault;
2122
import com.oracle.truffle.api.frame.FrameSlotKind;
2223
import com.oracle.truffle.api.strings.TruffleString;
@@ -155,7 +156,8 @@ public static boolean isHiddenVariable(Object name) {
155156
}
156157
}
157158

158-
private static boolean isHiddenVariable(String name) {
159+
@Idempotent
160+
static boolean isHiddenVariable(String name) {
159161
assert !name.isEmpty();
160162
final char first = name.charAt(0);
161163
return first == '$' || // Frame-local global variable

src/main/java/org/truffleruby/core/encoding/EncodingNodes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
package org.truffleruby.core.encoding;
1313

14+
import com.oracle.truffle.api.dsl.Idempotent;
1415
import com.oracle.truffle.api.dsl.ImportStatic;
1516
import com.oracle.truffle.api.dsl.NeverDefault;
1617
import com.oracle.truffle.api.strings.AbstractTruffleString;
@@ -213,6 +214,7 @@ private TruffleString.GetByteCodeRangeNode getCodeRangeNode() {
213214
/** Indicates whether the encoding is one of the runtime-default encodings. Many (most?) applications do not
214215
* override the default encodings and as such, this set of encodings is used very frequently in real-world Ruby
215216
* applications. */
217+
@Idempotent
216218
protected boolean isStandardEncoding(RubyEncoding encoding) {
217219
return encoding == Encodings.UTF_8 || encoding == Encodings.US_ASCII || encoding == Encodings.BINARY;
218220
}

src/main/java/org/truffleruby/core/numeric/IntegerNodes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.oracle.truffle.api.dsl.Cached.Shared;
1717
import com.oracle.truffle.api.dsl.Fallback;
18+
import com.oracle.truffle.api.dsl.Idempotent;
1819
import com.oracle.truffle.api.profiles.LoopConditionProfile;
1920
import com.oracle.truffle.api.strings.TruffleString;
2021
import org.truffleruby.annotations.CoreMethod;
@@ -515,6 +516,7 @@ protected int modPowerOfTwo(int a, int b,
515516
return a & (cachedB - 1);
516517
}
517518

519+
@Idempotent
518520
protected static boolean isPowerOfTwo(int n) {
519521
return n > 0 && (n & (n - 1)) == 0;
520522
}

src/main/java/org/truffleruby/language/RubyBaseNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.language;
1111

1212
import com.oracle.truffle.api.CompilerAsserts;
13+
import com.oracle.truffle.api.dsl.Idempotent;
1314
import com.oracle.truffle.api.dsl.ImportStatic;
1415
import com.oracle.truffle.api.dsl.TypeSystemReference;
1516
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
@@ -50,6 +51,7 @@ public abstract class RubyBaseNode extends Node {
5051

5152
public static final int MAX_EXPLODE_SIZE = 16;
5253

54+
@Idempotent
5355
public boolean isSingleContext() {
5456
return getLanguage().singleContext;
5557
}

src/main/java/org/truffleruby/language/RubyGuards.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.oracle.truffle.api.CompilerAsserts;
1313
import com.oracle.truffle.api.CompilerDirectives;
1414
import com.oracle.truffle.api.dsl.Cached;
15+
import com.oracle.truffle.api.dsl.Idempotent;
1516
import com.oracle.truffle.api.dsl.NeverDefault;
1617
import com.oracle.truffle.api.strings.TruffleString;
1718
import org.truffleruby.core.CoreLibrary;
@@ -94,6 +95,7 @@ public static boolean isPrimitive(Object value) {
9495
return value instanceof Boolean || value instanceof Integer || value instanceof Long || value instanceof Double;
9596
}
9697

98+
@Idempotent
9799
public static boolean isPrimitiveClass(Class<?> clazz) {
98100
return clazz == Boolean.class || clazz == Integer.class || clazz == Long.class || clazz == Double.class;
99101
}
@@ -113,6 +115,7 @@ public static boolean isRubyArray(Object value) {
113115
return value instanceof RubyArray;
114116
}
115117

118+
@Idempotent
116119
public static boolean isRubyClass(Object value) {
117120
return value instanceof RubyClass;
118121
}

src/main/java/org/truffleruby/language/globals/GlobalVariableStorage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.language.globals;
1111

12+
import com.oracle.truffle.api.dsl.Idempotent;
1213
import com.oracle.truffle.api.dsl.NeverDefault;
1314
import org.truffleruby.RubyContext;
1415
import org.truffleruby.core.proc.RubyProc;
@@ -89,6 +90,7 @@ public Assumption getUnchangedAssumption() {
8990
return unchangedAssumption.getAssumption();
9091
}
9192

93+
@Idempotent
9294
public boolean isAssumeConstant() {
9395
return assumeConstant;
9496
}

src/main/java/org/truffleruby/language/globals/LookupGlobalVariableStorageNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final GlobalVariableStorage execute(Object dynamicArgument) {
4242
protected abstract GlobalVariableStorage executeInternal();
4343

4444
@Specialization(
45-
guards = "getLanguage().singleContext",
45+
guards = "isSingleContext()",
4646
assumptions = "getLanguage().getGlobalVariableNeverAliasedAssumption(index)")
4747
protected GlobalVariableStorage singleContext(
4848
@Cached("getContext().getGlobalVariableStorage(index)") GlobalVariableStorage storage) {

src/main/java/org/truffleruby/language/globals/ReadSimpleGlobalVariableNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ReadSimpleGlobalVariableNode(String name) {
3838
public abstract Object execute();
3939

4040
@Specialization(
41-
guards = "getLanguage().singleContext",
41+
guards = "isSingleContext()",
4242
assumptions = {
4343
"storage.getUnchangedAssumption()",
4444
"getLanguage().getGlobalVariableNeverAliasedAssumption(index)" })

src/main/java/org/truffleruby/language/globals/WriteSimpleGlobalVariableNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public WriteSimpleGlobalVariableNode(String name) {
3636

3737
@Specialization(
3838
guards = {
39-
"getLanguage().singleContext",
39+
"isSingleContext()",
4040
"referenceEqualNode.executeReferenceEqual(value, previousValue)" },
4141
assumptions = {
4242
"storage.getUnchangedAssumption()",
@@ -53,7 +53,7 @@ protected Object writeTryToKeepConstant(Object value,
5353
}
5454

5555
@Specialization(
56-
guards = { "getLanguage().singleContext", "storage.isAssumeConstant()" },
56+
guards = { "isSingleContext()", "storage.isAssumeConstant()" },
5757
assumptions = {
5858
"storage.getUnchangedAssumption()",
5959
"getLanguage().getGlobalVariableNeverAliasedAssumption(index)" })

src/main/java/org/truffleruby/language/methods/CallForeignMethodNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
1313
import com.oracle.truffle.api.dsl.Cached;
1414
import com.oracle.truffle.api.dsl.GenerateUncached;
15+
import com.oracle.truffle.api.dsl.Idempotent;
1516
import com.oracle.truffle.api.dsl.Specialization;
1617
import com.oracle.truffle.api.interop.InteropException;
1718
import com.oracle.truffle.api.interop.InteropLibrary;
@@ -100,11 +101,13 @@ protected Object assignmentMethod(Object receiver, String name, Object[] args,
100101
}
101102
}
102103

104+
@Idempotent
103105
@TruffleBoundary
104106
protected static boolean isOperatorMethod(String name) {
105107
return !name.isEmpty() && !Character.isLetter(name.charAt(0));
106108
}
107109

110+
@Idempotent
108111
@TruffleBoundary
109112
protected static boolean isAssignmentMethod(String name) {
110113
return !name.isEmpty() && Character.isLetter(name.charAt(0)) && name.charAt(name.length() - 1) == '=';

0 commit comments

Comments
 (0)