Skip to content

Commit 6ab9956

Browse files
committed
[GR-45043] Cleanup after migrating to Prism. Part 2
PullRequest: truffleruby/4153
2 parents dd0c59d + 72b109d commit 6ab9956

27 files changed

+321
-337
lines changed

doc/user/compatibility.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ The JVM enforces a maximum array size of 2<sup>31</sup>-1 (by storing the size i
121121
That is, Strings must be smaller than 2GB. This is the same restriction as JRuby.
122122
A possible workaround could be to use natively-allocated strings, but it would be a large effort to support every Ruby String operation on native strings.
123123

124+
### Strings in UTF-16 and UTF-32 encoding
125+
126+
TruffleRuby does not support UTF-16 strings with an odd number of bytes (in native endianness). Similarly, with UTF-32 it needs to be a multiple of 4. This is necessary for optimizations, compression, invariants, etc.
127+
124128
### Threads detect interrupts at different points
125129

126130
TruffleRuby threads may detect that they have been interrupted at different points in the program compared to where they would on MRI.

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_else_branch.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ ast: |
9595
attributes:
9696
flags = 0
9797
frameSlot = 2 # %case_0
98-
sourceCharIndex = 0
99-
sourceLength = 89
98+
sourceCharIndex = -1
99+
sourceLength = 0
100100
type = FRAME_LOCAL
101101
elseBody =
102102
IfElseNodeGen
@@ -127,8 +127,8 @@ ast: |
127127
attributes:
128128
flags = 0
129129
frameSlot = 2 # %case_0
130-
sourceCharIndex = 0
131-
sourceLength = 89
130+
sourceCharIndex = -1
131+
sourceLength = 0
132132
type = FRAME_LOCAL
133133
elseBody =
134134
StringLiteralNode

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_multiple_values.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ ast: |
9595
attributes:
9696
flags = 0
9797
frameSlot = 2 # %case_0
98-
sourceCharIndex = 0
99-
sourceLength = 39
98+
sourceCharIndex = -1
99+
sourceLength = 0
100100
type = FRAME_LOCAL
101101
right =
102102
InlinedCaseEqualNodeGen
@@ -120,8 +120,8 @@ ast: |
120120
attributes:
121121
flags = 0
122122
frameSlot = 2 # %case_0
123-
sourceCharIndex = 0
124-
sourceLength = 39
123+
sourceCharIndex = -1
124+
sourceLength = 0
125125
type = FRAME_LOCAL
126126
elseBody =
127127
NilLiteralNode

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_single_value.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ ast: |
9494
attributes:
9595
flags = 0
9696
frameSlot = 2 # %case_0
97-
sourceCharIndex = 0
98-
sourceLength = 74
97+
sourceCharIndex = -1
98+
sourceLength = 0
9999
type = FRAME_LOCAL
100100
elseBody =
101101
IfElseNodeGen
@@ -126,8 +126,8 @@ ast: |
126126
attributes:
127127
flags = 0
128128
frameSlot = 2 # %case_0
129-
sourceCharIndex = 0
130-
sourceLength = 74
129+
sourceCharIndex = -1
130+
sourceLength = 0
131131
type = FRAME_LOCAL
132132
elseBody =
133133
NilLiteralNode

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_splat_operator.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ ast: |
7171
attributes:
7272
flags = 0
7373
frameSlot = 2 # %case_0
74-
sourceCharIndex = 0
75-
sourceLength = 28
74+
sourceCharIndex = -1
75+
sourceLength = 0
7676
type = FRAME_LOCAL
7777
]
7878
receiver =

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_splat_operator_and_following_element.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ ast: |
9494
attributes:
9595
flags = 0
9696
frameSlot = 2 # %case_0
97-
sourceCharIndex = 0
98-
sourceLength = 32
97+
sourceCharIndex = -1
98+
sourceLength = 0
9999
type = FRAME_LOCAL
100100
]
101101
receiver =

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_splat_operator_and_following_elements.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ ast: |
100100
attributes:
101101
flags = 0
102102
frameSlot = 2 # %case_0
103-
sourceCharIndex = 0
104-
sourceLength = 40
103+
sourceCharIndex = -1
104+
sourceLength = 0
105105
type = FRAME_LOCAL
106106
]
107107
receiver =

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_splat_operator_and_preceding_and_following_element.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ ast: |
109109
attributes:
110110
flags = 0
111111
frameSlot = 2 # %case_0
112-
sourceCharIndex = 0
113-
sourceLength = 40
112+
sourceCharIndex = -1
113+
sourceLength = 0
114114
type = FRAME_LOCAL
115115
]
116116
receiver =

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_splat_operator_and_preceding_and_following_elements.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ ast: |
123123
attributes:
124124
flags = 0
125125
frameSlot = 2 # %case_0
126-
sourceCharIndex = 0
127-
sourceLength = 54
126+
sourceCharIndex = -1
127+
sourceLength = 0
128128
type = FRAME_LOCAL
129129
]
130130
receiver =

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_splat_operator_and_preceding_element.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ ast: |
9494
attributes:
9595
flags = 0
9696
frameSlot = 2 # %case_0
97-
sourceCharIndex = 0
98-
sourceLength = 32
97+
sourceCharIndex = -1
98+
sourceLength = 0
9999
type = FRAME_LOCAL
100100
]
101101
receiver =

spec/truffle/parsing/fixtures/case/with_expression_and_when/with_splat_operator_and_preceding_elements.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ ast: |
100100
attributes:
101101
flags = 0
102102
frameSlot = 2 # %case_0
103-
sourceCharIndex = 0
104-
sourceLength = 40
103+
sourceCharIndex = -1
104+
sourceLength = 0
105105
type = FRAME_LOCAL
106106
]
107107
receiver =

spec/truffle/parsing/fixtures/method_calls/primitive.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ast: |
5959
sourceLength = 0
6060
TypeNodesFactory$IsNilNodeFactory$IsNilNodeGen
6161
attributes:
62-
flags = 0
62+
flags = 1
6363
sourceCharIndex = 32
6464
sourceLength = 18
6565
children:

spec/truffle/parsing/fixtures/operators/match/=~_with_regexp_without_interpolation_with_named_capture_groups_as_receiver.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ ast: |
109109
attributes:
110110
flags = 0
111111
frameSlot = 3 # %match_data_0
112-
sourceCharIndex = 0
113-
sourceLength = 24
112+
sourceCharIndex = -1
113+
sourceLength = 0
114114
type = FRAME_LOCAL
115115
]

src/main/java/org/truffleruby/builtins/PrimitiveNodeConstructor.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99
*/
1010
package org.truffleruby.builtins;
1111

12-
import org.truffleruby.RubyLanguage;
1312
import org.truffleruby.annotations.Primitive;
1413
import org.truffleruby.core.array.ArrayUtils;
1514
import org.truffleruby.core.numeric.FixnumLowerNodeGen.FixnumLowerASTNodeGen;
1615
import org.truffleruby.core.support.TypeNodes;
1716
import org.truffleruby.language.RubyBaseNode;
1817
import org.truffleruby.language.RubyNode;
19-
import org.truffleruby.language.SourceIndexLength;
2018

2119
import com.oracle.truffle.api.dsl.NodeFactory;
22-
import com.oracle.truffle.api.source.Source;
2320

2421
public final class PrimitiveNodeConstructor {
2522

@@ -39,13 +36,7 @@ public NodeFactory<? extends RubyBaseNode> getFactory() {
3936
return factory;
4037
}
4138

42-
public RubyNode createInvokePrimitiveNode(Source source, SourceIndexLength sourceSection, RubyNode[] arguments) {
43-
if (arguments.length != getPrimitiveArity()) {
44-
throw new Error(
45-
"Incorrect number of arguments (expected " + getPrimitiveArity() + ") at " +
46-
RubyLanguage.getCurrentContext().fileLine(sourceSection.toSourceSection(source)));
47-
}
48-
39+
public RubyNode createInvokePrimitiveNode(RubyNode[] arguments) {
4940
for (int n = 0; n < arguments.length; n++) {
5041
if (ArrayUtils.contains(annotation.lowerFixnum(), n)) {
5142
arguments[n] = FixnumLowerASTNodeGen.create(arguments[n]);
@@ -58,9 +49,7 @@ public RubyNode createInvokePrimitiveNode(Source source, SourceIndexLength sourc
5849
}
5950
}
6051

61-
final RubyNode primitiveNode = (RubyNode) CoreMethodNodeManager.createNodeFromFactory(factory, arguments);
62-
primitiveNode.unsafeSetSourceSection(sourceSection);
63-
return primitiveNode;
52+
return (RubyNode) CoreMethodNodeManager.createNodeFromFactory(factory, arguments);
6453
}
6554

6655
}

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

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public abstract class RubyNode extends RubyBaseNodeWithExecute implements Instru
5757
private static final byte FLAG_ROOT = 3; // 1<<3 = 8
5858

5959
protected static final int NO_SOURCE = -1;
60+
private static final int UNAVAILABLE_SOURCE_SECTION_LENGTH = -1;
6061

6162
// Used when the return value of a node is ignored syntactically.
6263
// Returns Nil instead of void to force RubyNodeWrapper to call `delegateNode.executeVoid(frame)`, otherwise
@@ -85,21 +86,13 @@ public boolean hasSource() {
8586
return isAdoptable() && getSourceCharIndex() != NO_SOURCE;
8687
}
8788

88-
public void unsafeSetSourceSection(SourceIndexLength sourceIndexLength) {
89-
assert !hasSource();
90-
91-
if (sourceIndexLength != null) {
92-
unsafeSetSourceSection(sourceIndexLength.getCharIndex(), sourceIndexLength.getLength());
93-
}
94-
}
95-
9689
public void unsafeSetSourceSection(SourceSection sourceSection) {
9790
assert !hasSource();
9891

9992
if (sourceSection.isAvailable()) {
10093
unsafeSetSourceSection(sourceSection.getCharIndex(), sourceSection.getCharLength());
10194
} else {
102-
unsafeSetSourceSection(0, SourceIndexLength.UNAVAILABLE);
95+
unsafeSetSourceSection(0, UNAVAILABLE_SOURCE_SECTION_LENGTH);
10396
}
10497
}
10598

@@ -121,14 +114,6 @@ public RubyNode copySourceSection(RubyNode from) {
121114
return this;
122115
}
123116

124-
public SourceIndexLength getSourceIndexLength() {
125-
if (!hasSource()) {
126-
return null;
127-
} else {
128-
return new SourceIndexLength(getSourceCharIndex(), getSourceLength());
129-
}
130-
}
131-
132117
@Override
133118
@TruffleBoundary
134119
public SourceSection getSourceSection() {
@@ -141,7 +126,7 @@ public SourceSection getSourceSection() {
141126
}
142127

143128
int sourceLength = getSourceLength();
144-
if (sourceLength == SourceIndexLength.UNAVAILABLE) {
129+
if (sourceLength == UNAVAILABLE_SOURCE_SECTION_LENGTH) {
145130
return source.createUnavailableSection();
146131
} else {
147132
return source.createSection(getSourceCharIndex(), sourceLength);
@@ -166,23 +151,6 @@ private Source getSource() {
166151
return sourceSection.getSource();
167152
}
168153

169-
public SourceIndexLength getEncapsulatingSourceIndexLength() {
170-
Node node = this;
171-
while (node != null) {
172-
if (node instanceof RubyNode && ((RubyNode) node).hasSource()) {
173-
return ((RubyNode) node).getSourceIndexLength();
174-
}
175-
176-
if (node instanceof RootNode) {
177-
return SourceIndexLength.fromSourceSection(node.getSourceSection());
178-
}
179-
180-
node = node.getParent();
181-
}
182-
183-
return null;
184-
}
185-
186154
@Override
187155
public String toString() {
188156
return super.toString() + " at " + RubyLanguage.fileLineRange(getSourceSection());

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

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/main/java/org/truffleruby/language/objects/DefineClassNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.oracle.truffle.api.profiles.BranchProfile;
2323
import com.oracle.truffle.api.profiles.ConditionProfile;
2424

25+
/** Defines a new class or returns an existing one found by name in a parent lexical scope. */
2526
public final class DefineClassNode extends RubyContextSourceNode {
2627

2728
private final String name;

src/main/java/org/truffleruby/language/objects/DefineModuleNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.oracle.truffle.api.profiles.BranchProfile;
2424
import com.oracle.truffle.api.profiles.ConditionProfile;
2525

26+
/** Defines a new module or returns an existing one found by name in a parent lexical scope. */
2627
@NodeChild(value = "lexicalParentModuleNode", type = RubyNode.class)
2728
public abstract class DefineModuleNode extends RubyContextSourceNode {
2829

src/main/java/org/truffleruby/language/objects/RunModuleDefinitionNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.oracle.truffle.api.frame.VirtualFrame;
2222
import com.oracle.truffle.api.nodes.IndirectCallNode;
2323

24+
/** Defines a new class or module (or gets an existing one) and executes its body. */
2425
public final class RunModuleDefinitionNode extends RubyContextSourceNode {
2526

2627
@Child private RubyNode definingModule;

src/main/java/org/truffleruby/language/objects/SingletonClassNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.oracle.truffle.api.dsl.NodeChild;
2828
import com.oracle.truffle.api.dsl.Specialization;
2929

30+
/** Get a Ruby object's singleton class */
3031
// Specializations are order by their frequency on railsbench using --engine.SpecializationStatistics
3132
@GenerateUncached
3233
public abstract class SingletonClassNode extends RubyBaseNode {

0 commit comments

Comments
 (0)