@@ -34,7 +34,7 @@ public class CoreModuleChecks {
34
34
this .processor = processor ;
35
35
}
36
36
37
- void checks (int [] lowerFixnum , CoreMethod coreMethod , TypeElement klass , boolean hasZeroArgument ) {
37
+ void checks (int [] lowerFixnum , CoreMethod coreMethod , TypeElement klass , boolean hasSelfArgument ) {
38
38
byte [] lowerArgs = null ;
39
39
List <ExecutableElement > specializationMethods = new ArrayList <>();
40
40
@@ -54,13 +54,11 @@ void checks(int[] lowerFixnum, CoreMethod coreMethod, TypeElement klass, boolean
54
54
specializationMethods .add (specializationMethod );
55
55
56
56
lowerArgs = checkLowerFixnumArguments (specializationMethod , lowerArgs );
57
+
57
58
if (coreMethod != null ) {
58
- checkAmbiguousOptionalArguments (
59
- coreMethod ,
60
- specializationMethod ,
61
- specializationAnnotation );
59
+ checkCoreMethodArguments (coreMethod , specializationMethod , specializationAnnotation ,
60
+ hasSelfArgument );
62
61
}
63
-
64
62
}
65
63
66
64
klassIt = processor
@@ -81,8 +79,8 @@ void checks(int[] lowerFixnum, CoreMethod coreMethod, TypeElement klass, boolean
81
79
// Verify against the lowerFixnum annotation
82
80
for (int i = 0 ; i < lowerArgs .length ; i ++) {
83
81
boolean shouldLower = lowerArgs [i ] == 0b01; // int without long
84
- if (shouldLower && !contains (lowerFixnum , hasZeroArgument ? i : i + 1 )) {
85
- processor .error ("should use lowerFixnum for argument " + (hasZeroArgument ? i : i + 1 ), klass );
82
+ if (shouldLower && !contains (lowerFixnum , hasSelfArgument ? i : i + 1 )) {
83
+ processor .error ("should use lowerFixnum for argument " + (hasSelfArgument ? i : i + 1 ), klass );
86
84
}
87
85
}
88
86
}
@@ -133,10 +131,11 @@ private static boolean contains(int[] array, int value) {
133
131
return false ;
134
132
}
135
133
136
- private void checkAmbiguousOptionalArguments (
134
+ private void checkCoreMethodArguments (
137
135
CoreMethod coreMethod ,
138
136
ExecutableElement specializationMethod ,
139
- Specialization specializationAnnotation ) {
137
+ Specialization specializationAnnotation ,
138
+ boolean hasSelfArgument ) {
140
139
List <? extends VariableElement > parameters = specializationMethod .getParameters ();
141
140
int n = getLastParameterIndex (parameters );
142
141
@@ -145,21 +144,24 @@ private void checkAmbiguousOptionalArguments(
145
144
processor .error ("last argument must be a RootCallTarget for alwaysInlined " , specializationMethod );
146
145
return ;
147
146
}
148
- n --;
147
+ // All other arguments are packed as Object[]
148
+ return ;
149
149
}
150
150
151
- if (coreMethod .needsBlock () && !coreMethod .alwaysInlined ()) {
151
+ final int parametersCount = getParametersCount (parameters );
152
+ int expectedParametersCount = coreMethod .required () + coreMethod .optional ();
153
+ if (hasSelfArgument ) {
154
+ expectedParametersCount ++;
155
+ }
156
+
157
+ if (coreMethod .needsBlock ()) {
152
158
if (n < 0 ) {
153
159
processor .error ("invalid block method parameter position for" , specializationMethod );
154
160
return ;
155
161
}
156
162
checkParameterBlock (parameters .get (n ));
157
163
n --; // Ignore block argument.
158
- }
159
-
160
- if (coreMethod .alwaysInlined ()) {
161
- // All other arguments are packed as Object[]
162
- return ;
164
+ expectedParametersCount ++;
163
165
}
164
166
165
167
if (coreMethod .rest ()) {
@@ -173,6 +175,13 @@ private void checkAmbiguousOptionalArguments(
173
175
return ;
174
176
}
175
177
n --; // ignore final Object[] argument
178
+ expectedParametersCount ++;
179
+ }
180
+
181
+ if (parametersCount != expectedParametersCount ) {
182
+ processor .error ("expected " + expectedParametersCount + " parameters for this @CoreMethod but there are " +
183
+ parametersCount , specializationMethod );
184
+ return ;
176
185
}
177
186
178
187
for (int i = 0 ; i < coreMethod .optional (); i ++, n --) {
@@ -221,6 +230,25 @@ private static int getLastParameterIndex(List<? extends VariableElement> paramet
221
230
return n ;
222
231
}
223
232
233
+ private int getParametersCount (List <? extends VariableElement > parameters ) {
234
+ int last = getLastParameterIndex (parameters );
235
+ int count = last + 1 ;
236
+
237
+ if (count > 0 ) {
238
+ var type = parameters .get (0 ).asType ();
239
+ if (processor .isSameType (type , processor .nodeType )) {
240
+ if (processor .isSameType (type , processor .virtualFrameType )) {
241
+ return count - 2 ;
242
+ } else {
243
+ return count - 1 ;
244
+ }
245
+ } else if (processor .isSameType (type , processor .virtualFrameType )) {
246
+ return count - 1 ;
247
+ }
248
+ }
249
+ return count ;
250
+ }
251
+
224
252
private void checkParameterUnguarded (Specialization specializationAnnotation , VariableElement parameter ) {
225
253
String name = parameter .getSimpleName ().toString ();
226
254
0 commit comments