Skip to content

Commit fb40eff

Browse files
author
Nicolas Laurent
committed
[GR-27063] Remove AllocateHelperNode.
PullRequest: truffleruby/2193
2 parents c0aad2b + 91c589f commit fb40eff

32 files changed

+125
-398
lines changed

src/main/java/org/truffleruby/core/array/ArrayIndexNodes.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.truffleruby.core.klass.RubyClass;
1717
import org.truffleruby.language.RubyContextSourceNode;
1818
import org.truffleruby.language.RubyNode;
19-
import org.truffleruby.language.objects.AllocateHelperNode;
2019

2120
import com.oracle.truffle.api.dsl.Cached;
2221
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -96,8 +95,6 @@ protected static boolean isInBounds(RubyArray array, int index) {
9695
@ImportStatic(ArrayGuards.class)
9796
public abstract static class ReadSliceNormalizedNode extends PrimitiveArrayArgumentsNode {
9897

99-
@Child private AllocateHelperNode helperNode = AllocateHelperNode.create();
100-
10198
public static ReadSliceNormalizedNode create() {
10299
return ArrayIndexNodesFactory.ReadSliceNormalizedNodeFactory.create(null);
103100
}
@@ -134,7 +131,7 @@ protected RubyArray createArrayOfSameClass(RubyArray array, Object store, int si
134131
final RubyClass logicalClass = array.getLogicalClass();
135132
RubyArray newArray = new RubyArray(
136133
logicalClass,
137-
helperNode.getCachedShape(logicalClass),
134+
getLanguage().arrayShape,
138135
store,
139136
size);
140137
AllocationTracing.trace(newArray, this);

src/main/java/org/truffleruby/core/array/ArrayNodes.java

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

1616
import java.util.Arrays;
1717

18+
import com.oracle.truffle.api.object.Shape;
1819
import com.oracle.truffle.api.profiles.LoopConditionProfile;
1920
import org.graalvm.collections.EconomicSet;
2021
import org.graalvm.collections.Equivalence;
@@ -78,7 +79,6 @@
7879
import org.truffleruby.language.dispatch.DispatchNode;
7980
import org.truffleruby.language.library.RubyStringLibrary;
8081
import org.truffleruby.language.methods.Split;
81-
import org.truffleruby.language.objects.AllocateHelperNode;
8282
import org.truffleruby.language.objects.AllocationTracing;
8383
import org.truffleruby.language.objects.WriteObjectFieldNode;
8484
import org.truffleruby.language.objects.shared.PropagateSharingNode;
@@ -110,19 +110,13 @@ public abstract class ArrayNodes {
110110
@CoreMethod(names = { "__allocate__", "__layout_allocate__" }, constructor = true, visibility = Visibility.PRIVATE)
111111
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
112112

113-
@Child private AllocateHelperNode helperNode = AllocateHelperNode.create();
114-
115113
@Specialization
116114
protected RubyArray allocate(RubyClass rubyClass) {
117-
RubyArray array = new RubyArray(
118-
rubyClass,
119-
helperNode.getCachedShape(rubyClass),
120-
ArrayStoreLibrary.INITIAL_STORE,
121-
0);
115+
final Shape shape = getLanguage().arrayShape;
116+
final RubyArray array = new RubyArray(rubyClass, shape, ArrayStoreLibrary.INITIAL_STORE, 0);
122117
AllocationTracing.trace(array, this);
123118
return array;
124119
}
125-
126120
}
127121

128122
@CoreMethod(names = "+", required = 1)
@@ -158,14 +152,12 @@ protected RubyArray addGeneralize(RubyArray a, RubyArray b,
158152
@ReportPolymorphism
159153
public abstract static class MulNode extends PrimitiveArrayArgumentsNode {
160154

161-
@Child private AllocateHelperNode helperNode = AllocateHelperNode.create();
162-
163155
@Specialization(guards = "count == 0")
164156
protected RubyArray mulZero(RubyArray array, int count) {
165157
final RubyClass logicalClass = array.getLogicalClass();
166158
return new RubyArray(
167159
logicalClass,
168-
helperNode.getCachedShape(logicalClass),
160+
getLanguage().arrayShape,
169161
ArrayStoreLibrary.INITIAL_STORE,
170162
0);
171163
}
@@ -194,7 +186,7 @@ protected RubyArray mulOther(RubyArray array, int count,
194186
final RubyClass logicalClass = array.getLogicalClass();
195187
return new RubyArray(
196188
logicalClass,
197-
helperNode.getCachedShape(logicalClass),
189+
getLanguage().arrayShape,
198190
newStore,
199191
newSize);
200192
}
@@ -214,7 +206,7 @@ protected RubyArray mulEmpty(RubyArray array, long count) {
214206
final RubyClass logicalClass = array.getLogicalClass();
215207
return new RubyArray(
216208
logicalClass,
217-
helperNode.getCachedShape(logicalClass),
209+
getLanguage().arrayShape,
218210
ArrayStoreLibrary.INITIAL_STORE,
219211
0);
220212
}

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.core.basicobject;
1111

1212
import com.oracle.truffle.api.dsl.CachedLanguage;
13+
import com.oracle.truffle.api.object.Shape;
1314
import org.truffleruby.Layouts;
1415
import org.truffleruby.RubyContext;
1516
import org.truffleruby.RubyLanguage;
@@ -56,7 +57,6 @@
5657
import org.truffleruby.language.methods.InternalMethod;
5758
import org.truffleruby.language.methods.LookupMethodNode;
5859
import org.truffleruby.language.methods.UnsupportedOperationBehavior;
59-
import org.truffleruby.language.objects.AllocateHelperNode;
6060
import org.truffleruby.language.objects.AllocationTracing;
6161
import org.truffleruby.language.objects.MetaClassNode;
6262
import org.truffleruby.language.objects.ObjectIDOperations;
@@ -82,7 +82,6 @@
8282
import com.oracle.truffle.api.nodes.Node;
8383
import com.oracle.truffle.api.nodes.NodeUtil;
8484
import com.oracle.truffle.api.object.DynamicObjectLibrary;
85-
import com.oracle.truffle.api.object.Shape;
8685
import com.oracle.truffle.api.profiles.ConditionProfile;
8786

8887

@@ -654,15 +653,20 @@ public static AllocateNode create() {
654653

655654
public abstract Object execute(VirtualFrame frame, Object rubyClass);
656655

657-
@Specialization
658-
protected RubyBasicObject allocate(RubyClass rubyClass,
659-
@Cached AllocateHelperNode allocateHelperNode) {
660-
final Shape shape = allocateHelperNode.getCachedShape(rubyClass);
661-
final RubyBasicObject instance = new RubyBasicObject(rubyClass, shape);
656+
@Specialization(guards = "!rubyClass.isSingleton")
657+
protected RubyBasicObject allocate(RubyClass rubyClass) {
658+
final RubyBasicObject instance = new RubyBasicObject(rubyClass, getLanguage().basicObjectShape);
662659
AllocationTracing.trace(instance, this);
663660
return instance;
664661
}
665662

663+
@Specialization(guards = "rubyClass.isSingleton")
664+
protected Shape allocateSingleton(RubyClass rubyClass) {
665+
throw new RaiseException(
666+
getContext(),
667+
getContext().getCoreExceptions().typeErrorCantCreateInstanceOfSingletonClass(this));
668+
}
669+
666670
@Override
667671
public Object inlineExecute(VirtualFrame frame, Object self, Object[] args, Object proc) {
668672
return execute(frame, proc);
@@ -673,5 +677,4 @@ public InternalMethod getMethod() {
673677
return getContext().getCoreMethods().BASIC_OBJECT_ALLOCATE;
674678
}
675679
}
676-
677680
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Set;
1818

1919
import com.oracle.truffle.api.library.CachedLibrary;
20+
import com.oracle.truffle.api.object.Shape;
2021
import org.jcodings.Encoding;
2122
import org.jcodings.Ptr;
2223
import org.jcodings.specific.ASCIIEncoding;
@@ -54,14 +55,12 @@
5455
import org.truffleruby.language.Visibility;
5556
import org.truffleruby.language.control.RaiseException;
5657
import org.truffleruby.language.library.RubyStringLibrary;
57-
import org.truffleruby.language.objects.AllocateHelperNode;
5858

5959
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6060
import com.oracle.truffle.api.dsl.Cached;
6161
import com.oracle.truffle.api.dsl.CreateCast;
6262
import com.oracle.truffle.api.dsl.NodeChild;
6363
import com.oracle.truffle.api.dsl.Specialization;
64-
import com.oracle.truffle.api.object.Shape;
6564
import com.oracle.truffle.api.profiles.BranchProfile;
6665
import org.truffleruby.language.objects.AllocationTracing;
6766

@@ -155,14 +154,12 @@ private int toJCodingFlags(int flags) {
155154
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
156155

157156
@Specialization
158-
protected RubyEncodingConverter allocate(RubyClass rubyClass,
159-
@Cached AllocateHelperNode allocateHelperNode) {
160-
final Shape shape = allocateHelperNode.getCachedShape(rubyClass);
157+
protected RubyEncodingConverter allocate(RubyClass rubyClass) {
158+
final Shape shape = getLanguage().encodingConverterShape;
161159
final RubyEncodingConverter instance = new RubyEncodingConverter(rubyClass, shape, null);
162160
AllocationTracing.trace(instance, this);
163161
return instance;
164162
}
165-
166163
}
167164

168165
@Primitive(name = "encoding_transcoders_from_encoding")

src/main/java/org/truffleruby/core/exception/ExceptionNodes.java

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

12+
import com.oracle.truffle.api.object.Shape;
1213
import org.truffleruby.SuppressFBWarnings;
1314
import org.truffleruby.builtins.CoreMethod;
1415
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
@@ -24,13 +25,11 @@
2425
import org.truffleruby.language.backtrace.Backtrace;
2526
import org.truffleruby.language.backtrace.BacktraceFormatter;
2627
import org.truffleruby.language.methods.LookupMethodOnSelfNode;
27-
import org.truffleruby.language.objects.AllocateHelperNode;
2828

2929
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3030
import com.oracle.truffle.api.dsl.Cached;
3131
import com.oracle.truffle.api.dsl.Specialization;
3232
import com.oracle.truffle.api.frame.VirtualFrame;
33-
import com.oracle.truffle.api.object.Shape;
3433
import com.oracle.truffle.api.profiles.ConditionProfile;
3534
import org.truffleruby.language.objects.AllocationTracing;
3635

@@ -40,16 +39,13 @@ public abstract class ExceptionNodes {
4039
@CoreMethod(names = { "__allocate__", "__layout_allocate__" }, constructor = true, visibility = Visibility.PRIVATE)
4140
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
4241

43-
@Child private AllocateHelperNode allocateNode = AllocateHelperNode.create();
44-
4542
@Specialization
4643
protected RubyException allocateException(RubyClass rubyClass) {
47-
final Shape shape = allocateNode.getCachedShape(rubyClass);
44+
final Shape shape = getLanguage().exceptionShape;
4845
final RubyException instance = new RubyException(rubyClass, shape, nil, null, nil);
4946
AllocationTracing.trace(instance, this);
5047
return instance;
5148
}
52-
5349
}
5450

5551
@CoreMethod(names = "initialize", optional = 1)

src/main/java/org/truffleruby/core/exception/FrozenErrorNodes.java

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

1212
import com.oracle.truffle.api.dsl.Cached;
13+
import com.oracle.truffle.api.object.Shape;
1314
import com.oracle.truffle.api.profiles.BranchProfile;
1415
import org.truffleruby.builtins.CoreMethod;
1516
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
@@ -19,23 +20,19 @@
1920
import org.truffleruby.core.klass.RubyClass;
2021
import org.truffleruby.language.Visibility;
2122
import org.truffleruby.language.control.RaiseException;
22-
import org.truffleruby.language.objects.AllocateHelperNode;
2323
import org.truffleruby.language.objects.AllocationTracing;
2424

2525
import com.oracle.truffle.api.dsl.Specialization;
26-
import com.oracle.truffle.api.object.Shape;
2726

2827
@CoreModule(value = "FrozenError", isClass = true)
2928
public abstract class FrozenErrorNodes {
3029

3130
@CoreMethod(names = { "__allocate__", "__layout_allocate__" }, constructor = true, visibility = Visibility.PRIVATE)
3231
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
3332

34-
@Child private AllocateHelperNode allocateNode = AllocateHelperNode.create();
35-
3633
@Specialization
3734
protected RubyFrozenError allocateFrozenError(RubyClass rubyClass) {
38-
final Shape shape = allocateNode.getCachedShape(rubyClass);
35+
final Shape shape = getLanguage().frozenErrorShape;
3936
final RubyFrozenError instance = new RubyFrozenError(rubyClass, shape, nil, null, nil, null);
4037
AllocationTracing.trace(instance, this);
4138
return instance;

src/main/java/org/truffleruby/core/exception/NameErrorNodes.java

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

12+
import com.oracle.truffle.api.object.Shape;
1213
import org.truffleruby.builtins.CoreMethod;
1314
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1415
import org.truffleruby.builtins.CoreModule;
@@ -17,10 +18,8 @@
1718
import org.truffleruby.core.klass.RubyClass;
1819
import org.truffleruby.language.Visibility;
1920
import org.truffleruby.language.control.RaiseException;
20-
import org.truffleruby.language.objects.AllocateHelperNode;
2121

2222
import com.oracle.truffle.api.dsl.Specialization;
23-
import com.oracle.truffle.api.object.Shape;
2423
import org.truffleruby.language.objects.AllocationTracing;
2524

2625
@CoreModule(value = "NameError", isClass = true)
@@ -29,11 +28,9 @@ public abstract class NameErrorNodes {
2928
@CoreMethod(names = { "__allocate__", "__layout_allocate__" }, constructor = true, visibility = Visibility.PRIVATE)
3029
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
3130

32-
@Child private AllocateHelperNode allocateNode = AllocateHelperNode.create();
33-
3431
@Specialization
3532
protected RubyNameError allocateNameError(RubyClass rubyClass) {
36-
final Shape shape = allocateNode.getCachedShape(rubyClass);
33+
final Shape shape = getLanguage().nameErrorShape;
3734
final RubyNameError instance = new RubyNameError(rubyClass, shape, nil, null, nil, null, nil);
3835
AllocationTracing.trace(instance, this);
3936
return instance;

src/main/java/org/truffleruby/core/exception/NoMethodErrorNodes.java

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

12+
import com.oracle.truffle.api.object.Shape;
1213
import org.truffleruby.builtins.CoreMethod;
1314
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1415
import org.truffleruby.builtins.CoreModule;
@@ -18,10 +19,8 @@
1819
import org.truffleruby.core.klass.RubyClass;
1920
import org.truffleruby.language.Nil;
2021
import org.truffleruby.language.Visibility;
21-
import org.truffleruby.language.objects.AllocateHelperNode;
2222

2323
import com.oracle.truffle.api.dsl.Specialization;
24-
import com.oracle.truffle.api.object.Shape;
2524
import org.truffleruby.language.objects.AllocationTracing;
2625

2726
@CoreModule(value = "NoMethodError", isClass = true)
@@ -30,11 +29,9 @@ public abstract class NoMethodErrorNodes {
3029
@CoreMethod(names = { "__allocate__", "__layout_allocate__" }, constructor = true, visibility = Visibility.PRIVATE)
3130
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
3231

33-
@Child private AllocateHelperNode allocateNode = AllocateHelperNode.create();
34-
3532
@Specialization
3633
protected RubyNoMethodError allocateNoMethodError(RubyClass rubyClass) {
37-
final Shape shape = allocateNode.getCachedShape(rubyClass);
34+
final Shape shape = getLanguage().noMethodErrorShape;
3835
final RubyNoMethodError instance = new RubyNoMethodError(rubyClass, shape, nil, null, nil, null, nil, nil);
3936
AllocationTracing.trace(instance, this);
4037
return instance;

src/main/java/org/truffleruby/core/exception/SyntaxErrorNodes.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.truffleruby.builtins.CoreModule;
1515
import org.truffleruby.core.klass.RubyClass;
1616
import org.truffleruby.language.Visibility;
17-
import org.truffleruby.language.objects.AllocateHelperNode;
1817
import org.truffleruby.language.objects.AllocationTracing;
1918

2019
import com.oracle.truffle.api.dsl.Specialization;
@@ -26,11 +25,9 @@ public abstract class SyntaxErrorNodes {
2625
@CoreMethod(names = { "__allocate__", "__layout_allocate__" }, constructor = true, visibility = Visibility.PRIVATE)
2726
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
2827

29-
@Child private AllocateHelperNode allocateNode = AllocateHelperNode.create();
30-
3128
@Specialization
3229
protected RubySyntaxError allocateSyntaxError(RubyClass rubyClass) {
33-
final Shape shape = allocateNode.getCachedShape(rubyClass);
30+
final Shape shape = getLanguage().syntaxErrorShape;
3431
final RubySyntaxError instance = new RubySyntaxError(rubyClass, shape, nil, null, nil, null);
3532
AllocationTracing.trace(instance, this);
3633
return instance;

src/main/java/org/truffleruby/core/exception/SystemCallErrorNodes.java

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

12+
import com.oracle.truffle.api.object.Shape;
1213
import org.truffleruby.builtins.CoreMethod;
1314
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1415
import org.truffleruby.builtins.CoreModule;
1516
import org.truffleruby.builtins.Primitive;
1617
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
1718
import org.truffleruby.core.klass.RubyClass;
1819
import org.truffleruby.language.Visibility;
19-
import org.truffleruby.language.objects.AllocateHelperNode;
2020

2121
import com.oracle.truffle.api.dsl.Specialization;
22-
import com.oracle.truffle.api.object.Shape;
2322
import org.truffleruby.language.objects.AllocationTracing;
2423

2524
@CoreModule(value = "SystemCallError", isClass = true)
@@ -28,16 +27,13 @@ public abstract class SystemCallErrorNodes {
2827
@CoreMethod(names = { "__allocate__", "__layout_allocate__" }, constructor = true, visibility = Visibility.PRIVATE)
2928
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
3029

31-
@Child private AllocateHelperNode allocateNode = AllocateHelperNode.create();
32-
3330
@Specialization
3431
protected RubySystemCallError allocateNameError(RubyClass rubyClass) {
35-
final Shape shape = allocateNode.getCachedShape(rubyClass);
32+
final Shape shape = getLanguage().systemCallErrorShape;
3633
final RubySystemCallError instance = new RubySystemCallError(rubyClass, shape, nil, null, nil, nil);
3734
AllocationTracing.trace(instance, this);
3835
return instance;
3936
}
40-
4137
}
4238

4339
@CoreMethod(names = "errno")

0 commit comments

Comments
 (0)