diff --git a/src/main/java/org/truffleruby/core/array/ArrayNodes.java b/src/main/java/org/truffleruby/core/array/ArrayNodes.java index 8d446d63e8f2..2691f79bcb51 100644 --- a/src/main/java/org/truffleruby/core/array/ArrayNodes.java +++ b/src/main/java/org/truffleruby/core/array/ArrayNodes.java @@ -138,9 +138,10 @@ public abstract static class AddNode extends CoreMethodArrayArgumentsNode { @Specialization( limit = "storageStrategyLimit()") - RubyArray addGeneralize(RubyArray a, Object bObject, + static RubyArray addGeneralize(RubyArray a, Object bObject, @Cached ToAryNode toAryNode, - @Bind("toAryNode.execute(bObject)") RubyArray b, + @Bind("this") Node node, + @Bind("toAryNode.execute(node, bObject)") RubyArray b, @Bind("a.getStore()") Object aStore, @Bind("b.getStore()") Object bStore, @CachedLibrary("aStore") ArrayStoreLibrary as, @@ -153,7 +154,7 @@ RubyArray addGeneralize(RubyArray a, Object bObject, Object newStore = as.unsharedAllocateForNewStore(aStore, bStore, combinedSize); as.copyContents(aStore, 0, newStore, 0, aSize); bs.copyContents(bStore, 0, newStore, aSize, bSize); - return createArray(newStore, combinedSize); + return createArray(node, newStore, combinedSize); } } @@ -595,7 +596,7 @@ RubyArray concatZero(RubyArray array, NotProvided first, Object[] rest) { RubyArray concatOne(RubyArray array, Object first, Object[] rest, @Cached @Shared ToAryNode toAryNode, @Cached @Shared ArrayAppendManyNode appendManyNode) { - appendManyNode.executeAppendMany(array, toAryNode.execute(first)); + appendManyNode.executeAppendMany(array, toAryNode.execute(this, first)); return array; } @@ -615,11 +616,11 @@ RubyArray concatMany(RubyArray array, Object first, Object[] rest, @Cached @Shared ConditionProfile selfArgProfile) { int size = array.size; RubyArray copy = createArray(cowNode.execute(array, 0, size), size); - RubyArray result = appendManyNode.executeAppendMany(array, toAryNode.execute(first)); + RubyArray result = appendManyNode.executeAppendMany(array, toAryNode.execute(this, first)); for (int i = 0; i < cachedLength; ++i) { final RubyArray argOrCopy = selfArgProfile.profile(rest[i] == array) ? copy - : toAryNode.execute(rest[i]); + : toAryNode.execute(this, rest[i]); result = appendManyNode.executeAppendMany(array, argOrCopy); } return result; @@ -638,7 +639,7 @@ RubyArray concatManyGeneral(RubyArray array, Object first, Object[] rest, final int size = array.size; Object store = cowNode.execute(array, 0, size); - RubyArray result = appendManyNode.executeAppendMany(array, toAryNode.execute(first)); + RubyArray result = appendManyNode.executeAppendMany(array, toAryNode.execute(this, first)); int i = 0; try { for (; loopProfile.inject(i < rest.length); i++) { @@ -646,7 +647,7 @@ RubyArray concatManyGeneral(RubyArray array, Object first, Object[] rest, if (selfArgProfile.profile(arg == array)) { result = appendManyNode.executeAppendMany(array, createArray(store, size)); } else { - result = appendManyNode.executeAppendMany(array, toAryNode.execute(arg)); + result = appendManyNode.executeAppendMany(array, toAryNode.execute(this, arg)); } TruffleSafepoint.poll(this); } @@ -1286,7 +1287,7 @@ public abstract static class InitializeCopyNode extends CoreMethodArrayArguments RubyArray initializeCopy(RubyArray self, Object fromObject, @Cached ToAryNode toAryNode, @Cached ReplaceNode replaceNode) { - final var from = toAryNode.execute(fromObject); + final var from = toAryNode.execute(this, fromObject); if (self == from) { return self; } @@ -1797,7 +1798,7 @@ RubyArray replace(RubyArray array, Object otherObject, @Cached IsSharedNode isSharedNode, @Cached ConditionProfile sharedProfile, @CachedLibrary(limit = "2") ArrayStoreLibrary stores) { - final var other = toAryNode.execute(otherObject); + final var other = toAryNode.execute(this, otherObject); final int size = other.size; Object store = cowNode.execute(other, 0, size); if (sharedProfile.profile(isSharedNode.executeIsShared(this, array))) { diff --git a/src/main/java/org/truffleruby/core/cast/ToAryNode.java b/src/main/java/org/truffleruby/core/cast/ToAryNode.java index a5708488f3e5..e7b0e81749aa 100644 --- a/src/main/java/org/truffleruby/core/cast/ToAryNode.java +++ b/src/main/java/org/truffleruby/core/cast/ToAryNode.java @@ -9,6 +9,9 @@ */ package org.truffleruby.core.cast; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.core.array.RubyArray; import org.truffleruby.language.RubyBaseNode; @@ -16,25 +19,25 @@ import com.oracle.truffle.api.dsl.Specialization; import org.truffleruby.language.dispatch.DispatchNode; +@GenerateCached(false) +@GenerateInline public abstract class ToAryNode extends RubyBaseNode { - - public abstract RubyArray execute(Object object); - + public abstract RubyArray execute(Node node, Object object); @Specialization - RubyArray coerceRubyArray(RubyArray array) { + static RubyArray coerceRubyArray(RubyArray array) { return array; } @Specialization(guards = "!isRubyArray(object)") - RubyArray coerceObject(Object object, - @Cached DispatchNode toAryNode) { + static RubyArray coerceObject(Node node, Object object, + @Cached(inline = false) DispatchNode toAryNode) { return (RubyArray) toAryNode.call( - coreLibrary().truffleTypeModule, + coreLibrary(node).truffleTypeModule, "rb_convert_type", object, - coreLibrary().arrayClass, - coreSymbols().TO_ARY); + coreLibrary(node).arrayClass, + coreSymbols(node).TO_ARY); } } diff --git a/src/main/java/org/truffleruby/core/cast/ToCallTargetNode.java b/src/main/java/org/truffleruby/core/cast/ToCallTargetNode.java index 5eaae5fda7c7..cf25ba893b9a 100644 --- a/src/main/java/org/truffleruby/core/cast/ToCallTargetNode.java +++ b/src/main/java/org/truffleruby/core/cast/ToCallTargetNode.java @@ -9,6 +9,9 @@ */ package org.truffleruby.core.cast; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.core.method.RubyMethod; import org.truffleruby.core.method.RubyUnboundMethod; import org.truffleruby.core.proc.RubyProc; @@ -17,22 +20,24 @@ import com.oracle.truffle.api.RootCallTarget; import com.oracle.truffle.api.dsl.Specialization; +@GenerateInline +@GenerateCached(false) public abstract class ToCallTargetNode extends RubyBaseNode { - public abstract RootCallTarget execute(Object executable); + public abstract RootCallTarget execute(Node node, Object executable); @Specialization - RootCallTarget boundMethod(RubyMethod method) { + static RootCallTarget boundMethod(RubyMethod method) { return method.method.getCallTarget(); } @Specialization - RootCallTarget unboundMethod(RubyUnboundMethod method) { + static RootCallTarget unboundMethod(RubyUnboundMethod method) { return method.method.getCallTarget(); } @Specialization - RootCallTarget proc(RubyProc proc) { + static RootCallTarget proc(RubyProc proc) { return proc.callTarget; } diff --git a/src/main/java/org/truffleruby/core/cast/ToPathNode.java b/src/main/java/org/truffleruby/core/cast/ToPathNode.java index 8eca8b00a006..cbbdf1900df6 100644 --- a/src/main/java/org/truffleruby/core/cast/ToPathNode.java +++ b/src/main/java/org/truffleruby/core/cast/ToPathNode.java @@ -9,6 +9,9 @@ */ package org.truffleruby.core.cast; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.core.string.RubyString; import org.truffleruby.core.string.ImmutableRubyString; import org.truffleruby.language.RubyBaseNode; @@ -17,23 +20,25 @@ import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; +@GenerateCached(false) +@GenerateInline public abstract class ToPathNode extends RubyBaseNode { - public abstract Object execute(Object value); + public abstract Object execute(Node node, Object value); @Specialization - RubyString coerceRubyString(RubyString path) { + static RubyString coerceRubyString(RubyString path) { return path; } @Specialization - ImmutableRubyString coerceImmutableRubyString(ImmutableRubyString path) { + static ImmutableRubyString coerceImmutableRubyString(ImmutableRubyString path) { return path; } @Specialization(guards = "isNotRubyString(object)") - RubyString coerceObject(Object object, - @Cached DispatchNode toPathNode) { - return (RubyString) toPathNode.call(coreLibrary().truffleTypeModule, "coerce_to_path", object); + static RubyString coerceObject(Node node, Object object, + @Cached(inline = false) DispatchNode toPathNode) { + return (RubyString) toPathNode.call(coreLibrary(node).truffleTypeModule, "coerce_to_path", object); } } diff --git a/src/main/java/org/truffleruby/core/encoding/EncodingNodes.java b/src/main/java/org/truffleruby/core/encoding/EncodingNodes.java index 4c90e1513a50..3f31f083ffd7 100644 --- a/src/main/java/org/truffleruby/core/encoding/EncodingNodes.java +++ b/src/main/java/org/truffleruby/core/encoding/EncodingNodes.java @@ -520,28 +520,31 @@ boolean isUnicode(RubyEncoding encoding) { public abstract static class GetActualEncodingPrimitiveNode extends PrimitiveArrayArgumentsNode { @Specialization(guards = "libString.isRubyString(string)", limit = "1") - RubyEncoding getActualEncoding(Object string, + static RubyEncoding getActualEncoding(Object string, @Cached GetActualEncodingNode getActualEncodingNode, - @Cached RubyStringLibrary libString) { - return getActualEncodingNode.execute(libString.getTString(string), libString.getEncoding(string)); + @Cached RubyStringLibrary libString, + @Bind("this") Node node) { + return getActualEncodingNode.execute(node, libString.getTString(string), libString.getEncoding(string)); } } // MRI: get_actual_encoding + @GenerateInline + @GenerateCached(false) public abstract static class GetActualEncodingNode extends RubyBaseNode { - public abstract RubyEncoding execute(AbstractTruffleString tstring, RubyEncoding encoding); + public abstract RubyEncoding execute(Node node, AbstractTruffleString tstring, RubyEncoding encoding); @Specialization(guards = "!encoding.isDummy") - RubyEncoding getActualEncoding(AbstractTruffleString tstring, RubyEncoding encoding) { + static RubyEncoding getActualEncoding(AbstractTruffleString tstring, RubyEncoding encoding) { return encoding; } @TruffleBoundary @Specialization(guards = "encoding.isDummy") - RubyEncoding getActualEncodingDummy(AbstractTruffleString tstring, RubyEncoding encoding, - @Cached TruffleString.ReadByteNode readByteNode) { + static RubyEncoding getActualEncodingDummy(AbstractTruffleString tstring, RubyEncoding encoding, + @Cached(inline = false) TruffleString.ReadByteNode readByteNode) { if (encoding.isUnicode) { var enc = encoding.tencoding; var byteLength = tstring.byteLength(enc); diff --git a/src/main/java/org/truffleruby/core/hash/FreezeHashKeyIfNeededNode.java b/src/main/java/org/truffleruby/core/hash/FreezeHashKeyIfNeededNode.java index ed4c1fdc39a0..e627aed29307 100644 --- a/src/main/java/org/truffleruby/core/hash/FreezeHashKeyIfNeededNode.java +++ b/src/main/java/org/truffleruby/core/hash/FreezeHashKeyIfNeededNode.java @@ -10,7 +10,10 @@ package org.truffleruby.core.hash; import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.core.string.RubyString; import org.truffleruby.core.string.ImmutableRubyString; import org.truffleruby.language.RubyBaseNode; @@ -19,35 +22,37 @@ import com.oracle.truffle.api.dsl.Specialization; @GenerateUncached +@GenerateInline +@GenerateCached(false) public abstract class FreezeHashKeyIfNeededNode extends RubyBaseNode { - public abstract Object executeFreezeIfNeeded(Object key, boolean compareByIdentity); + public abstract Object executeFreezeIfNeeded(Node node, Object key, boolean compareByIdentity); @Specialization - Object immutable(ImmutableRubyString string, boolean compareByIdentity) { + static Object immutable(ImmutableRubyString string, boolean compareByIdentity) { return string; } @Specialization(guards = "string.isFrozen()") - Object alreadyFrozen(RubyString string, boolean compareByIdentity) { + static Object alreadyFrozen(RubyString string, boolean compareByIdentity) { return string; } @Specialization(guards = { "!string.isFrozen()", "!compareByIdentity" }) - Object dupAndFreeze(RubyString string, boolean compareByIdentity, - @Cached DispatchNode dupNode) { + static Object dupAndFreeze(RubyString string, boolean compareByIdentity, + @Cached(inline = false) DispatchNode dupNode) { final RubyString copy = (RubyString) dupNode.call(string, "dup"); copy.freeze(); return copy; } @Specialization(guards = { "!string.isFrozen()", "compareByIdentity" }) - Object compareByIdentity(RubyString string, boolean compareByIdentity) { + static Object compareByIdentity(RubyString string, boolean compareByIdentity) { return string; } @Specialization(guards = "isNotRubyString(value)") - Object passThrough(Object value, boolean compareByIdentity) { + static Object passThrough(Object value, boolean compareByIdentity) { return value; } } diff --git a/src/main/java/org/truffleruby/core/hash/library/BucketsHashStore.java b/src/main/java/org/truffleruby/core/hash/library/BucketsHashStore.java index 22138da952f3..79878f4e2fa6 100644 --- a/src/main/java/org/truffleruby/core/hash/library/BucketsHashStore.java +++ b/src/main/java/org/truffleruby/core/hash/library/BucketsHashStore.java @@ -246,7 +246,7 @@ protected boolean set(RubyHash hash, Object key, Object value, boolean byIdentit @Bind("$node") Node node) { assert verify(hash); - final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(key, byIdentity); + final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(node, key, byIdentity); propagateSharingKey.execute(node, hash, key2); propagateSharingValue.execute(node, hash, value); diff --git a/src/main/java/org/truffleruby/core/hash/library/HashStoreLibrary.java b/src/main/java/org/truffleruby/core/hash/library/HashStoreLibrary.java index 0a232084336e..84856cd7dd08 100644 --- a/src/main/java/org/truffleruby/core/hash/library/HashStoreLibrary.java +++ b/src/main/java/org/truffleruby/core/hash/library/HashStoreLibrary.java @@ -11,6 +11,7 @@ import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.Frame; @@ -118,6 +119,7 @@ public interface EachEntryCallback { /** Call the block with an key-value entry. If the block has > 1 arity, passes the key and the value as arguments, * otherwise passes an array containing the key and the value as single argument. */ @GenerateUncached + @GenerateInline(false) public abstract static class YieldPairNode extends RubyBaseNode { public static YieldPairNode create() { diff --git a/src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java b/src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java index 4805256dc1df..7db49bfb126e 100644 --- a/src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java +++ b/src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java @@ -177,7 +177,7 @@ static boolean setFirst(Object[] store, RubyHash hash, Object key, Object value, @Cached @Shared PropagateSharingNode propagateSharingValue, @Bind("this") Node node) { - final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(key, byIdentity); + final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(node, key, byIdentity); propagateSharingKey.execute(node, hash, key2); propagateSharingValue.execute(node, hash, value); setHashedKeyValue(store, 0, hashNode.execute(key2, byIdentity), key2, value); @@ -199,7 +199,7 @@ static boolean set(Object[] store, RubyHash hash, Object key, Object value, bool assert verify(store, hash); final int size = hash.size; - final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(key, byIdentity); + final Object key2 = freezeHashKeyIfNeeded.executeFreezeIfNeeded(node, key, byIdentity); final int hashed = hashNode.execute(key2, byIdentity); propagateSharingKey.execute(node, hash, key2); propagateSharingValue.execute(node, hash, value); @@ -499,7 +499,7 @@ Object doHash(VirtualFrame frame, for (int n = 0; n < keyValues.length / 2; n++) { Object key = keyValues[n * 2].execute(frame); - key = freezeHashKeyIfNeededNode.executeFreezeIfNeeded(key, false); + key = freezeHashKeyIfNeededNode.executeFreezeIfNeeded(this, key, false); final int hashed = hash(key); diff --git a/src/main/java/org/truffleruby/core/kernel/KernelNodes.java b/src/main/java/org/truffleruby/core/kernel/KernelNodes.java index a5a020c7a6ad..576447b3cf84 100644 --- a/src/main/java/org/truffleruby/core/kernel/KernelNodes.java +++ b/src/main/java/org/truffleruby/core/kernel/KernelNodes.java @@ -994,7 +994,7 @@ boolean isInstanceVariableDefined(RubyDynamicObject object, Object name, @CachedLibrary(limit = "getDynamicObjectCacheLimit()") DynamicObjectLibrary objectLibrary, @Cached NameToJavaStringNode nameToJavaStringNode) { final String nameString = nameToJavaStringNode.execute(this, name); - checkIVarNameNode.execute(object, nameString, name); + checkIVarNameNode.execute(this, object, nameString, name); return objectLibrary.containsKey(object, nameString); } @@ -1013,7 +1013,7 @@ Object instanceVariableGetSymbol(RubyDynamicObject object, Object name, @CachedLibrary(limit = "getDynamicObjectCacheLimit()") DynamicObjectLibrary objectLibrary, @Cached @Shared NameToJavaStringNode nameToJavaStringNode) { final String nameString = nameToJavaStringNode.execute(this, name); - checkIVarNameNode.execute(object, nameString, name); + checkIVarNameNode.execute(this, object, nameString, name); return objectLibrary.getOrDefault(object, nameString, nil); } @@ -1022,7 +1022,7 @@ Object immutable(Object object, Object name, @Cached @Shared CheckIVarNameNode checkIVarNameNode, @Cached @Shared NameToJavaStringNode nameToJavaStringNode) { final String nameString = nameToJavaStringNode.execute(this, name); - checkIVarNameNode.execute(object, nameString, name); + checkIVarNameNode.execute(this, object, nameString, name); return nil; } } @@ -1037,7 +1037,7 @@ Object instanceVariableSet(RubyDynamicObject object, Object name, Object value, @Cached @Shared NameToJavaStringNode nameToJavaStringNode, @Cached TypeNodes.CheckFrozenNode raiseIfFrozenNode) { final String nameString = nameToJavaStringNode.execute(this, name); - checkIVarNameNode.execute(object, nameString, name); + checkIVarNameNode.execute(this, object, nameString, name); raiseIfFrozenNode.execute(this, object); writeNode.execute(this, object, nameString, value); return value; @@ -1048,7 +1048,7 @@ Object immutable(Object object, Object name, Object value, @Cached @Shared CheckIVarNameNode checkIVarNameNode, @Cached @Shared NameToJavaStringNode nameToJavaStringNode) { final String nameString = nameToJavaStringNode.execute(this, name); - checkIVarNameNode.execute(object, nameString, name); + checkIVarNameNode.execute(this, object, nameString, name); throw new RaiseException(getContext(), coreExceptions().frozenError(object, this)); } } @@ -1062,7 +1062,7 @@ Object removeInstanceVariable(RubyDynamicObject object, Object name, @Cached @Shared NameToJavaStringNode nameToJavaStringNode, @Cached TypeNodes.CheckFrozenNode raiseIfFrozenNode) { final String nameString = nameToJavaStringNode.execute(this, name); - checkIVarNameNode.execute(object, nameString, name); + checkIVarNameNode.execute(this, object, nameString, name); raiseIfFrozenNode.execute(this, object); return removeIVar(object, nameString); } @@ -1072,7 +1072,7 @@ Object immutable(Object object, Object name, @Cached @Shared CheckIVarNameNode checkIVarNameNode, @Cached @Shared NameToJavaStringNode nameToJavaStringNode) { final String nameString = nameToJavaStringNode.execute(this, name); - checkIVarNameNode.execute(object, nameString, name); + checkIVarNameNode.execute(this, object, nameString, name); throw new RaiseException(getContext(), coreExceptions().frozenError(object, this)); } diff --git a/src/main/java/org/truffleruby/core/method/RubyMethod.java b/src/main/java/org/truffleruby/core/method/RubyMethod.java index 22b8c4bb6286..2267633fba53 100644 --- a/src/main/java/org/truffleruby/core/method/RubyMethod.java +++ b/src/main/java/org/truffleruby/core/method/RubyMethod.java @@ -11,6 +11,8 @@ import java.util.Set; +import com.oracle.truffle.api.dsl.Bind; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.core.klass.RubyClass; import org.truffleruby.interop.ForeignToRubyArgumentsNode; import org.truffleruby.language.RubyDynamicObject; @@ -69,8 +71,9 @@ public boolean isExecutable() { @ExportMessage public Object execute(Object[] arguments, @Cached ForeignToRubyArgumentsNode foreignToRubyArgumentsNode, - @Cached CallInternalMethodNode callInternalMethodNode) { - final Object[] convertedArguments = foreignToRubyArgumentsNode.executeConvert(arguments); + @Cached CallInternalMethodNode callInternalMethodNode, + @Bind("$node") Node node) { + final Object[] convertedArguments = foreignToRubyArgumentsNode.executeConvert(node, arguments); final Object[] frameArgs = RubyArguments.pack(null, null, method, null, receiver, nil, EmptyArgumentsDescriptor.INSTANCE, convertedArguments); return callInternalMethodNode.execute(null, method, receiver, frameArgs); diff --git a/src/main/java/org/truffleruby/core/method/UnboundMethodNodes.java b/src/main/java/org/truffleruby/core/method/UnboundMethodNodes.java index 0ec483ef5385..069bf50392de 100644 --- a/src/main/java/org/truffleruby/core/method/UnboundMethodNodes.java +++ b/src/main/java/org/truffleruby/core/method/UnboundMethodNodes.java @@ -84,7 +84,7 @@ RubyMethod bind(RubyUnboundMethod unboundMethod, Object object, final RubyClass objectMetaClass = metaClassNode.execute(this, object); if (!canBindMethodToModuleNode - .executeCanBindMethodToModule(unboundMethod.method, objectMetaClass)) { + .executeCanBindMethodToModule(this, unboundMethod.method, objectMetaClass)) { errorProfile.enter(this); final RubyModule declaringModule = unboundMethod.method.getDeclaringModule(); if (RubyGuards.isSingletonClass(declaringModule)) { diff --git a/src/main/java/org/truffleruby/core/module/ModuleNodes.java b/src/main/java/org/truffleruby/core/module/ModuleNodes.java index 73857588b9d5..a65f2e21a754 100644 --- a/src/main/java/org/truffleruby/core/module/ModuleNodes.java +++ b/src/main/java/org/truffleruby/core/module/ModuleNodes.java @@ -617,9 +617,9 @@ public abstract static class AutoloadNode extends CoreMethodArrayArgumentsNode { static Object autoload(RubyModule module, Object nameObject, Object filename, @Cached NameToJavaStringNode nameToJavaStringNode, @Cached ToPathNode toPathNode, - @Bind("toPathNode.execute(filename)") Object filenameAsPath, - @Cached RubyStringLibrary libFilename, - @Bind("this") Node node) { + @Bind("this") Node node, + @Bind("toPathNode.execute(node, filename)") Object filenameAsPath, + @Cached RubyStringLibrary libFilename) { final var name = nameToJavaStringNode.execute(node, nameObject); if (!Identifiers.isValidConstantName(name)) { throw new RaiseException( @@ -694,7 +694,7 @@ Object evalWithBlock(Frame callerFrame, RubyModule self, Object[] rubyArgs, Root } final Object block = RubyArguments.getBlock(rubyArgs); - return classExecNode.execute(EmptyArgumentsDescriptor.INSTANCE, self, new Object[]{ self }, + return classExecNode.execute(this, EmptyArgumentsDescriptor.INSTANCE, self, new Object[]{ self }, (RubyProc) block); } @@ -786,7 +786,7 @@ public abstract static class ClassExecNode extends CoreMethodArrayArgumentsNode @Specialization Object withBlock(VirtualFrame frame, RubyModule self, Object[] args, RubyProc block, @Cached ClassExecBlockNode classExecBlockNode) { - return classExecBlockNode.execute(RubyArguments.getDescriptor(frame), self, args, block); + return classExecBlockNode.execute(this, RubyArguments.getDescriptor(frame), self, args, block); } @Specialization @@ -796,19 +796,23 @@ Object noBlock(RubyModule self, Object[] args, Nil block) { } @GenerateUncached + @GenerateInline + @GenerateCached(false) public abstract static class ClassExecBlockNode extends RubyBaseNode { - public abstract Object execute(ArgumentsDescriptor descriptor, RubyModule self, Object[] args, RubyProc block); + public abstract Object execute(Node node, ArgumentsDescriptor descriptor, RubyModule self, Object[] args, + RubyProc block); @Specialization - Object classExec(ArgumentsDescriptor descriptor, RubyModule self, Object[] args, RubyProc block, + static Object classExec( + Node node, ArgumentsDescriptor descriptor, RubyModule self, Object[] args, RubyProc block, @Cached CallBlockNode callBlockNode) { final DeclarationContext declarationContext = new DeclarationContext( Visibility.PUBLIC, new FixedDefaultDefinee(self), block.declarationContext.getRefinements()); - return callBlockNode.executeCallBlock(this, declarationContext, block, self, nil, descriptor, args); + return callBlockNode.executeCallBlock(node, declarationContext, block, self, nil, descriptor, args); } } @@ -821,7 +825,7 @@ boolean isClassVariableDefinedString(RubyModule module, Object nameObject, @Cached CheckClassVariableNameNode checkClassVariableNameNode, @Cached LookupClassVariableNode lookupClassVariableNode) { final var name = nameToJavaStringNode.execute(this, nameObject); - checkClassVariableNameNode.execute(module, name); + checkClassVariableNameNode.execute(this, module, name); return lookupClassVariableNode.execute(module, name) != null; } @@ -837,7 +841,7 @@ Object getClassVariable(RubyModule module, Object nameObject, @Cached LookupClassVariableNode lookupClassVariableNode, @Cached InlinedConditionProfile undefinedProfile) { final var name = nameToJavaStringNode.execute(this, nameObject); - checkClassVariableNameNode.execute(module, name); + checkClassVariableNameNode.execute(this, module, name); final Object value = lookupClassVariableNode.execute(module, name); if (undefinedProfile.profile(this, value == null)) { @@ -860,7 +864,7 @@ Object setClassVariable(RubyModule module, Object nameObject, Object value, @Cached CheckClassVariableNameNode checkClassVariableNameNode, @Cached SetClassVariableNode setClassVariableNode) { final var name = nameToJavaStringNode.execute(this, nameObject); - checkClassVariableNameNode.execute(module, name); + checkClassVariableNameNode.execute(this, module, name); setClassVariableNode.execute(module, name, value); return value; } @@ -1452,7 +1456,7 @@ RubyModule initialize(RubyModule module, Nil block) { @Specialization RubyModule initialize(RubyModule module, RubyProc block, @Cached ClassExecBlockNode classExecBlockNode) { - classExecBlockNode.execute(EmptyArgumentsDescriptor.INSTANCE, module, new Object[]{ module }, block); + classExecBlockNode.execute(this, EmptyArgumentsDescriptor.INSTANCE, module, new Object[]{ module }, block); return module; } @@ -1999,7 +2003,7 @@ Object removeClassVariableString(RubyModule module, Object nameObject, @Cached NameToJavaStringNode nameToJavaStringNode, @Cached CheckClassVariableNameNode checkClassVariableNameNode) { final var name = nameToJavaStringNode.execute(this, nameObject); - checkClassVariableNameNode.execute(module, name); + checkClassVariableNameNode.execute(this, module, name); return ModuleOperations.removeClassVariable(module.fields, getContext(), this, name); } diff --git a/src/main/java/org/truffleruby/core/proc/RubyProc.java b/src/main/java/org/truffleruby/core/proc/RubyProc.java index a7fbc1db1d60..34270e86d88a 100644 --- a/src/main/java/org/truffleruby/core/proc/RubyProc.java +++ b/src/main/java/org/truffleruby/core/proc/RubyProc.java @@ -149,7 +149,7 @@ public Object execute(Object[] arguments, @Cached CallBlockNode yieldNode, @Cached ForeignToRubyArgumentsNode foreignToRubyArgumentsNode, @Bind("$node") Node node) { - return yieldNode.yield(node, this, foreignToRubyArgumentsNode.executeConvert(arguments)); + return yieldNode.yield(node, this, foreignToRubyArgumentsNode.executeConvert(node, arguments)); } // endregion } diff --git a/src/main/java/org/truffleruby/core/string/StringHelperNodes.java b/src/main/java/org/truffleruby/core/string/StringHelperNodes.java index 30e9e8436a48..41ff9a765939 100644 --- a/src/main/java/org/truffleruby/core/string/StringHelperNodes.java +++ b/src/main/java/org/truffleruby/core/string/StringHelperNodes.java @@ -443,19 +443,16 @@ static int checkIndex(Node node, int index, int length, } + @GenerateInline + @GenerateCached(false) public abstract static class NormalizeIndexNode extends RubyBaseNode { - @NeverDefault - public static NormalizeIndexNode create() { - return StringHelperNodesFactory.NormalizeIndexNodeGen.create(); - } - - public abstract int executeNormalize(int index, int length); + public abstract int executeNormalize(Node node, int index, int length); @Specialization - int normalizeIndex(int index, int length, + static int normalizeIndex(Node node, int index, int length, @Cached InlinedConditionProfile negativeIndexProfile) { - if (negativeIndexProfile.profile(this, index < 0)) { + if (negativeIndexProfile.profile(node, index < 0)) { return index + length; } @@ -572,42 +569,41 @@ Object invert(RubyString string, } @ImportStatic(StringGuards.class) + @GenerateCached(false) + @GenerateInline public abstract static class GetCodePointNode extends RubyBaseNode { - public abstract int executeGetCodePoint(AbstractTruffleString string, RubyEncoding encoding, int byteIndex); + public abstract int executeGetCodePoint(Node node, AbstractTruffleString string, RubyEncoding encoding, + int byteIndex); @Specialization - int getCodePoint(AbstractTruffleString string, RubyEncoding encoding, int byteIndex, - @Cached TruffleString.CodePointAtByteIndexNode getCodePointNode, + static int getCodePoint(Node node, AbstractTruffleString string, RubyEncoding encoding, int byteIndex, + @Cached(inline = false) TruffleString.CodePointAtByteIndexNode getCodePointNode, @Cached InlinedBranchProfile badCodePointProfile) { int codePoint = getCodePointNode.execute(string, byteIndex, encoding.tencoding, ErrorHandling.RETURN_NEGATIVE); if (codePoint == -1) { - badCodePointProfile.enter(this); - throw new RaiseException(getContext(), - coreExceptions().argumentErrorInvalidByteSequence(encoding, this)); + badCodePointProfile.enter(node); + throw new RaiseException(getContext(node), + coreExceptions(node).argumentErrorInvalidByteSequence(encoding, node)); } return codePoint; } } + @GenerateInline + @GenerateCached(false) public abstract static class StringAppendNode extends RubyBaseNode { - @NeverDefault - public static StringAppendNode create() { - return StringHelperNodesFactory.StringAppendNodeGen.create(); - } - - public abstract RubyString executeStringAppend(Object string, Object other); + public abstract RubyString executeStringAppend(Node node, Object string, Object other); @Specialization(guards = "libOther.isRubyString(other)", limit = "1") - static RubyString stringAppend(Object string, Object other, + static RubyString stringAppend(Node node, Object string, Object other, @Cached RubyStringLibrary libString, @Cached RubyStringLibrary libOther, @Cached EncodingNodes.CheckStringEncodingNode checkEncodingNode, - @Cached TruffleString.ConcatNode concatNode, - @Bind("this") Node node) { + @Cached(inline = false) TruffleString.ConcatNode concatNode) { var left = libString.getTString(string); var leftEncoding = libString.getEncoding(string); diff --git a/src/main/java/org/truffleruby/core/string/StringNodes.java b/src/main/java/org/truffleruby/core/string/StringNodes.java index b5c840d76b2c..07905bfc0242 100644 --- a/src/main/java/org/truffleruby/core/string/StringNodes.java +++ b/src/main/java/org/truffleruby/core/string/StringNodes.java @@ -222,7 +222,7 @@ RubyString add(Object string, Object other, @Cached ToStrNode toStrNode, @Cached StringHelperNodes.StringAppendNode stringAppendNode) { final var otherAsString = toStrNode.execute(this, other); - return stringAppendNode.executeStringAppend(string, otherAsString); + return stringAppendNode.executeStringAppend(this, string, otherAsString); } } @@ -1406,19 +1406,18 @@ static RubyString forceEncoding(RubyString string, Object newEncoding, @CoreMethod(names = "getbyte", required = 1, lowerFixnum = 1) public abstract static class StringGetByteNode extends CoreMethodArrayArgumentsNode { - @Child private StringHelperNodes.NormalizeIndexNode normalizeIndexNode = StringHelperNodes.NormalizeIndexNode - .create(); @Child private TruffleString.ReadByteNode readByteNode = TruffleString.ReadByteNode.create(); @Specialization Object getByte(Object string, int index, @Cached InlinedConditionProfile indexOutOfBoundsProfile, - @Cached RubyStringLibrary libString) { + @Cached RubyStringLibrary libString, + @Cached StringHelperNodes.NormalizeIndexNode normalizeIndexNode) { var tstring = libString.getTString(string); var encoding = libString.getEncoding(string).tencoding; int byteLength = tstring.byteLength(encoding); - final int normalizedIndex = normalizeIndexNode.executeNormalize(index, byteLength); + final int normalizedIndex = normalizeIndexNode.executeNormalize(this, index, byteLength); if (indexOutOfBoundsProfile.profile(this, (normalizedIndex < 0) || (normalizedIndex >= byteLength))) { return nil; @@ -1612,7 +1611,7 @@ static Object lstripBangSingleByte(RubyString string, @Cached InlinedConditionProfile noopProfile, @Bind("this") Node node) { var tstring = string.tstring; - var encoding = getActualEncodingNode.execute(tstring, libString.getEncoding(string)); + var encoding = getActualEncodingNode.execute(node, tstring, libString.getEncoding(string)); var tencoding = encoding.tencoding; var iterator = createCodePointIteratorNode.execute(tstring, tencoding, ErrorHandling.RETURN_NEGATIVE); @@ -1682,7 +1681,8 @@ int ordEmpty(Object string, int ord(Object string, @Cached @Shared RubyStringLibrary strings, @Cached StringHelperNodes.GetCodePointNode getCodePointNode) { - return getCodePointNode.executeGetCodePoint(strings.getTString(string), strings.getEncoding(string), 0); + return getCodePointNode.executeGetCodePoint(this, strings.getTString(string), strings.getEncoding(string), + 0); } } @@ -1751,7 +1751,7 @@ static Object rstripBangNonEmptyString(RubyString string, @Cached @Exclusive InlinedConditionProfile noopProfile, @Bind("this") Node node) { var tstring = string.tstring; - var encoding = getActualEncodingNode.execute(tstring, libString.getEncoding(string)); + var encoding = getActualEncodingNode.execute(node, tstring, libString.getEncoding(string)); var tencoding = encoding.tencoding; var iterator = createBackwardCodePointIteratorNode.execute(tstring, tencoding, @@ -3105,9 +3105,6 @@ protected boolean isMBCPrintable(Encoding encoding, int codePoint) { @Primitive(name = "string_append") public abstract static class StringAppendPrimitiveNode extends PrimitiveArrayArgumentsNode { - @Child private StringHelperNodes.StringAppendNode stringAppendNode = StringHelperNodes.StringAppendNode - .create(); - @NeverDefault public static StringAppendPrimitiveNode create() { return StringAppendPrimitiveNodeFactory.create(null); @@ -3116,8 +3113,9 @@ public static StringAppendPrimitiveNode create() { public abstract RubyString executeStringAppend(RubyString string, Object other); @Specialization - RubyString stringAppend(RubyString string, Object other) { - final RubyString result = stringAppendNode.executeStringAppend(string, other); + RubyString stringAppend(RubyString string, Object other, + @Cached StringHelperNodes.StringAppendNode stringAppendNode) { + final RubyString result = stringAppendNode.executeStringAppend(this, string, other); string.setTString(result.tstring, result.getEncodingUnprofiled()); return string; } @@ -3329,18 +3327,16 @@ private static Object[] addSubstring(Node node, CallBlockNode yieldNode, Object[ @Primitive(name = "string_byte_substring", lowerFixnum = { 1, 2 }) public abstract static class StringByteSubstringPrimitiveNode extends PrimitiveArrayArgumentsNode { - @Child private StringHelperNodes.NormalizeIndexNode normalizeIndexNode = StringHelperNodes.NormalizeIndexNode - .create(); - @Specialization Object stringByteSubstring(Object string, int index, NotProvided length, @Cached @Exclusive InlinedConditionProfile indexOutOfBoundsProfile, @Cached @Shared RubyStringLibrary libString, - @Cached @Shared TruffleString.SubstringByteIndexNode substringNode) { + @Cached @Shared TruffleString.SubstringByteIndexNode substringNode, + @Cached @Shared StringHelperNodes.NormalizeIndexNode normalizeIndexNode) { var tString = libString.getTString(string); var encoding = libString.getEncoding(string); final int stringByteLength = tString.byteLength(encoding.tencoding); - final int normalizedIndex = normalizeIndexNode.executeNormalize(index, stringByteLength); + final int normalizedIndex = normalizeIndexNode.executeNormalize(this, index, stringByteLength); if (indexOutOfBoundsProfile.profile(this, normalizedIndex < 0 || normalizedIndex >= stringByteLength)) { return nil; @@ -3355,7 +3351,8 @@ Object stringByteSubstring(Object string, int index, int length, @Cached @Exclusive InlinedConditionProfile indexOutOfBoundsProfile, @Cached @Exclusive InlinedConditionProfile lengthTooLongProfile, @Cached @Shared RubyStringLibrary libString, - @Cached @Shared TruffleString.SubstringByteIndexNode substringNode) { + @Cached @Shared TruffleString.SubstringByteIndexNode substringNode, + @Cached @Shared StringHelperNodes.NormalizeIndexNode normalizeIndexNode) { if (negativeLengthProfile.profile(this, length < 0)) { return nil; } @@ -3363,7 +3360,7 @@ Object stringByteSubstring(Object string, int index, int length, var tString = libString.getTString(string); var encoding = libString.getEncoding(string); final int stringByteLength = tString.byteLength(encoding.tencoding); - final int normalizedIndex = normalizeIndexNode.executeNormalize(index, stringByteLength); + final int normalizedIndex = normalizeIndexNode.executeNormalize(this, index, stringByteLength); if (indexOutOfBoundsProfile.profile(this, normalizedIndex < 0 || normalizedIndex > stringByteLength)) { return nil; @@ -3423,7 +3420,7 @@ static Object stringChrAt(Object string, int byteIndex, @Bind("strings.getTString(string)") AbstractTruffleString originalTString, @Bind("strings.getEncoding(string)") RubyEncoding originalEncoding, @Bind("this") Node node) { - final RubyEncoding actualEncoding = getActualEncodingNode.execute(originalTString, originalEncoding); + final RubyEncoding actualEncoding = getActualEncodingNode.execute(node, originalTString, originalEncoding); var tstring = forceEncodingNode.execute(originalTString, originalEncoding.tencoding, actualEncoding.tencoding); @@ -4280,7 +4277,8 @@ Object stringSubstringGeneric(Object string, int codePointOffset, int codePointL return nil; } - int normalizedCodePointOffset = normalizeIndexNode.executeNormalize(codePointOffset, stringCodePointLength); + int normalizedCodePointOffset = normalizeIndexNode.executeNormalize(this, codePointOffset, + stringCodePointLength); if (negativeIndexProfile.profile(this, normalizedCodePointOffset < 0)) { return nil; } diff --git a/src/main/java/org/truffleruby/debug/TruffleDebugNodes.java b/src/main/java/org/truffleruby/debug/TruffleDebugNodes.java index cbadde04d6ee..70f8c86757f5 100644 --- a/src/main/java/org/truffleruby/debug/TruffleDebugNodes.java +++ b/src/main/java/org/truffleruby/debug/TruffleDebugNodes.java @@ -364,7 +364,7 @@ public abstract static class ASTNode extends CoreMethodArrayArgumentsNode { @Specialization Object ast(Object executable, @Cached ToCallTargetNode toCallTargetNode) { - final RootCallTarget callTarget = toCallTargetNode.execute(executable); + final RootCallTarget callTarget = toCallTargetNode.execute(this, executable); return ast(callTarget.getRootNode()); } @@ -391,7 +391,7 @@ public abstract static class PrintASTNode extends CoreMethodArrayArgumentsNode { @Specialization Object printAST(Object executable, @Cached ToCallTargetNode toCallTargetNode) { - final RootCallTarget callTarget = toCallTargetNode.execute(executable); + final RootCallTarget callTarget = toCallTargetNode.execute(this, executable); NodeUtil.printCompactTree(getContext().getEnvErrStream(), callTarget.getRootNode()); return nil; } @@ -403,7 +403,7 @@ public abstract static class PrintSourceSectionsNode extends CoreMethodArrayArgu @Specialization Object printSourceSections(Object executable, @Cached ToCallTargetNode toCallTargetNode) { - final RootCallTarget callTarget = toCallTargetNode.execute(executable); + final RootCallTarget callTarget = toCallTargetNode.execute(this, executable); NodeUtil.printSourceAttributionTree(getContext().getEnvErrStream(), callTarget.getRootNode()); return nil; } @@ -415,7 +415,7 @@ public abstract static class ASTSizeNode extends CoreMethodArrayArgumentsNode { @Specialization int astSize(Object executable, @Cached ToCallTargetNode toCallTargetNode) { - final RootCallTarget callTarget = toCallTargetNode.execute(executable); + final RootCallTarget callTarget = toCallTargetNode.execute(this, executable); return NodeUtil.countNodes(callTarget.getRootNode()); } } diff --git a/src/main/java/org/truffleruby/extra/TruffleGraalNodes.java b/src/main/java/org/truffleruby/extra/TruffleGraalNodes.java index 64b299f2dc81..b7073eee27c5 100644 --- a/src/main/java/org/truffleruby/extra/TruffleGraalNodes.java +++ b/src/main/java/org/truffleruby/extra/TruffleGraalNodes.java @@ -57,7 +57,7 @@ public abstract static class AlwaysSplitNode extends CoreMethodArrayArgumentsNod @Specialization Object alwaysSplit(Object executable, @Cached ToCallTargetNode toCallTargetNode) { - final RootCallTarget callTarget = toCallTargetNode.execute(executable); + final RootCallTarget callTarget = toCallTargetNode.execute(this, executable); if (getContext().getOptions().ALWAYS_SPLIT_HONOR) { RubyRootNode.of(callTarget).setSplit(Split.ALWAYS); } @@ -71,7 +71,7 @@ public abstract static class NeverSplitNode extends CoreMethodArrayArgumentsNode @Specialization Object neverSplit(Object executable, @Cached ToCallTargetNode toCallTargetNode) { - final RootCallTarget callTarget = toCallTargetNode.execute(executable); + final RootCallTarget callTarget = toCallTargetNode.execute(this, executable); if (getContext().getOptions().NEVER_SPLIT_HONOR) { RubyRootNode.of(callTarget).setSplit(Split.NEVER); } diff --git a/src/main/java/org/truffleruby/interop/ForeignToRubyArgumentsNode.java b/src/main/java/org/truffleruby/interop/ForeignToRubyArgumentsNode.java index 81a862b04ff9..31b463211f65 100644 --- a/src/main/java/org/truffleruby/interop/ForeignToRubyArgumentsNode.java +++ b/src/main/java/org/truffleruby/interop/ForeignToRubyArgumentsNode.java @@ -9,6 +9,9 @@ */ package org.truffleruby.interop; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.language.RubyBaseNode; import com.oracle.truffle.api.dsl.Cached; @@ -17,15 +20,17 @@ import com.oracle.truffle.api.nodes.ExplodeLoop; @GenerateUncached +@GenerateCached(false) +@GenerateInline public abstract class ForeignToRubyArgumentsNode extends RubyBaseNode { - public abstract Object[] executeConvert(Object[] args); + public abstract Object[] executeConvert(Node node, Object[] args); @ExplodeLoop @Specialization( guards = { "args.length == cachedArgsLength", "cachedArgsLength <= MAX_EXPLODE_SIZE" }, limit = "getLimit()") - Object[] convertCached(Object[] args, + static Object[] convertCached(Object[] args, @Cached("args.length") int cachedArgsLength, @Cached("foreignToRubyNodes(cachedArgsLength)") ForeignToRubyNode[] foreignToRubyNodes) { final Object[] convertedArgs = new Object[cachedArgsLength]; @@ -38,12 +43,12 @@ Object[] convertCached(Object[] args, } @Specialization(replaces = "convertCached") - Object[] convertUncached(Object[] args, + static Object[] convertUncached(Node node, Object[] args, @Cached ForeignToRubyNode foreignToRubyNode) { final Object[] convertedArgs = new Object[args.length]; for (int n = 0; n < args.length; n++) { - convertedArgs[n] = foreignToRubyNode.execute(this, args[n]); + convertedArgs[n] = foreignToRubyNode.execute(node, args[n]); } return convertedArgs; diff --git a/src/main/java/org/truffleruby/interop/IsStringLikeNode.java b/src/main/java/org/truffleruby/interop/IsStringLikeNode.java deleted file mode 100644 index 10ac7475c37a..000000000000 --- a/src/main/java/org/truffleruby/interop/IsStringLikeNode.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2016, 2023 Oracle and/or its affiliates. All rights reserved. This - * code is released under a tri EPL/GPL/LGPL license. You can use it, - * redistribute it and/or modify it under the terms of the: - * - * Eclipse Public License version 2.0, or - * GNU General Public License version 2, or - * GNU Lesser General Public License version 2.1. - */ -package org.truffleruby.interop; - -import org.truffleruby.core.string.RubyString; -import org.truffleruby.core.symbol.RubySymbol; -import org.truffleruby.core.string.ImmutableRubyString; -import org.truffleruby.language.RubyBaseNode; - -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; - -@GenerateUncached -public abstract class IsStringLikeNode extends RubyBaseNode { - - public static IsStringLikeNode create() { - return IsStringLikeNodeGen.create(); - } - - public abstract boolean executeIsStringLike(Object value); - - @Specialization - boolean isRubyStringStringLike(RubyString value) { - return true; - } - - @Specialization - boolean isImmutableRubyStringStringLike(ImmutableRubyString value) { - return true; - } - - @Specialization - boolean isRubySymbolStringLike(RubySymbol value) { - return true; - } - - @Specialization - boolean isJavaStringStringLike(String value) { - return true; - } - - @Specialization(guards = { "isNotRubyString(value)", "!isRubySymbol(value)", "!isString(value)" }) - boolean notStringLike(Object value) { - return false; - } - -} diff --git a/src/main/java/org/truffleruby/interop/ProxyForeignObject.java b/src/main/java/org/truffleruby/interop/ProxyForeignObject.java index 44628844e5fa..cf1cf7f937e0 100644 --- a/src/main/java/org/truffleruby/interop/ProxyForeignObject.java +++ b/src/main/java/org/truffleruby/interop/ProxyForeignObject.java @@ -9,6 +9,8 @@ */ package org.truffleruby.interop; +import com.oracle.truffle.api.dsl.Bind; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.RubyLanguage; import org.truffleruby.core.array.ArrayUtils; import org.truffleruby.language.dispatch.DispatchNode; @@ -49,7 +51,7 @@ protected Object send(Message message, Object[] rawArgs, @Cached DispatchNode dispatchNode, @Cached ForeignToRubyArgumentsNode foreignToRubyArgumentsNode, @CachedLibrary("this.delegate") ReflectionLibrary reflections, - @CachedLibrary("this") ReflectionLibrary node) throws Exception { + @Bind("$node") Node node) throws Exception { if (message == IS_META_INSTANCE) { // Workaround StackOverflowError in asserts (GR-37197) rawArgs = rawArgs.clone(); @@ -75,7 +77,7 @@ protected Object send(Message message, Object[] rawArgs, } } - Object[] convertedArgs = foreignToRubyArgumentsNode.executeConvert(loggingArgs); + Object[] convertedArgs = foreignToRubyArgumentsNode.executeConvert(node, loggingArgs); dispatchNode.call(logger, "<<", convertedArgs); } diff --git a/src/main/java/org/truffleruby/language/ImmutableRubyObject.java b/src/main/java/org/truffleruby/language/ImmutableRubyObject.java index 051654dd5c75..bca803563a35 100644 --- a/src/main/java/org/truffleruby/language/ImmutableRubyObject.java +++ b/src/main/java/org/truffleruby/language/ImmutableRubyObject.java @@ -10,7 +10,9 @@ package org.truffleruby.language; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.library.CachedLibrary; +import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.ConditionProfile; import com.oracle.truffle.api.utilities.TriState; import org.truffleruby.RubyContext; @@ -144,9 +146,10 @@ public boolean isMemberInvocable(String name, public Object invokeMember(String name, Object[] arguments, @Cached @Exclusive DispatchNode dispatchMember, @Cached @Exclusive ForeignToRubyArgumentsNode foreignToRubyArgumentsNode, - @Cached @Shared BranchProfile errorProfile) + @Cached @Shared BranchProfile errorProfile, + @Bind("$node") Node node) throws UnknownIdentifierException { - Object[] convertedArguments = foreignToRubyArgumentsNode.executeConvert(arguments); + Object[] convertedArguments = foreignToRubyArgumentsNode.executeConvert(node, arguments); Object result = dispatchMember.call(PRIVATE_RETURN_MISSING, this, name, convertedArguments); if (result == DispatchNode.MISSING) { errorProfile.enter(); diff --git a/src/main/java/org/truffleruby/language/RubyDynamicObject.java b/src/main/java/org/truffleruby/language/RubyDynamicObject.java index f8881fe50427..b1ef797548a6 100644 --- a/src/main/java/org/truffleruby/language/RubyDynamicObject.java +++ b/src/main/java/org/truffleruby/language/RubyDynamicObject.java @@ -670,9 +670,10 @@ public Object invokeMember(String name, Object[] arguments, @Cached @Exclusive ForeignToRubyArgumentsNode foreignToRubyArgumentsNode, @Cached @Shared ConditionProfile dynamicProfile, @Cached @Shared TranslateInteropRubyExceptionNode translateRubyException, - @Cached @Shared BranchProfile errorProfile) + @Cached @Shared BranchProfile errorProfile, + @Bind("$node") Node node) throws UnknownIdentifierException, UnsupportedTypeException, UnsupportedMessageException, ArityException { - Object[] convertedArguments = foreignToRubyArgumentsNode.executeConvert(arguments); + Object[] convertedArguments = foreignToRubyArgumentsNode.executeConvert(node, arguments); Object[] combinedArguments = ArrayUtils.unshift(convertedArguments, name); Object dynamic; try { @@ -877,10 +878,11 @@ public boolean isInstantiable( public Object instantiate(Object[] arguments, @Cached @Shared BranchProfile errorProfile, @Cached @Exclusive DispatchNode dispatchNode, - @Cached @Exclusive ForeignToRubyArgumentsNode foreignToRubyArgumentsNode) + @Cached @Exclusive ForeignToRubyArgumentsNode foreignToRubyArgumentsNode, + @Bind("$node") Node node) throws UnsupportedMessageException { Object instance = dispatchNode.call(PUBLIC_RETURN_MISSING, this, "new", - foreignToRubyArgumentsNode.executeConvert(arguments)); + foreignToRubyArgumentsNode.executeConvert(node, arguments)); // TODO (pitr-ch 28-Jan-2020): we should translate argument-error caused by bad arity to ArityException if (instance == DispatchNode.MISSING) { diff --git a/src/main/java/org/truffleruby/language/methods/BlockDefinitionNode.java b/src/main/java/org/truffleruby/language/methods/BlockDefinitionNode.java index 35f061d07194..dc1b1709bda8 100644 --- a/src/main/java/org/truffleruby/language/methods/BlockDefinitionNode.java +++ b/src/main/java/org/truffleruby/language/methods/BlockDefinitionNode.java @@ -9,6 +9,8 @@ */ package org.truffleruby.language.methods; +import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Specialization; import org.truffleruby.core.kernel.TruffleKernelNodes.GetSpecialVariableStorage; import org.truffleruby.core.proc.ProcOperations; import org.truffleruby.core.proc.ProcCallTargets; @@ -20,13 +22,12 @@ import org.truffleruby.language.control.BreakID; import org.truffleruby.language.control.FrameOnStackMarker; -import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.frame.VirtualFrame; import org.truffleruby.parser.BodyTranslator; /** Create a Ruby Proc to pass as a block to the called method. The literal block is represented as call targets and a * SharedMethodInfo. This is executed at the call site just before dispatch. */ -public final class BlockDefinitionNode extends RubyContextSourceNode { +public abstract class BlockDefinitionNode extends RubyContextSourceNode { private final ProcType type; private final SharedMethodInfo sharedMethodInfo; @@ -34,9 +35,6 @@ public final class BlockDefinitionNode extends RubyContextSourceNode { private final BreakID breakID; private final int frameOnStackMarkerSlot; - @Child private GetSpecialVariableStorage readSpecialVariableStorageNode; - @Child private WithoutVisibilityNode withoutVisibilityNode; - public BlockDefinitionNode( ProcType type, SharedMethodInfo sharedMethodInfo, @@ -50,15 +48,18 @@ public BlockDefinitionNode( this.breakID = breakID; this.frameOnStackMarkerSlot = frameOnStackMarkerSlot; - readSpecialVariableStorageNode = GetSpecialVariableStorage.create(); } public BreakID getBreakID() { return breakID; } - @Override - public RubyProc execute(VirtualFrame frame) { + public abstract RubyProc execute(VirtualFrame virtualFrame); + + @Specialization + RubyProc doBlockDefinition(VirtualFrame frame, + @Cached GetSpecialVariableStorage readSpecialVariableStorageNode, + @Cached WithoutVisibilityNode withoutVisibilityNode) { final FrameOnStackMarker frameOnStackMarker; if (frameOnStackMarkerSlot != BodyTranslator.NO_FRAME_ON_STACK_MARKER) { frameOnStackMarker = (FrameOnStackMarker) frame.getObject(frameOnStackMarkerSlot); @@ -74,23 +75,16 @@ public RubyProc execute(VirtualFrame frame) { sharedMethodInfo, callTargets, frame.materialize(), - readSpecialVariableStorageNode.executeCached(frame), + readSpecialVariableStorageNode.execute(frame, this), RubyArguments.getMethod(frame), frameOnStackMarker, - executeWithoutVisibility(RubyArguments.getDeclarationContext(frame))); + withoutVisibilityNode.executeWithoutVisibility(this, RubyArguments.getDeclarationContext(frame))); } - private DeclarationContext executeWithoutVisibility(DeclarationContext ctxIn) { - if (withoutVisibilityNode == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - withoutVisibilityNode = insert(WithoutVisibilityNodeGen.create()); - } - return withoutVisibilityNode.executeWithoutVisibility(ctxIn); - } @Override public RubyNode cloneUninitialized() { - var copy = new BlockDefinitionNode(type, sharedMethodInfo, callTargets, breakID, frameOnStackMarkerSlot); + var copy = BlockDefinitionNodeGen.create(type, sharedMethodInfo, callTargets, breakID, frameOnStackMarkerSlot); return copy.copyFlags(this); } diff --git a/src/main/java/org/truffleruby/language/methods/CanBindMethodToModuleNode.java b/src/main/java/org/truffleruby/language/methods/CanBindMethodToModuleNode.java index e20131d58fd5..64709d0d9535 100644 --- a/src/main/java/org/truffleruby/language/methods/CanBindMethodToModuleNode.java +++ b/src/main/java/org/truffleruby/language/methods/CanBindMethodToModuleNode.java @@ -9,6 +9,9 @@ */ package org.truffleruby.language.methods; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.core.module.ModuleOperations; import org.truffleruby.core.module.RubyModule; import org.truffleruby.language.RubyBaseNode; @@ -17,16 +20,18 @@ import com.oracle.truffle.api.dsl.Specialization; /** Caches {@link ModuleOperations#canBindMethodTo} for a method. */ +@GenerateInline +@GenerateCached(false) public abstract class CanBindMethodToModuleNode extends RubyBaseNode { - public abstract boolean executeCanBindMethodToModule(InternalMethod method, RubyModule module); + public abstract boolean executeCanBindMethodToModule(Node node, InternalMethod method, RubyModule module); @Specialization( guards = { "method.getDeclaringModule() == declaringModule", "module == cachedModule" }, limit = "getCacheLimit()") - boolean canBindMethodToCached(InternalMethod method, RubyModule module, + static boolean canBindMethodToCached(InternalMethod method, RubyModule module, @Cached("method.getDeclaringModule()") RubyModule declaringModule, @Cached("module") RubyModule cachedModule, @Cached("canBindMethodTo(method, cachedModule)") boolean canBindMethodTo) { @@ -34,11 +39,11 @@ boolean canBindMethodToCached(InternalMethod method, RubyModule module, } @Specialization - boolean canBindMethodToUncached(InternalMethod method, RubyModule module) { + static boolean canBindMethodToUncached(InternalMethod method, RubyModule module) { return canBindMethodTo(method, module); } - protected boolean canBindMethodTo(InternalMethod method, RubyModule module) { + protected static boolean canBindMethodTo(InternalMethod method, RubyModule module) { return ModuleOperations.canBindMethodTo(method, module); } diff --git a/src/main/java/org/truffleruby/language/methods/WithoutVisibilityNode.java b/src/main/java/org/truffleruby/language/methods/WithoutVisibilityNode.java index ffb9f3379d9e..496656162ced 100644 --- a/src/main/java/org/truffleruby/language/methods/WithoutVisibilityNode.java +++ b/src/main/java/org/truffleruby/language/methods/WithoutVisibilityNode.java @@ -9,25 +9,30 @@ */ package org.truffleruby.language.methods; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.nodes.Node; import org.truffleruby.language.RubyBaseNode; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; +@GenerateCached(false) +@GenerateInline public abstract class WithoutVisibilityNode extends RubyBaseNode { - public abstract DeclarationContext executeWithoutVisibility(DeclarationContext declarationContext); + public abstract DeclarationContext executeWithoutVisibility(Node node, DeclarationContext declarationContext); @Specialization(guards = { "isSingleContext()", "declarationContext == cachedContext" }, limit = "getDefaultCacheLimit()") - DeclarationContext cached(DeclarationContext declarationContext, + static DeclarationContext cached(DeclarationContext declarationContext, @Cached("declarationContext") DeclarationContext cachedContext, @Cached("uncached(cachedContext)") DeclarationContext without) { return without; } @Specialization(replaces = "cached") - DeclarationContext uncached(DeclarationContext declarationContext) { + static DeclarationContext uncached(DeclarationContext declarationContext) { return declarationContext.withVisibility(null); } diff --git a/src/main/java/org/truffleruby/language/objects/CheckIVarNameNode.java b/src/main/java/org/truffleruby/language/objects/CheckIVarNameNode.java index daab4e15abbe..a9b6b7e0a39f 100644 --- a/src/main/java/org/truffleruby/language/objects/CheckIVarNameNode.java +++ b/src/main/java/org/truffleruby/language/objects/CheckIVarNameNode.java @@ -10,6 +10,9 @@ package org.truffleruby.language.objects; import com.oracle.truffle.api.dsl.Cached.Shared; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; +import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import org.truffleruby.core.symbol.RubySymbol; import org.truffleruby.language.RubyBaseNode; @@ -22,40 +25,40 @@ import com.oracle.truffle.api.dsl.Specialization; @ImportStatic(Identifiers.class) +@GenerateInline +@GenerateCached(false) public abstract class CheckIVarNameNode extends RubyBaseNode { /** Pass both the j.l.String name and the original name, the original name can be faster to check and the j.l.String * name is needed by all callers so it is better for footprint that callers convert to j.l.String */ - public abstract void execute(Object object, String name, Object originalName); + public abstract void execute(Node node, Object object, String name, Object originalName); @Specialization - void checkSymbol(Object object, String name, RubySymbol originalName, + static void checkSymbol(Node node, Object object, String name, RubySymbol originalName, @Cached @Shared InlinedBranchProfile errorProfile) { if (originalName.getType() != IdentifierType.INSTANCE) { - errorProfile.enter(this); - throw new RaiseException(getContext(), getContext().getCoreExceptions().nameErrorInstanceNameNotAllowable( - name, - object, - this)); + errorProfile.enter(node); + throw new RaiseException(getContext(node), + getContext(node).getCoreExceptions().nameErrorInstanceNameNotAllowable(name, object, node)); } } @Specialization( guards = { "name == cachedName", "isValidInstanceVariableName(cachedName)", "!isRubySymbol(originalName)" }, limit = "getDynamicObjectCacheLimit()") - void cached(Object object, String name, Object originalName, + static void cached(Object object, String name, Object originalName, @Cached("name") String cachedName) { } @Specialization(replaces = "cached", guards = "!isRubySymbol(originalName)") - void uncached(Object object, String name, Object originalName, + static void uncached(Node node, Object object, String name, Object originalName, @Cached @Shared InlinedBranchProfile errorProfile) { if (!Identifiers.isValidInstanceVariableName(name)) { - errorProfile.enter(this); - throw new RaiseException(getContext(), coreExceptions().nameErrorInstanceNameNotAllowable( + errorProfile.enter(node); + throw new RaiseException(getContext(node), coreExceptions(node).nameErrorInstanceNameNotAllowable( name, object, - this)); + node)); } } } diff --git a/src/main/java/org/truffleruby/language/objects/classvariables/CheckClassVariableNameNode.java b/src/main/java/org/truffleruby/language/objects/classvariables/CheckClassVariableNameNode.java index 635d3f162304..d6644be23cb8 100644 --- a/src/main/java/org/truffleruby/language/objects/classvariables/CheckClassVariableNameNode.java +++ b/src/main/java/org/truffleruby/language/objects/classvariables/CheckClassVariableNameNode.java @@ -10,8 +10,11 @@ package org.truffleruby.language.objects.classvariables; import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.InlinedBranchProfile; import org.truffleruby.language.RubyBaseNode; import org.truffleruby.language.RubyDynamicObject; @@ -19,25 +22,27 @@ import org.truffleruby.parser.Identifiers; @ImportStatic(Identifiers.class) +@GenerateInline +@GenerateCached(false) public abstract class CheckClassVariableNameNode extends RubyBaseNode { - public abstract void execute(RubyDynamicObject object, String name); + public abstract void execute(Node node, RubyDynamicObject object, String name); @Specialization(guards = { "name == cachedName", "isValidClassVariableName(cachedName)" }, limit = "getDefaultCacheLimit()") - void cached(RubyDynamicObject object, String name, + static void cached(RubyDynamicObject object, String name, @Cached("name") String cachedName) { } @Specialization(replaces = "cached") - void uncached(RubyDynamicObject object, String name, + static void uncached(Node node, RubyDynamicObject object, String name, @Cached InlinedBranchProfile errorProfile) { if (!Identifiers.isValidClassVariableName(name)) { - errorProfile.enter(this); - throw new RaiseException(getContext(), coreExceptions().nameErrorInstanceNameNotAllowable( + errorProfile.enter(node); + throw new RaiseException(getContext(node), coreExceptions(node).nameErrorInstanceNameNotAllowable( name, object, - this)); + node)); } } diff --git a/src/main/java/org/truffleruby/language/objects/classvariables/LookupClassVariableNode.java b/src/main/java/org/truffleruby/language/objects/classvariables/LookupClassVariableNode.java index f9ebd7ead1c2..0cdf9346acd2 100644 --- a/src/main/java/org/truffleruby/language/objects/classvariables/LookupClassVariableNode.java +++ b/src/main/java/org/truffleruby/language/objects/classvariables/LookupClassVariableNode.java @@ -32,7 +32,7 @@ Object lookupClassVariable(RubyModule module, String name, @Cached LookupClassVariableStorageNode lookupClassVariableStorageNode, @Cached InlinedConditionProfile noStorageProfile, @CachedLibrary(limit = "getDynamicObjectCacheLimit()") DynamicObjectLibrary objectLibrary) { - final ClassVariableStorage classVariables = lookupClassVariableStorageNode.execute(module, name); + final ClassVariableStorage classVariables = lookupClassVariableStorageNode.execute(this, module, name); if (noStorageProfile.profile(this, classVariables == null)) { return null; diff --git a/src/main/java/org/truffleruby/language/objects/classvariables/LookupClassVariableStorageNode.java b/src/main/java/org/truffleruby/language/objects/classvariables/LookupClassVariableStorageNode.java index 596d234b3ea5..f54057f0eb1d 100644 --- a/src/main/java/org/truffleruby/language/objects/classvariables/LookupClassVariableStorageNode.java +++ b/src/main/java/org/truffleruby/language/objects/classvariables/LookupClassVariableStorageNode.java @@ -11,19 +11,24 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Bind; +import com.oracle.truffle.api.dsl.GenerateCached; +import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.library.CachedLibrary; +import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.object.DynamicObjectLibrary; import org.truffleruby.core.module.ModuleOperations; import org.truffleruby.core.module.RubyModule; import org.truffleruby.language.RubyBaseNode; +@GenerateCached(false) +@GenerateInline public abstract class LookupClassVariableStorageNode extends RubyBaseNode { - public abstract ClassVariableStorage execute(RubyModule module, String name); + public abstract ClassVariableStorage execute(Node node, RubyModule module, String name); @Specialization(guards = "objectLibrary.containsKey(classVariableStorage, name)") - ClassVariableStorage lookupClassVariable(RubyModule module, String name, + static ClassVariableStorage lookupClassVariable(RubyModule module, String name, @Bind("module.fields.getClassVariables()") ClassVariableStorage classVariableStorage, @CachedLibrary(limit = "getDynamicObjectCacheLimit()") DynamicObjectLibrary objectLibrary) { return classVariableStorage; @@ -31,7 +36,7 @@ ClassVariableStorage lookupClassVariable(RubyModule module, String name, @Specialization(replaces = "lookupClassVariable") @TruffleBoundary - ClassVariableStorage uncachedLookupClassVariable(RubyModule module, String name) { + static ClassVariableStorage uncachedLookupClassVariable(RubyModule module, String name) { return ModuleOperations.classVariableLookup(module, true, m -> { final ClassVariableStorage classVariables = m.fields.getClassVariables(); if (classVariables.getShape().hasProperty(name)) { diff --git a/src/main/java/org/truffleruby/language/objects/classvariables/ResolveTargetModuleForClassVariablesNode.java b/src/main/java/org/truffleruby/language/objects/classvariables/ResolveTargetModuleForClassVariablesNode.java index d93d18dd67fc..05f603942d2d 100644 --- a/src/main/java/org/truffleruby/language/objects/classvariables/ResolveTargetModuleForClassVariablesNode.java +++ b/src/main/java/org/truffleruby/language/objects/classvariables/ResolveTargetModuleForClassVariablesNode.java @@ -10,12 +10,16 @@ package org.truffleruby.language.objects.classvariables; import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.Specialization; import org.truffleruby.core.module.RubyModule; import org.truffleruby.language.LexicalScope; import org.truffleruby.language.RubyBaseNode; import org.truffleruby.language.RubyGuards; +/** Not inlined since the usage is in {@link WriteClassVariableNode} or {@link ReadClassVariableNode} which are not DSL + * nodes. */ +@GenerateInline(false) public abstract class ResolveTargetModuleForClassVariablesNode extends RubyBaseNode { public static ResolveTargetModuleForClassVariablesNode create() { diff --git a/src/main/java/org/truffleruby/parser/MethodTranslator.java b/src/main/java/org/truffleruby/parser/MethodTranslator.java index bd5bc6c62d68..eac9f1c0a04b 100644 --- a/src/main/java/org/truffleruby/parser/MethodTranslator.java +++ b/src/main/java/org/truffleruby/parser/MethodTranslator.java @@ -17,6 +17,7 @@ import org.truffleruby.language.control.IfElseNodeGen; import org.truffleruby.language.control.NotNodeGen; import org.truffleruby.language.locals.FindDeclarationVariableNodes.FrameSlotAndDepth; +import org.truffleruby.language.methods.BlockDefinitionNodeGen; import org.truffleruby.language.methods.CachedLazyCallTargetSupplier; import org.truffleruby.core.IsNilNode; import org.truffleruby.core.cast.SplatCastNode; @@ -178,7 +179,7 @@ public BlockDefinitionNode compileBlockNode(SourceIndexLength sourceSection, Par callTargets = new ProcCallTargets(procCompiler.get(), null, lambdaCompiler); } - final BlockDefinitionNode ret = new BlockDefinitionNode( + final BlockDefinitionNode ret = BlockDefinitionNodeGen.create( emitLambda ? ProcType.LAMBDA : ProcType.PROC, environment.getSharedMethodInfo(), callTargets,