Skip to content

Commit b64cd1d

Browse files
committed
[GR-17457] Refactor nodes to get rid of CreateCast (part 3)
PullRequest: truffleruby/3897
2 parents e941116 + ca1e41c commit b64cd1d

File tree

54 files changed

+893
-1044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+893
-1044
lines changed

spec/truffle/parsing/fixtures/instance_variables/writing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ focused_on_node: "org.truffleruby.language.objects.WriteInstanceVariableNode"
44
ruby: |
55
@foo = 42
66
ast: |
7-
WriteInstanceVariableNode
7+
WriteInstanceVariableNodeGen
88
attributes:
99
flags = 1
1010
frozenProfile = false

spec/truffle/parsing/fixtures/operators/&&=/variable_assignments/instance_variable.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ast: |
2727
attributes:
2828
frameSlot = 0
2929
right =
30-
WriteInstanceVariableNode
30+
WriteInstanceVariableNodeGen
3131
attributes:
3232
flags = 0
3333
frozenProfile = false

spec/truffle/parsing/fixtures/operators/multi_assignments/instance_variables.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ast: |
1111
flags = 1
1212
children:
1313
preNodes = [
14-
WriteInstanceVariableNode
14+
WriteInstanceVariableNodeGen
1515
attributes:
1616
flags = 0
1717
frozenProfile = false
@@ -21,7 +21,7 @@ ast: |
2121
ReadFrameSlotNodeGen
2222
attributes:
2323
frameSlot = 0
24-
WriteInstanceVariableNode
24+
WriteInstanceVariableNodeGen
2525
attributes:
2626
flags = 0
2727
frozenProfile = false
@@ -31,7 +31,7 @@ ast: |
3131
ReadFrameSlotNodeGen
3232
attributes:
3333
frameSlot = 0
34-
WriteInstanceVariableNode
34+
WriteInstanceVariableNodeGen
3535
attributes:
3636
flags = 0
3737
frozenProfile = false

spec/truffle/parsing/fixtures/operators/||=/variable_assignments/instance_variable.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ast: |
2222
attributes:
2323
frameSlot = 0
2424
right =
25-
WriteInstanceVariableNode
25+
WriteInstanceVariableNodeGen
2626
attributes:
2727
flags = 0
2828
frozenProfile = false

spec/truffle/parsing/fixtures/rescue/capturing/with_instance_variable.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ast: |
5252
flags = 0
5353
children:
5454
body = [
55-
WriteInstanceVariableNode
55+
WriteInstanceVariableNodeGen
5656
attributes:
5757
flags = 0
5858
frozenProfile = false

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

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.truffleruby.annotations.Primitive;
3535
import org.truffleruby.annotations.Visibility;
3636
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
37-
import org.truffleruby.builtins.CoreMethodNode;
3837
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
3938
import org.truffleruby.cext.UnwrapNode.UnwrapCArrayNode;
4039
import org.truffleruby.core.MarkingService.ExtensionCallStack;
@@ -87,7 +86,6 @@
8786
import org.truffleruby.language.RubyBaseNode;
8887
import org.truffleruby.language.RubyDynamicObject;
8988
import org.truffleruby.language.RubyGuards;
90-
import org.truffleruby.language.RubyNode;
9189
import org.truffleruby.language.RubyRootNode;
9290
import org.truffleruby.language.WarnNode;
9391
import org.truffleruby.language.arguments.ArgumentsDescriptor;
@@ -127,7 +125,6 @@
127125
import com.oracle.truffle.api.dsl.Cached;
128126
import com.oracle.truffle.api.dsl.Cached.Shared;
129127
import com.oracle.truffle.api.dsl.Fallback;
130-
import com.oracle.truffle.api.dsl.NodeChild;
131128
import com.oracle.truffle.api.dsl.ReportPolymorphism;
132129
import com.oracle.truffle.api.dsl.Specialization;
133130
import com.oracle.truffle.api.frame.Frame;
@@ -139,8 +136,6 @@
139136
import com.oracle.truffle.api.nodes.IndirectCallNode;
140137
import com.oracle.truffle.api.nodes.Node;
141138
import com.oracle.truffle.api.nodes.RootNode;
142-
import com.oracle.truffle.api.profiles.BranchProfile;
143-
import com.oracle.truffle.api.profiles.ConditionProfile;
144139
import com.oracle.truffle.api.source.SourceSection;
145140
import org.truffleruby.parser.RubySource;
146141

@@ -682,7 +677,7 @@ public abstract static class DBL2BIGNode extends CoreMethodArrayArgumentsNode {
682677
@Specialization
683678
protected Object dbl2big(double num,
684679
@Cached FloatToIntegerNode floatToIntegerNode) {
685-
return floatToIntegerNode.fixnumOrBignum(num);
680+
return floatToIntegerNode.execute(this, num);
686681
}
687682

688683
}
@@ -996,9 +991,7 @@ protected ImmutableRubyString rbStrUnlockTmpImmutable(ImmutableRubyString string
996991
}
997992

998993
@CoreMethod(names = "rb_const_get", onSingleton = true, required = 2)
999-
@NodeChild(value = "module", type = RubyNode.class)
1000-
@NodeChild(value = "name", type = RubyNode.class)
1001-
public abstract static class RbConstGetNode extends CoreMethodNode {
994+
public abstract static class RbConstGetNode extends CoreMethodArrayArgumentsNode {
1002995

1003996
@Child private LookupConstantNode lookupConstantNode = LookupConstantNode.create(true, true);
1004997

@@ -1015,9 +1008,7 @@ protected Object rbConstGet(RubyModule module, Object name,
10151008
}
10161009

10171010
@CoreMethod(names = "rb_const_get_from", onSingleton = true, required = 2)
1018-
@NodeChild(value = "module", type = RubyNode.class)
1019-
@NodeChild(value = "name", type = RubyNode.class)
1020-
public abstract static class RbConstGetFromNode extends CoreMethodNode {
1011+
public abstract static class RbConstGetFromNode extends CoreMethodArrayArgumentsNode {
10211012

10221013
@Child private LookupConstantNode lookupConstantNode = LookupConstantNode.create(true, false);
10231014

@@ -1034,10 +1025,7 @@ protected Object rbConstGetFrom(RubyModule module, Object name,
10341025
}
10351026

10361027
@CoreMethod(names = "rb_const_set", onSingleton = true, required = 3)
1037-
@NodeChild(value = "module", type = RubyNode.class)
1038-
@NodeChild(value = "name", type = RubyNode.class)
1039-
@NodeChild(value = "value", type = RubyNode.class)
1040-
public abstract static class RbConstSetNode extends CoreMethodNode {
1028+
public abstract static class RbConstSetNode extends CoreMethodArrayArgumentsNode {
10411029

10421030

10431031
@Specialization
@@ -1106,11 +1094,10 @@ protected int getCacheLimit() {
11061094
@CoreMethod(names = "cext_module_function", onSingleton = true, required = 2)
11071095
public abstract static class CextModuleFunctionNode extends CoreMethodArrayArgumentsNode {
11081096

1109-
@Child SetMethodVisibilityNode setMethodVisibilityNode = SetMethodVisibilityNode.create();
1110-
11111097
@Specialization
1112-
protected RubyModule cextModuleFunction(RubyModule module, RubySymbol name) {
1113-
setMethodVisibilityNode.execute(module, name, Visibility.MODULE_FUNCTION);
1098+
protected RubyModule cextModuleFunction(RubyModule module, RubySymbol name,
1099+
@Cached SetMethodVisibilityNode setMethodVisibilityNode) {
1100+
setMethodVisibilityNode.execute(this, module, name, Visibility.MODULE_FUNCTION);
11141101
return module;
11151102
}
11161103

@@ -1960,14 +1947,16 @@ public abstract static class RBSprintfFormatNode extends CoreMethodArrayArgument
19601947
@Specialization(
19611948
guards = {
19621949
"libFormat.isRubyString(format)",
1963-
"equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
1950+
"equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
19641951
limit = "2")
1965-
protected Object typesCached(VirtualFrame frame, Object format,
1952+
1953+
protected static Object typesCached(VirtualFrame frame, Object format,
19661954
@Cached @Shared RubyStringLibrary libFormat,
19671955
@Cached("asTruffleStringUncached(format)") TruffleString cachedFormat,
19681956
@Cached("libFormat.getEncoding(format)") RubyEncoding cachedEncoding,
19691957
@Cached("compileArgTypes(cachedFormat, cachedEncoding, byteArrayNode)") RubyArray cachedTypes,
1970-
@Cached StringHelperNodes.EqualSameEncodingNode equalNode) {
1958+
@Cached StringHelperNodes.EqualSameEncodingNode equalNode,
1959+
@Bind("this") Node node) {
19711960
return cachedTypes;
19721961
}
19731962

@@ -1993,41 +1982,43 @@ protected RubyArray compileArgTypes(AbstractTruffleString format, RubyEncoding e
19931982
@ReportPolymorphism
19941983
public abstract static class RBSprintfNode extends CoreMethodArrayArgumentsNode {
19951984

1996-
@Child private TruffleString.FromByteArrayNode fromByteArrayNode;
1997-
1998-
private final BranchProfile exceptionProfile = BranchProfile.create();
1999-
private final ConditionProfile resizeProfile = ConditionProfile.create();
2000-
20011985
@Specialization(
20021986
guards = {
20031987
"libFormat.isRubyString(format)",
2004-
"equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
1988+
"equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
20051989
limit = "2")
2006-
protected RubyString formatCached(Object format, Object stringReader, RubyArray argArray,
1990+
protected static RubyString formatCached(Object format, Object stringReader, RubyArray argArray,
20071991
@Cached @Shared ArrayToObjectArrayNode arrayToObjectArrayNode,
20081992
@Cached @Shared RubyStringLibrary libFormat,
1993+
@Cached @Shared InlinedBranchProfile exceptionProfile,
1994+
@Cached @Shared InlinedConditionProfile resizeProfile,
1995+
@Cached @Shared TruffleString.FromByteArrayNode fromByteArrayNode,
20091996
@Cached("asTruffleStringUncached(format)") TruffleString cachedFormat,
20101997
@Cached("libFormat.getEncoding(format)") RubyEncoding cachedEncoding,
20111998
@Cached("cachedFormat.byteLength(cachedEncoding.tencoding)") int cachedFormatLength,
20121999
@Cached("create(compileFormat(cachedFormat, cachedEncoding, stringReader))") DirectCallNode formatNode,
2013-
@Cached StringHelperNodes.EqualSameEncodingNode equalNode) {
2000+
@Cached StringHelperNodes.EqualSameEncodingNode equalNode,
2001+
@Bind("this") Node node) {
20142002
final BytesResult result;
20152003
final Object[] arguments = arrayToObjectArrayNode.executeToObjectArray(argArray);
20162004
try {
20172005
result = (BytesResult) formatNode.call(new Object[]{ arguments, arguments.length, null });
20182006
} catch (FormatException e) {
2019-
exceptionProfile.enter();
2020-
throw FormatExceptionTranslator.translate(getContext(), this, e);
2007+
exceptionProfile.enter(node);
2008+
throw FormatExceptionTranslator.translate(getContext(node), node, e);
20212009
}
20222010

2023-
return finishFormat(cachedFormatLength, result);
2011+
return finishFormat(node, cachedFormatLength, result, resizeProfile, fromByteArrayNode);
20242012
}
20252013

20262014
@Specialization(
20272015
guards = "libFormat.isRubyString(format)",
20282016
replaces = "formatCached", limit = "1")
20292017
protected RubyString formatUncached(Object format, Object stringReader, RubyArray argArray,
20302018
@Cached IndirectCallNode formatNode,
2019+
@Cached @Shared InlinedBranchProfile exceptionProfile,
2020+
@Cached @Shared InlinedConditionProfile resizeProfile,
2021+
@Cached @Shared TruffleString.FromByteArrayNode fromByteArrayNode,
20312022
@Cached @Shared ArrayToObjectArrayNode arrayToObjectArrayNode,
20322023
@Cached @Shared RubyStringLibrary libFormat) {
20332024
var tstring = libFormat.getTString(format);
@@ -2038,26 +2029,23 @@ protected RubyString formatUncached(Object format, Object stringReader, RubyArra
20382029
result = (BytesResult) formatNode.call(compileFormat(tstring, encoding, stringReader),
20392030
new Object[]{ arguments, arguments.length, null });
20402031
} catch (FormatException e) {
2041-
exceptionProfile.enter();
2032+
exceptionProfile.enter(this);
20422033
throw FormatExceptionTranslator.translate(getContext(), this, e);
20432034
}
20442035

2045-
return finishFormat(tstring.byteLength(encoding.tencoding), result);
2036+
return finishFormat(this, tstring.byteLength(encoding.tencoding), result, resizeProfile, fromByteArrayNode);
20462037
}
20472038

2048-
private RubyString finishFormat(int formatLength, BytesResult result) {
2039+
private static RubyString finishFormat(Node node, int formatLength, BytesResult result,
2040+
InlinedConditionProfile resizeProfile, TruffleString.FromByteArrayNode fromByteArrayNode) {
20492041
byte[] bytes = result.getOutput();
20502042

2051-
if (resizeProfile.profile(bytes.length != result.getOutputLength())) {
2043+
if (resizeProfile.profile(node, bytes.length != result.getOutputLength())) {
20522044
bytes = Arrays.copyOf(bytes, result.getOutputLength());
20532045
}
20542046

2055-
if (fromByteArrayNode == null) {
2056-
CompilerDirectives.transferToInterpreterAndInvalidate();
2057-
fromByteArrayNode = insert(TruffleString.FromByteArrayNode.create());
2058-
}
2059-
2060-
return createString(fromByteArrayNode, bytes, result.getEncoding().getEncodingForLength(formatLength));
2047+
return createString(node, fromByteArrayNode, bytes,
2048+
result.getEncoding().getEncodingForLength(formatLength));
20612049
}
20622050

20632051
@TruffleBoundary

0 commit comments

Comments
 (0)