use of com.oracle.truffle.dsl.processor.model.SpecializationData in project graal by oracle.
the class NodeParser method resolveReplaces.
private void resolveReplaces(NodeData node) {
// flatten transitive includes
for (SpecializationData specialization : node.getSpecializations()) {
if (specialization.getReplaces().isEmpty()) {
continue;
}
Set<SpecializationData> foundSpecializations = new HashSet<>();
collectIncludes(specialization, foundSpecializations, new HashSet<SpecializationData>());
specialization.getReplaces().addAll(foundSpecializations);
}
}
use of com.oracle.truffle.dsl.processor.model.SpecializationData in project graal by oracle.
the class NodeParser method initializeExecutableTypeHierarchy.
private static void initializeExecutableTypeHierarchy(NodeData node) {
SpecializationData polymorphic = node.getPolymorphicSpecialization();
if (polymorphic != null) {
boolean polymorphicSignatureFound = false;
List<TypeMirror> dynamicTypes = polymorphic.getDynamicTypes();
TypeMirror frame = null;
if (polymorphic.getFrame() != null) {
frame = dynamicTypes.remove(0);
}
ExecutableTypeData polymorphicType = new ExecutableTypeData(node, polymorphic.getReturnType().getType(), "execute", frame, dynamicTypes);
String genericName = ExecutableTypeData.createName(polymorphicType) + "_";
polymorphicType.setUniqueName(genericName);
for (ExecutableTypeData type : node.getExecutableTypes()) {
if (polymorphicType.sameSignature(type)) {
polymorphicSignatureFound = true;
break;
}
}
if (!polymorphicSignatureFound) {
node.getExecutableTypes().add(polymorphicType);
}
}
List<ExecutableTypeData> rootTypes = buildExecutableHierarchy(node);
List<ExecutableTypeData> additionalAbstractRootTypes = new ArrayList<>();
for (int i = 1; i < rootTypes.size(); i++) {
ExecutableTypeData rootType = rootTypes.get(i);
if (rootType.isAbstract()) {
// cannot implemement root
additionalAbstractRootTypes.add(rootType);
} else {
node.getExecutableTypes().remove(rootType);
}
}
if (!additionalAbstractRootTypes.isEmpty()) {
node.addError("Incompatible abstract execute methods found %s.", additionalAbstractRootTypes);
}
namesUnique(node.getExecutableTypes());
}
use of com.oracle.truffle.dsl.processor.model.SpecializationData in project graal by oracle.
the class NodeParser method initializeReachability.
private static void initializeReachability(final NodeData node) {
List<SpecializationData> specializations = node.getSpecializations();
for (int i = specializations.size() - 1; i >= 0; i--) {
SpecializationData current = specializations.get(i);
if (current.isPolymorphic()) {
current.setReachable(true);
continue;
}
List<SpecializationData> shadowedBy = null;
for (int j = i - 1; j >= 0; j--) {
SpecializationData prev = specializations.get(j);
if (prev.isPolymorphic()) {
continue;
}
if (!current.isReachableAfter(prev)) {
if (shadowedBy == null) {
shadowedBy = new ArrayList<>();
}
shadowedBy.add(prev);
}
}
if (shadowedBy != null) {
StringBuilder name = new StringBuilder();
String sep = "";
for (SpecializationData shadowSpecialization : shadowedBy) {
name.append(sep);
name.append(shadowSpecialization.createReferenceName());
sep = ", ";
}
current.addError("%s is not reachable. It is shadowed by %s.", current.isFallback() ? "Generic" : "Specialization", name);
}
current.setReachable(shadowedBy == null);
}
}
use of com.oracle.truffle.dsl.processor.model.SpecializationData in project graal by oracle.
the class NodeParser method initializeOrder.
private static void initializeOrder(NodeData node) {
List<SpecializationData> specializations = node.getSpecializations();
Collections.sort(specializations);
for (SpecializationData specialization : specializations) {
String searchName = specialization.getInsertBeforeName();
if (searchName == null || specialization.getMethod() == null) {
continue;
}
SpecializationData found = lookupSpecialization(node, searchName);
if (found == null || found.getMethod() == null) {
AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "insertBefore");
specialization.addError(value, "The referenced specialization '%s' could not be found.", searchName);
continue;
}
ExecutableElement currentMethod = specialization.getMethod();
ExecutableElement insertBeforeMethod = found.getMethod();
TypeMirror currentEnclosedType = currentMethod.getEnclosingElement().asType();
TypeMirror insertBeforeEnclosedType = insertBeforeMethod.getEnclosingElement().asType();
if (ElementUtils.typeEquals(currentEnclosedType, insertBeforeEnclosedType) || !ElementUtils.isSubtype(currentEnclosedType, insertBeforeEnclosedType)) {
AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "insertBefore");
specialization.addError(value, "Specializations can only be inserted before specializations in superclasses.", searchName);
continue;
}
specialization.setInsertBefore(found);
}
for (int i = 0; i < specializations.size(); i++) {
SpecializationData specialization = specializations.get(i);
SpecializationData insertBefore = specialization.getInsertBefore();
if (insertBefore != null) {
int insertIndex = specializations.indexOf(insertBefore);
if (insertIndex < i) {
specializations.remove(i);
specializations.add(insertIndex, specialization);
}
}
}
for (int i = 0; i < specializations.size(); i++) {
specializations.get(i).setIndex(i);
}
}
use of com.oracle.truffle.dsl.processor.model.SpecializationData in project graal by oracle.
the class NodeParser method initializeSpecializations.
private void initializeSpecializations(List<? extends Element> elements, final NodeData node) {
if (node.getSpecializations().isEmpty()) {
return;
}
initializeExpressions(elements, node);
if (node.hasErrors()) {
return;
}
initializeGeneric(node);
initializeUninitialized(node);
initializeOrder(node);
// requires specializations
initializePolymorphism(node);
initializeReachability(node);
initializeReplaces(node);
initializeFallbackReachability(node);
resolveReplaces(node);
List<SpecializationData> specializations = node.getSpecializations();
for (SpecializationData cur : specializations) {
for (SpecializationData contained : cur.getReplaces()) {
if (contained != cur) {
contained.getExcludedBy().add(cur);
}
}
}
initializeSpecializationIdsWithMethodNames(node.getSpecializations());
}
Aggregations