Skip to content

Commit 754519e

Browse files
committed
SlotsProcessor checks that simple slots do not take VirtualFrame
1 parent 60c8b65 commit 754519e

File tree

1 file changed

+24
-2
lines changed
  • graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor

1 file changed

+24
-2
lines changed

graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsProcessor.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555
import javax.lang.model.SourceVersion;
5656
import javax.lang.model.element.Element;
5757
import javax.lang.model.element.ElementKind;
58+
import javax.lang.model.element.ExecutableElement;
5859
import javax.lang.model.element.TypeElement;
60+
import javax.lang.model.element.VariableElement;
61+
import javax.lang.model.type.DeclaredType;
5962
import javax.lang.model.type.TypeMirror;
6063
import javax.tools.Diagnostic.Kind;
6164
import javax.tools.JavaFileObject;
@@ -218,22 +221,41 @@ private HashMap<TypeElement, Set<TpSlotData>> collectEnclosingTypes(RoundEnviron
218221
for (Element e : elements) {
219222
log("Checking type '%s'", e);
220223
if (e.getKind() != ElementKind.CLASS) {
221-
throw error(e, "@TpSlot annotation is applicable only to classes.");
224+
throw error(e, "@%s annotation is applicable only to classes.", Slot.class.getSimpleName());
222225
}
223226
TypeElement type = (TypeElement) e;
224227
if (type.getEnclosingElement() == null) {
225-
throw error(e, "@TpSlot annotation supports only inner classes at moment.");
228+
throw error(e, "@%s annotation supports only inner classes at moment.", Slot.class.getSimpleName());
226229
}
227230

228231
TypeElement enclosingType = (TypeElement) type.getEnclosingElement();
229232
for (Slot slotAnnotation : e.getAnnotationsByType(Slot.class)) {
233+
if (!slotAnnotation.isComplex()) {
234+
verifySimpleNode(type);
235+
}
230236
var tpSlotDataSet = enclosingTypes.computeIfAbsent(enclosingType, k -> new HashSet<>());
231237
tpSlotDataSet.add(new TpSlotData(slotAnnotation, enclosingType, type));
232238
}
233239
}
234240
return enclosingTypes;
235241
}
236242

243+
private static void verifySimpleNode(TypeElement type) throws ProcessingError {
244+
for (Element enclosed : type.getEnclosedElements()) {
245+
if (enclosed instanceof ExecutableElement executable) {
246+
if (executable.getAnnotationMirrors().stream().anyMatch(x -> x.getAnnotationType().asElement().getSimpleName().contentEquals("Specialization"))) {
247+
for (VariableElement param : executable.getParameters()) {
248+
if (param.asType() instanceof DeclaredType declType) {
249+
if (declType.asElement().getSimpleName().contentEquals("VirtualFrame")) {
250+
throw new ProcessingError(type, "Slot node has isComplex=false (the default), but seems to have methods that take VirtualFrame");
251+
}
252+
}
253+
}
254+
}
255+
}
256+
}
257+
}
258+
237259
private static String getNodeFactory(TpSlotData slot, TypeElement node) {
238260
return slot.enclosingType.getQualifiedName() + "Factory." + node.getSimpleName() + "Factory";
239261
}

0 commit comments

Comments
 (0)