@@ -71,6 +71,8 @@ private PythonDispatchers() {
71
71
abstract static class PythonSlotDispatcherNodeBase extends PNodeWithContext {
72
72
@ Idempotent
73
73
static boolean isSimpleSignature (PFunction callable , int positionArgsCount ) {
74
+ CompilerAsserts .partialEvaluationConstant (callable );
75
+ CompilerAsserts .partialEvaluationConstant (positionArgsCount );
74
76
Signature signature = callable .getCode ().getSignature ();
75
77
boolean result = signature .takesPositionalOnly () && signature .getMaxNumOfPositionalArgs () == positionArgsCount ;
76
78
CompilerAsserts .partialEvaluationConstant (result ); // should hold in single context
@@ -96,7 +98,8 @@ final Object execute(VirtualFrame frame, Node inliningTarget, Object callable, O
96
98
97
99
abstract Object executeImpl (VirtualFrame frame , Node inliningTarget , Object callable , Object type , Object self );
98
100
99
- @ Specialization (guards = {"isSingleContext()" , "callee == cachedCallee" , "isSimpleSignature(cachedCallee, 1)" }, limit = "getCallSiteInlineCacheMaxDepth()" )
101
+ @ Specialization (guards = {"isSingleContext()" , "callee == cachedCallee" , "isSimpleSignature(cachedCallee, 1)" }, //
102
+ limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = "cachedCallee.getCodeStableAssumption()" )
100
103
protected static Object doCachedPFunction (VirtualFrame frame , @ SuppressWarnings ("unused" ) PFunction callee , @ SuppressWarnings ("unused" ) Object type , Object self ,
101
104
@ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
102
105
@ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ) {
@@ -136,7 +139,8 @@ final Object execute(VirtualFrame frame, Node inliningTarget, Object callable, O
136
139
137
140
abstract Object executeImpl (VirtualFrame frame , Node inliningTarget , Object callable , Object type , Object self , Object arg1 );
138
141
139
- @ Specialization (guards = {"isSingleContext()" , "callee == cachedCallee" , "isSimpleSignature(cachedCallee, 2)" }, limit = "getCallSiteInlineCacheMaxDepth()" )
142
+ @ Specialization (guards = {"isSingleContext()" , "callee == cachedCallee" , "isSimpleSignature(cachedCallee, 2)" }, //
143
+ limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = "cachedCallee.getCodeStableAssumption()" )
140
144
protected static Object doCachedPFunction (VirtualFrame frame , @ SuppressWarnings ("unused" ) PFunction callee , @ SuppressWarnings ("unused" ) Object type , Object self , Object arg1 ,
141
145
@ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
142
146
@ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ) {
@@ -168,59 +172,44 @@ static Object doGeneric(VirtualFrame frame, Node inliningTarget, Object callable
168
172
@ GenerateUncached
169
173
@ GenerateInline
170
174
@ GenerateCached (false )
171
- abstract static class TernaryOrBinaryPythonSlotDispatcherNode extends PythonSlotDispatcherNodeBase {
172
- final Object execute (VirtualFrame frame , Node inliningTarget , boolean callTernary , Object callable , Object type , Object self , Object arg1 , Object arg2 ) {
175
+ abstract static class TernaryPythonSlotDispatcherNode extends PythonSlotDispatcherNodeBase {
176
+ final Object execute (VirtualFrame frame , Node inliningTarget , Object callable , Object type , Object self , Object arg1 , Object arg2 ) {
173
177
assert !(callable instanceof TruffleWeakReference <?>);
174
178
assert !(type instanceof TruffleWeakReference <?>);
175
- return executeImpl (frame , inliningTarget , callTernary , callable , type , self , arg1 , arg2 );
179
+ return executeImpl (frame , inliningTarget , callable , type , self , arg1 , arg2 );
176
180
}
177
181
178
- abstract Object executeImpl (VirtualFrame frame , Node inliningTarget , boolean callTernary , Object callable , Object type , Object self , Object arg1 , Object arg2 );
182
+ abstract Object executeImpl (VirtualFrame frame , Node inliningTarget , Object callable , Object type , Object self , Object arg1 , Object arg2 );
179
183
180
- @ Idempotent
181
- static int getArgsCount (boolean callTernary ) {
182
- return callTernary ? 3 : 2 ;
183
- }
184
-
185
- @ Specialization (guards = {"isSingleContext()" , "callee == cachedCallee" , "isSimpleSignature(cachedCallee, getArgsCount(callTernary))" }, limit = "getCallSiteInlineCacheMaxDepth()" )
186
- protected static Object doCachedPFunction (VirtualFrame frame , boolean callTernary , @ SuppressWarnings ("unused" ) PFunction callee , @ SuppressWarnings ("unused" ) Object type , Object self ,
184
+ @ Specialization (guards = {"isSingleContext()" , "callee == cachedCallee" , "isSimpleSignature(cachedCallee, 3)" }, //
185
+ limit = "getCallSiteInlineCacheMaxDepth()" , assumptions = "cachedCallee.getCodeStableAssumption()" )
186
+ protected static Object doCachedPFunction (VirtualFrame frame , @ SuppressWarnings ("unused" ) PFunction callee , @ SuppressWarnings ("unused" ) Object type , Object self ,
187
187
Object arg1 , Object arg2 ,
188
188
@ SuppressWarnings ("unused" ) @ Cached ("callee" ) PFunction cachedCallee ,
189
189
@ Cached ("createInvokeNode(cachedCallee)" ) FunctionInvokeNode invoke ) {
190
- Object [] arguments = PArguments .create (getArgsCount ( callTernary ) );
190
+ Object [] arguments = PArguments .create (3 );
191
191
PArguments .setArgument (arguments , 0 , self );
192
192
PArguments .setArgument (arguments , 1 , arg1 );
193
- if (callTernary ) {
194
- PArguments .setArgument (arguments , 2 , arg2 );
195
- }
193
+ PArguments .setArgument (arguments , 2 , arg2 );
196
194
return invoke .execute (frame , arguments );
197
195
}
198
196
199
197
@ Specialization (replaces = "doCachedPFunction" )
200
198
@ InliningCutoff
201
- static Object doGeneric (VirtualFrame frame , Node inliningTarget , boolean callTernary , Object callableObj , Object type , Object self , Object arg1 , Object arg2 ,
199
+ static Object doGeneric (VirtualFrame frame , Node inliningTarget , Object callableObj , Object type , Object self , Object arg1 , Object arg2 ,
202
200
@ Cached MaybeBindDescriptorNode bindDescriptorNode ,
203
201
@ Cached (inline = false ) CallNode callNode ) {
204
202
Object bound = bindDescriptorNode .execute (frame , inliningTarget , callableObj , self , type );
205
- int argsCount = 1 + asInt (callTernary ) + asInt (!(bound instanceof BoundDescriptor ));
206
- Object [] arguments = new Object [argsCount ];
207
- int argIndex = 0 ;
203
+ Object [] arguments ;
208
204
Object callable ;
209
205
if (bound instanceof BoundDescriptor boundDescr ) {
210
206
callable = boundDescr .descriptor ;
207
+ arguments = new Object []{arg1 , arg2 };
211
208
} else {
212
209
callable = bound ;
213
- arguments [argIndex ++] = self ;
214
- }
215
- arguments [argIndex ++] = arg1 ;
216
- if (callTernary ) {
217
- arguments [argIndex ] = arg2 ;
210
+ arguments = new Object []{self , arg1 , arg2 };
218
211
}
219
212
return callNode .execute (frame , callable , arguments );
220
213
}
221
-
222
- private static int asInt (boolean b ) {
223
- return b ? 1 : 0 ;
224
- }
225
214
}
226
215
}
0 commit comments