42
42
import com .oracle .graal .python .nodes .PRootNode ;
43
43
import com .oracle .graal .python .nodes .argument .ApplyKeywordsNode ;
44
44
import com .oracle .graal .python .nodes .argument .ArityCheckNode ;
45
+ import com .oracle .graal .python .nodes .function .ClassBodyRootNode ;
45
46
import com .oracle .graal .python .runtime .PythonOptions ;
46
47
import com .oracle .truffle .api .CallTarget ;
47
48
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
60
61
abstract class AbstractInvokeNode extends Node {
61
62
62
63
private final ConditionProfile needsFrameProfile = ConditionProfile .createBinaryProfile ();
64
+ private final ConditionProfile isClassBodyProfile = ConditionProfile .createBinaryProfile ();
63
65
64
66
protected static boolean shouldInlineGenerators () {
65
67
return PythonOptions .getOption (PythonLanguage .getContextRef ().get (), PythonOptions .ForceInlineGeneratorCalls );
@@ -101,6 +103,13 @@ protected final MaterializedFrame getCallerFrame(VirtualFrame frame, CallTarget
101
103
return null ;
102
104
}
103
105
106
+ protected final void optionallySetClassBodySpecial (Object [] arguments , CallTarget callTarget ) {
107
+ RootNode rootNode = ((RootCallTarget ) callTarget ).getRootNode ();
108
+ if (isClassBodyProfile .profile (rootNode instanceof ClassBodyRootNode )) {
109
+ PArguments .setSpecialArgument (arguments , rootNode );
110
+ }
111
+ }
112
+
104
113
@ TruffleBoundary
105
114
protected static Arity getArity (PythonCallable callee ) {
106
115
if (callee instanceof PythonBuiltinClass ) {
@@ -128,6 +137,7 @@ protected Object execute(VirtualFrame frame, PythonCallable callee, Object[] arg
128
137
RootCallTarget callTarget = getCallTarget (callee );
129
138
MaterializedFrame callerFrame = getCallerFrame (frame , callTarget );
130
139
PArguments .setCallerFrame (arguments , callerFrame );
140
+ optionallySetClassBodySpecial (arguments , callTarget );
131
141
Arity arity = getArity (callee );
132
142
if (isBuiltin (callee )) {
133
143
PArguments .setKeywordArguments (arguments , keywords );
@@ -175,6 +185,7 @@ protected Object doNoKeywords(VirtualFrame frame, PythonObject globals, PCell[]
175
185
PArguments .setGlobals (arguments , globals );
176
186
PArguments .setClosure (arguments , closure );
177
187
PArguments .setCallerFrame (arguments , getCallerFrame (frame , callNode .getCallTarget ()));
188
+ optionallySetClassBodySpecial (arguments , callNode .getCallTarget ());
178
189
arityCheck .execute (arity , arguments , keywords );
179
190
return callNode .call (arguments );
180
191
}
@@ -186,6 +197,7 @@ protected Object doWithKeywords(VirtualFrame frame, PythonObject globals, PCell[
186
197
PArguments .setGlobals (combined , globals );
187
198
PArguments .setClosure (combined , closure );
188
199
PArguments .setCallerFrame (arguments , getCallerFrame (frame , callNode .getCallTarget ()));
200
+ optionallySetClassBodySpecial (arguments , callNode .getCallTarget ());
189
201
arityCheck .execute (arity , combined , PArguments .getKeywordArguments (combined ));
190
202
return callNode .call (combined );
191
203
}
@@ -195,6 +207,7 @@ protected Object doBuiltinWithKeywords(VirtualFrame frame, @SuppressWarnings("un
195
207
PKeyword [] keywords ) {
196
208
PArguments .setKeywordArguments (arguments , keywords );
197
209
PArguments .setCallerFrame (arguments , getCallerFrame (frame , callNode .getCallTarget ()));
210
+ optionallySetClassBodySpecial (arguments , callNode .getCallTarget ());
198
211
arityCheck .execute (arity , arguments , keywords );
199
212
return callNode .call (arguments );
200
213
}
@@ -236,6 +249,7 @@ protected Object doNoKeywords(VirtualFrame frame, Object[] arguments, PKeyword[]
236
249
PArguments .setGlobals (arguments , globals );
237
250
PArguments .setClosure (arguments , closure );
238
251
PArguments .setCallerFrame (arguments , getCallerFrame (frame , callNode .getCallTarget ()));
252
+ optionallySetClassBodySpecial (arguments , callNode .getCallTarget ());
239
253
arityCheck .execute (arity , arguments , keywords );
240
254
return callNode .call (arguments );
241
255
}
@@ -247,6 +261,7 @@ protected Object doWithKeywords(VirtualFrame frame, Object[] arguments, PKeyword
247
261
PArguments .setGlobals (combined , globals );
248
262
PArguments .setClosure (combined , closure );
249
263
PArguments .setCallerFrame (arguments , getCallerFrame (frame , callNode .getCallTarget ()));
264
+ optionallySetClassBodySpecial (arguments , callNode .getCallTarget ());
250
265
arityCheck .execute (arity , combined , PArguments .getKeywordArguments (combined ));
251
266
return callNode .call (combined );
252
267
}
@@ -255,6 +270,7 @@ protected Object doWithKeywords(VirtualFrame frame, Object[] arguments, PKeyword
255
270
protected Object doBuiltinWithKeywords (VirtualFrame frame , Object [] arguments , PKeyword [] keywords ) {
256
271
PArguments .setKeywordArguments (arguments , keywords );
257
272
PArguments .setCallerFrame (arguments , getCallerFrame (frame , callNode .getCallTarget ()));
273
+ optionallySetClassBodySpecial (arguments , callNode .getCallTarget ());
258
274
arityCheck .execute (arity , arguments , keywords );
259
275
return callNode .call (arguments );
260
276
}
0 commit comments