Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-17457] Convert nodes to DSL inlinable - part 2 #3298

Merged
merged 18 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/main/java/org/truffleruby/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -638,15 +639,15 @@ 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++) {
Object arg = rest[i];
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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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))) {
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/org/truffleruby/core/cast/ToAryNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,35 @@
*/
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;

import com.oracle.truffle.api.dsl.Cached;
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);
}
}
13 changes: 9 additions & 4 deletions src/main/java/org/truffleruby/core/cast/ToCallTargetNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/org/truffleruby/core/cast/ToPathNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
17 changes: 10 additions & 7 deletions src/main/java/org/truffleruby/core/encoding/EncodingNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
Loading
Loading