Skip to content

Commit 63418c6

Browse files
committed
[GR-45042] MetaClassNode and ForeignClassNode supports DSL inlining
PullRequest: truffleruby/3829
2 parents 2de206d + 2bd75dc commit 63418c6

17 files changed

+83
-83
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,14 +1220,14 @@ protected boolean isClassVariableId(RubySymbol symbol) {
12201220
public abstract static class CallSuperNode extends CoreMethodArrayArgumentsNode {
12211221

12221222
@Child private CallSuperMethodNode callSuperMethodNode = CallSuperMethodNode.create();
1223-
@Child private MetaClassNode metaClassNode = MetaClassNode.create();
12241223

12251224
@Specialization
1226-
protected Object callSuper(VirtualFrame frame, Object[] args) {
1225+
protected Object callSuper(VirtualFrame frame, Object[] args,
1226+
@Cached MetaClassNode metaClassNode) {
12271227
final Frame callingMethodFrame = findCallingMethodFrame();
12281228
final InternalMethod callingMethod = RubyArguments.getMethod(callingMethodFrame);
12291229
final Object callingSelf = RubyArguments.getSelf(callingMethodFrame);
1230-
final RubyClass callingMetaclass = metaClassNode.execute(callingSelf);
1230+
final RubyClass callingMetaclass = metaClassNode.execute(this, callingSelf);
12311231
final MethodLookupResult superMethodLookup = ModuleOperations
12321232
.lookupSuperMethod(callingMethod, callingMetaclass);
12331233
final InternalMethod superMethod = superMethodLookup.getMethod();

src/main/java/org/truffleruby/core/VMPrimitiveNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected Object vmExtendedModules(Object object, RubyProc block,
147147
@Cached MetaClassNode metaClassNode,
148148
@Cached CallBlockNode yieldNode,
149149
@Cached InlinedConditionProfile isSingletonProfile) {
150-
final RubyClass metaClass = metaClassNode.execute(object);
150+
final RubyClass metaClass = metaClassNode.execute(this, object);
151151

152152
if (isSingletonProfile.profile(this, metaClass.isSingleton)) {
153153
for (RubyModule included : metaClass.fields.prependedAndIncludedModules()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ private Visibility lastCallWasCallingPrivateOrProtectedMethod(Object self, Strin
624624
FrameAndCallNode callerFrame) {
625625
final DeclarationContext declarationContext = RubyArguments.tryGetDeclarationContext(callerFrame.frame);
626626
final InternalMethod method = ModuleOperations
627-
.lookupMethodUncached(MetaClassNode.getUncached().execute(self), name, declarationContext);
627+
.lookupMethodUncached(MetaClassNode.executeUncached(self), name, declarationContext);
628628
if (method != null && !method.isUndefined()) {
629629
assert method.getVisibility() == Visibility.PRIVATE || method.getVisibility() == Visibility.PROTECTED;
630630
return method.getVisibility();

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ protected RubyDynamicObject copyable(Object object, Object freeze,
569569
final RubyDynamicObject newObject = copyNode.executeCopy(object);
570570

571571
// Copy the singleton class if any.
572-
final RubyClass selfMetaClass = metaClassNode.execute(object);
572+
final RubyClass selfMetaClass = metaClassNode.execute(this, object);
573573
if (isSingletonProfile.profile(this, selfMetaClass.isSingleton)) {
574574
final RubyClass newObjectMetaClass = executeSingletonClass(newObject);
575575
newObjectMetaClass.fields.initCopy(selfMetaClass);
@@ -1261,7 +1261,7 @@ protected RubyBaseNodeWithExecute coerceToBoolean(RubyBaseNodeWithExecute regula
12611261
@Specialization(guards = "regular")
12621262
protected RubyArray methodsRegular(Object self, boolean regular,
12631263
@Cached MetaClassNode metaClassNode) {
1264-
final RubyModule metaClass = metaClassNode.execute(self);
1264+
final RubyModule metaClass = metaClassNode.execute(this, self);
12651265

12661266
Object[] objects = metaClass.fields
12671267
.filterMethodsOnObject(getLanguage(), regular, MethodFilter.PUBLIC_PROTECTED)
@@ -1311,17 +1311,16 @@ private void print(Object inspected) {
13111311
@NodeChild(value = "includeAncestors", type = RubyBaseNodeWithExecute.class)
13121312
public abstract static class PrivateMethodsNode extends CoreMethodNode {
13131313

1314-
@Child private MetaClassNode metaClassNode = MetaClassNode.create();
1315-
13161314
@CreateCast("includeAncestors")
13171315
protected RubyBaseNodeWithExecute coerceToBoolean(RubyBaseNodeWithExecute includeAncestors) {
13181316
return BooleanCastWithDefaultNode.create(true, includeAncestors);
13191317
}
13201318

13211319
@TruffleBoundary
13221320
@Specialization
1323-
protected RubyArray privateMethods(Object self, boolean includeAncestors) {
1324-
RubyClass metaClass = metaClassNode.execute(self);
1321+
protected RubyArray privateMethods(Object self, boolean includeAncestors,
1322+
@Cached MetaClassNode metaClassNode) {
1323+
RubyClass metaClass = metaClassNode.execute(this, self);
13251324

13261325
Object[] objects = metaClass.fields
13271326
.filterMethodsOnObject(getLanguage(), includeAncestors, MethodFilter.PRIVATE)
@@ -1347,17 +1346,16 @@ protected RubyProc proc(VirtualFrame frame, Object maybeBlock,
13471346
@NodeChild(value = "includeAncestors", type = RubyBaseNodeWithExecute.class)
13481347
public abstract static class ProtectedMethodsNode extends CoreMethodNode {
13491348

1350-
@Child private MetaClassNode metaClassNode = MetaClassNode.create();
1351-
13521349
@CreateCast("includeAncestors")
13531350
protected RubyBaseNodeWithExecute coerceToBoolean(RubyBaseNodeWithExecute includeAncestors) {
13541351
return BooleanCastWithDefaultNode.create(true, includeAncestors);
13551352
}
13561353

13571354
@TruffleBoundary
13581355
@Specialization
1359-
protected RubyArray protectedMethods(Object self, boolean includeAncestors) {
1360-
final RubyClass metaClass = metaClassNode.execute(self);
1356+
protected RubyArray protectedMethods(Object self, boolean includeAncestors,
1357+
@Cached MetaClassNode metaClassNode) {
1358+
final RubyClass metaClass = metaClassNode.execute(this, self);
13611359

13621360
Object[] objects = metaClass.fields
13631361
.filterMethodsOnObject(getLanguage(), includeAncestors, MethodFilter.PROTECTED)
@@ -1387,17 +1385,16 @@ protected RubyMethod method(Frame callerFrame, Object self, Object[] rubyArgs, R
13871385
@NodeChild(value = "includeAncestors", type = RubyBaseNodeWithExecute.class)
13881386
public abstract static class PublicMethodsNode extends CoreMethodNode {
13891387

1390-
@Child private MetaClassNode metaClassNode = MetaClassNode.create();
1391-
13921388
@CreateCast("includeAncestors")
13931389
protected RubyBaseNodeWithExecute coerceToBoolean(RubyBaseNodeWithExecute includeAncestors) {
13941390
return BooleanCastWithDefaultNode.create(true, includeAncestors);
13951391
}
13961392

13971393
@TruffleBoundary
13981394
@Specialization
1399-
protected RubyArray publicMethods(Object self, boolean includeAncestors) {
1400-
final RubyModule metaClass = metaClassNode.execute(self);
1395+
protected RubyArray publicMethods(Object self, boolean includeAncestors,
1396+
@Cached MetaClassNode metaClassNode) {
1397+
final RubyModule metaClass = metaClassNode.execute(this, self);
14011398

14021399
Object[] objects = metaClass.fields
14031400
.filterMethodsOnObject(getLanguage(), includeAncestors, MethodFilter.PUBLIC)
@@ -1524,7 +1521,6 @@ protected RubyClass singletonClass(Object self) {
15241521
@NodeChild(value = "name", type = RubyBaseNodeWithExecute.class)
15251522
public abstract static class SingletonMethodNode extends CoreMethodNode {
15261523

1527-
@Child private MetaClassNode metaClassNode = MetaClassNode.create();
15281524

15291525
@CreateCast("name")
15301526
protected RubyBaseNodeWithExecute coerceToString(RubyBaseNodeWithExecute name) {
@@ -1535,8 +1531,9 @@ protected RubyBaseNodeWithExecute coerceToString(RubyBaseNodeWithExecute name) {
15351531
protected RubyMethod singletonMethod(Object self, String name,
15361532
@Cached InlinedBranchProfile errorProfile,
15371533
@Cached InlinedConditionProfile singletonProfile,
1538-
@Cached InlinedConditionProfile methodProfile) {
1539-
final RubyClass metaClass = metaClassNode.execute(self);
1534+
@Cached InlinedConditionProfile methodProfile,
1535+
@Cached MetaClassNode metaClassNode) {
1536+
final RubyClass metaClass = metaClassNode.execute(this, self);
15401537

15411538
if (singletonProfile.profile(this, metaClass.isSingleton)) {
15421539
final InternalMethod method = metaClass.fields.getMethod(name);
@@ -1580,7 +1577,7 @@ protected RubyBaseNodeWithExecute coerceToBoolean(RubyBaseNodeWithExecute includ
15801577
@Specialization
15811578
protected RubyArray singletonMethods(Object self, boolean includeAncestors,
15821579
@Cached MetaClassNode metaClassNode) {
1583-
final RubyClass metaClass = metaClassNode.execute(self);
1580+
final RubyClass metaClass = metaClassNode.execute(this, self);
15841581

15851582
if (!metaClass.isSingleton) {
15861583
return createEmptyArray();
@@ -1601,7 +1598,7 @@ public abstract static class HasSingletonMethodsNode extends PrimitiveArrayArgum
16011598
@Specialization
16021599
protected boolean hasSingletonMethods(Object self,
16031600
@Cached MetaClassNode metaClassNode) {
1604-
final RubyClass metaClass = metaClassNode.execute(self);
1601+
final RubyClass metaClass = metaClassNode.execute(this, self);
16051602

16061603
if (!metaClass.isSingleton) {
16071604
return false;

src/main/java/org/truffleruby/core/method/MethodNodes.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,12 @@ protected Object sourceLocation(RubyMethod method,
242242
@CoreMethod(names = "super_method")
243243
public abstract static class SuperMethodNode extends CoreMethodArrayArgumentsNode {
244244

245-
@Child private MetaClassNode metaClassNode = MetaClassNode.create();
246-
247245
@Specialization
248-
protected Object superMethod(RubyMethod method) {
246+
protected Object superMethod(RubyMethod method,
247+
@Cached MetaClassNode metaClassNode) {
249248
Object receiver = method.receiver;
250249
InternalMethod internalMethod = method.method;
251-
RubyClass selfMetaClass = metaClassNode.execute(receiver);
250+
RubyClass selfMetaClass = metaClassNode.execute(this, receiver);
252251
MethodLookupResult superMethod = ModuleOperations.lookupSuperMethod(internalMethod, selfMetaClass);
253252
if (!superMethod.isDefined()) {
254253
return nil;
@@ -268,11 +267,10 @@ protected Object superMethod(RubyMethod method) {
268267
@CoreMethod(names = "unbind")
269268
public abstract static class UnbindNode extends CoreMethodArrayArgumentsNode {
270269

271-
@Child private MetaClassNode metaClassNode = MetaClassNode.create();
272-
273270
@Specialization
274-
protected RubyUnboundMethod unbind(RubyMethod method) {
275-
final RubyClass receiverClass = metaClassNode.execute(method.receiver);
271+
protected RubyUnboundMethod unbind(RubyMethod method,
272+
@Cached MetaClassNode metaClassNode) {
273+
final RubyClass receiverClass = metaClassNode.execute(this, method.receiver);
276274
final RubyUnboundMethod instance = new RubyUnboundMethod(
277275
coreLibrary().unboundMethodClass,
278276
getLanguage().unboundMethodShape,

src/main/java/org/truffleruby/core/method/UnboundMethodNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected RubyMethod bind(RubyUnboundMethod unboundMethod, Object object,
8181
@Cached MetaClassNode metaClassNode,
8282
@Cached CanBindMethodToModuleNode canBindMethodToModuleNode,
8383
@Cached InlinedBranchProfile errorProfile) {
84-
final RubyClass objectMetaClass = metaClassNode.execute(object);
84+
final RubyClass objectMetaClass = metaClassNode.execute(this, object);
8585

8686
if (!canBindMethodToModuleNode
8787
.executeCanBindMethodToModule(unboundMethod.method, objectMetaClass)) {

src/main/java/org/truffleruby/core/support/TypeNodes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public abstract static class MetaClassPrimitiveNode extends PrimitiveArrayArgume
9999
@Specialization
100100
protected RubyClass metaClass(Object object,
101101
@Cached MetaClassNode metaClassNode) {
102-
return metaClassNode.execute(object);
102+
return metaClassNode.execute(this, object);
103103
}
104104
}
105105

@@ -128,7 +128,7 @@ protected Object freeze(Object self,
128128
protected Object freezeNormalObject(RubyDynamicObject self,
129129
@Cached @Shared FreezeNode freezeNode,
130130
@Cached @Shared MetaClassNode metaClassNode,
131-
@Bind("metaClassNode.execute(self)") RubyClass metaClass) {
131+
@Bind("metaClassNode.execute(this, self)") RubyClass metaClass) {
132132
freezeNode.execute(self);
133133
return self;
134134
}
@@ -140,7 +140,7 @@ protected Object freezeSingletonObject(RubyDynamicObject self,
140140
@Cached IsFrozenNode isFrozenMetaClassNode,
141141
@Cached InlinedConditionProfile singletonClassUnfrozenProfile,
142142
@Cached @Shared MetaClassNode metaClassNode,
143-
@Bind("metaClassNode.execute(self)") RubyClass metaClass) {
143+
@Bind("metaClassNode.execute(this, self)") RubyClass metaClass) {
144144
if (singletonClassUnfrozenProfile.profile(this,
145145
!RubyGuards.isSingletonClass(self) && !isFrozenMetaClassNode.execute(metaClass))) {
146146
freezeMetaClasNode.execute(metaClass);

src/main/java/org/truffleruby/language/dispatch/DispatchNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ protected final Object dispatchInternal(Frame frame, Object receiver, String met
297297
CallInternalMethodNode callNode) {
298298
assert RubyArguments.getSelf(rubyArgs) == receiver;
299299

300-
final RubyClass metaclass = metaClassNode.execute(receiver);
300+
final RubyClass metaclass = metaClassNode.executeCached(receiver);
301301
final InternalMethod method = lookupMethodNode.execute(frame, metaclass, methodName, config);
302302

303303
if (methodMissingProfile.profile(method == null || method.isUndefined())) {

src/main/java/org/truffleruby/language/dispatch/InternalRespondToNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected static boolean executeInternal(Frame frame, Object receiver, String me
7979
DispatchConfiguration config,
8080
MetaClassNode metaclassNode,
8181
LookupMethodNode methodLookup) {
82-
final RubyClass metaclass = metaclassNode.execute(receiver);
82+
final RubyClass metaclass = metaclassNode.executeCached(receiver);
8383
final InternalMethod method = methodLookup.execute(frame, metaclass, methodName, config);
8484
return method != null && method.isDefined() && method.isImplemented();
8585
}

src/main/java/org/truffleruby/language/methods/GetMethodObjectNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private InternalMethod createMissingMethod(Object self, RubySymbol name, String
106106
ReturnID.INVALID);
107107
final RootCallTarget newCallTarget = newRootNode.getCallTarget();
108108

109-
final RubyClass module = MetaClassNode.getUncached().execute(self);
109+
final RubyClass module = MetaClassNode.executeUncached(self);
110110
return new InternalMethod(
111111
getContext(),
112112
info,

0 commit comments

Comments
 (0)