53
53
import com .oracle .graal .python .builtins .objects .function .PythonCallable ;
54
54
import com .oracle .graal .python .nodes .PBaseNode ;
55
55
import com .oracle .graal .python .runtime .PythonOptions ;
56
+ import com .oracle .graal .python .runtime .exception .PException ;
56
57
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
57
58
import com .oracle .truffle .api .dsl .Cached ;
58
59
import com .oracle .truffle .api .dsl .ImportStatic ;
@@ -93,11 +94,33 @@ private String[] extractKeywordNames(PKeyword[] keywords) {
93
94
return extractKeywordNames (keywords .length , keywords );
94
95
}
95
96
97
+ protected boolean arityCheckWithoutKeywords (Arity arity , Object [] arguments ) {
98
+ try {
99
+ arityCheck (arity , arguments , arity .getNumParameterIds (), PArguments .getNumberOfUserArgs (arguments ), 0 , 0 , new String [0 ]);
100
+ } catch (PException e ) {
101
+ return false ;
102
+ }
103
+ return true ;
104
+ }
105
+
106
+ @ SuppressWarnings ("unused" )
107
+ @ Specialization (guards = {
108
+ "arity == cachedArity" ,
109
+ "keywords.length == 0" ,
110
+ "arguments.length == cachedArgLen" ,
111
+ "isValid" ,
112
+ }, limit = "1" )
113
+ void constantArityCheck (Arity arity , Object [] arguments , PKeyword [] keywords ,
114
+ @ Cached ("arity" ) Arity cachedArity ,
115
+ @ Cached ("arguments.length" ) int cachedArgLen ,
116
+ @ Cached ("arityCheckWithoutKeywords(arity, arguments)" ) boolean isValid ) {
117
+ }
118
+
96
119
@ Specialization (guards = {
97
120
"cachedLen == keywords.length" ,
98
121
"cachedNumParamIds == arity.getNumParameterIds()" ,
99
122
"cachedDeclLen == arity.getNumKeywordNames()"
100
- }, limit = "getVariableArgumentInlineCacheLimit()" )
123
+ }, limit = "getVariableArgumentInlineCacheLimit()" , replaces = "constantArityCheck" )
101
124
void arityCheck (Arity arity , Object [] arguments , PKeyword [] keywords ,
102
125
@ Cached ("arity.getNumParameterIds()" ) int cachedNumParamIds ,
103
126
@ Cached ("arity.getNumKeywordNames()" ) int cachedDeclLen ,
@@ -110,7 +133,7 @@ void arityCheck(Arity arity, Object[] arguments, PKeyword[] keywords,
110
133
"cachedLen == keywords.length" ,
111
134
"cachedNumParamIds == callee.getArity().getNumParameterIds()" ,
112
135
"cachedDeclLen == callee.getArity().getNumKeywordNames()"
113
- }, limit = "getVariableArgumentInlineCacheLimit()" )
136
+ }, limit = "getVariableArgumentInlineCacheLimit()" , replaces = "constantArityCheck" )
114
137
void arityCheckCallable (PythonCallable callee , Object [] arguments , PKeyword [] keywords ,
115
138
@ Cached ("callee.getArity().getNumParameterIds()" ) int cachedNumParamIds ,
116
139
@ Cached ("callee.getArity().getNumKeywordNames()" ) int cachedDeclLen ,
@@ -120,13 +143,13 @@ void arityCheckCallable(PythonCallable callee, Object[] arguments, PKeyword[] ke
120
143
arityCheck (arity , arguments , cachedNumParamIds , PArguments .getNumberOfUserArgs (arguments ), cachedDeclLen , cachedLen , kwNames );
121
144
}
122
145
123
- @ Specialization (replaces = "arityCheck" )
146
+ @ Specialization (replaces = { "arityCheck" , "constantArityCheck" } )
124
147
void uncachedCheck (Arity arity , Object [] arguments , PKeyword [] keywords ) {
125
148
String [] kwNames = extractKeywordNames (keywords );
126
149
arityCheck (arity , arguments , PArguments .getNumberOfUserArgs (arguments ), kwNames );
127
150
}
128
151
129
- @ Specialization (replaces = "arityCheckCallable" )
152
+ @ Specialization (replaces = { "arityCheckCallable" , "constantArityCheck" } )
130
153
void uncachedCheckCallable (PythonCallable callee , Object [] arguments , PKeyword [] keywords ) {
131
154
String [] kwNames = extractKeywordNames (keywords );
132
155
arityCheck (callee .getArity (), arguments , PArguments .getNumberOfUserArgs (arguments ), kwNames );
0 commit comments