# HG changeset patch # User Christian Humer # Date 1369158660 -7200 # Node ID 5402504894fe7487fd082993aae25f4d9f7f8267 # Parent ba02d19dd3cc325809c45efa498f1f830751366a# Parent 05b719a4ae09457ab67ccbc172fdbe610c2aa862 Merge. diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue May 21 19:51:00 2013 +0200 @@ -149,6 +149,7 @@ // Pass on the source section to the new node. newNode.assignSourceSection(sourceSection); } + onReplace(newNode, reason); return (T) this.getParent().replaceChild(this, newNode); } @@ -170,6 +171,16 @@ } /** + * Intended to be implemented by subclasses of {@link Node} to receive a notification when the + * node is rewritten. This method is invoked before the actual replace has happened. + * + * @param newNode the replacement node + * @param reason the reason the replace supplied + */ + protected void onReplace(Node newNode, String reason) { + } + + /** * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all * child nodes. * diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeInfo.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeInfo.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeInfo.java Tue May 21 19:51:00 2013 +0200 @@ -37,4 +37,11 @@ * @return the short name */ String shortName() default ""; + + Kind kind() default Kind.SPECIALIZED; + + public enum Kind { + UNINITIALIZED, SPECIALIZED, GENERIC + } + } diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/TruffleTypes.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/TruffleTypes.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/TruffleTypes.java Tue May 21 19:51:00 2013 +0200 @@ -26,7 +26,7 @@ import javax.lang.model.element.*; import javax.lang.model.type.*; -import javax.tools.Diagnostic.*; +import javax.tools.Diagnostic.Kind; import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; @@ -47,6 +47,8 @@ private final TypeMirror invalidAssumption; private final DeclaredType childAnnotation; private final DeclaredType childrenAnnotation; + private final DeclaredType nodeInfoAnnotation; + private final DeclaredType nodeInfoKind; private final TypeMirror compilerDirectives; private final TypeMirror compilerAsserts; @@ -63,6 +65,12 @@ compilerAsserts = getRequired(context, CompilerAsserts.class); assumption = getRequired(context, Assumption.class); invalidAssumption = getRequired(context, InvalidAssumptionException.class); + nodeInfoAnnotation = getRequired(context, NodeInfo.class); + nodeInfoKind = getRequired(context, NodeInfo.Kind.class); + } + + public DeclaredType getNodeInfoAnnotation() { + return nodeInfoAnnotation; } public boolean verify(ProcessorContext context, Element element, AnnotationMirror mirror) { @@ -77,6 +85,10 @@ return false; } + public DeclaredType getNodeInfoKind() { + return nodeInfoKind; + } + private DeclaredType getRequired(ProcessorContext context, Class clazz) { TypeMirror type = context.getType(clazz); if (type == null) { diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/Utils.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/Utils.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/Utils.java Tue May 21 19:51:00 2013 +0200 @@ -40,6 +40,26 @@ */ public class Utils { + public static ExecutableElement findExecutableElement(DeclaredType type, String name) { + List elements = ElementFilter.methodsIn(type.asElement().getEnclosedElements()); + for (ExecutableElement executableElement : elements) { + if (executableElement.getSimpleName().toString().equals(name)) { + return executableElement; + } + } + return null; + } + + public static VariableElement findVariableElement(DeclaredType type, String name) { + List elements = ElementFilter.fieldsIn(type.asElement().getEnclosedElements()); + for (VariableElement variableElement : elements) { + if (variableElement.getSimpleName().toString().equals(name)) { + return variableElement; + } + } + return null; + } + public static String getMethodBody(ProcessingEnvironment env, ExecutableElement method) { if (method instanceof CodeExecutableElement) { return ((CodeExecutableElement) method).getBody(); diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/ast/CodeAnnotationMirror.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/ast/CodeAnnotationMirror.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/ast/CodeAnnotationMirror.java Tue May 21 19:51:00 2013 +0200 @@ -26,8 +26,8 @@ import javax.lang.model.element.*; import javax.lang.model.type.*; -import javax.lang.model.util.*; +import com.oracle.truffle.codegen.processor.*; import com.oracle.truffle.codegen.processor.api.element.*; public class CodeAnnotationMirror implements WritableAnnotationMirror { @@ -60,13 +60,7 @@ } public ExecutableElement findExecutableElement(String name) { - List elements = ElementFilter.methodsIn(annotationType.asElement().getEnclosedElements()); - for (ExecutableElement executableElement : elements) { - if (executableElement.getSimpleName().toString().equals(name)) { - return executableElement; - } - } - return null; + return Utils.findExecutableElement(annotationType, name); } public static CodeAnnotationMirror clone(AnnotationMirror mirror) { diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeData.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeData.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeData.java Tue May 21 19:51:00 2013 +0200 @@ -75,23 +75,6 @@ return count; } - public boolean startsWithSignature(TemplateMethod method) { - for (ActualParameter param : getParameters()) { - if (!param.getSpecification().isSignature()) { - continue; - } - ActualParameter foundParam = method.findParameter(param.getLocalName()); - if (foundParam != null) { - TypeData actualType = param.getTypeSystemType(); - TypeData foundType = foundParam.getTypeSystemType(); - if (actualType == null || foundType == null || !actualType.equalsType(foundType)) { - return false; - } - } - } - return true; - } - public boolean hasGenericSignature() { List types = getSignature(); for (TypeData typeData : types) { diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeMethodParser.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeMethodParser.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/ExecutableTypeMethodParser.java Tue May 21 19:51:00 2013 +0200 @@ -44,8 +44,15 @@ @Override public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { MethodSpec spec = createDefaultMethodSpec(method, mirror, false, null); + List requiredSpecs = new ArrayList<>(spec.getRequired()); + spec.getRequired().clear(); + + for (ParameterSpec originalSpec : requiredSpecs) { + spec.addRequired(new ParameterSpec(originalSpec, Arrays.asList(getNode().getTypeSystem().getGenericType()))); + } + spec.setVariableRequiredArguments(true); - ParameterSpec other = new ParameterSpec("other", nodeTypeMirrors(getNode())); + ParameterSpec other = new ParameterSpec("other", Arrays.asList(getNode().getTypeSystem().getGenericType())); other.setCardinality(Cardinality.MANY); other.setSignature(true); other.setIndexed(true); diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java Tue May 21 19:51:00 2013 +0200 @@ -1336,6 +1336,27 @@ baseType = nodeGen.asType(); } CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), baseType, false); + + String shortName = specialization.getNode().getShortName(); + CodeAnnotationMirror nodeInfoMirror = new CodeAnnotationMirror(getContext().getTruffleTypes().getNodeInfoAnnotation()); + if (shortName != null) { + nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("shortName"), new CodeAnnotationValue(shortName)); + } + + DeclaredType nodeinfoKind = getContext().getTruffleTypes().getNodeInfoKind(); + VariableElement kind; + if (specialization.isGeneric()) { + kind = Utils.findVariableElement(nodeinfoKind, "GENERIC"); + } else if (specialization.isUninitialized()) { + kind = Utils.findVariableElement(nodeinfoKind, "UNINITIALIZED"); + } else { + kind = Utils.findVariableElement(nodeinfoKind, "SPECIALIZED"); + } + + nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("kind"), new CodeAnnotationValue(kind)); + + clazz.getAnnotationMirrors().add(nodeInfoMirror); + return clazz; } @@ -1373,12 +1394,13 @@ CodeTreeBuilder builder = new CodeTreeBuilder(parent); - ExecutableTypeData foundEvaluatedPrimaryType = findFunctionalExecutableType(specialization, execType.getEvaluatedCount()); + List primaryExecutes = findFunctionalExecutableType(specialization, execType.getEvaluatedCount()); - if (execType == foundEvaluatedPrimaryType || foundEvaluatedPrimaryType == null) { + if (primaryExecutes.contains(execType) || primaryExecutes.isEmpty()) { builder.tree(createFunctionalExecute(builder, specialization, execType)); } else if (needsCastingExecuteMethod(execType, primaryType)) { - builder.tree(createCastingExecute(builder, specialization, execType, foundEvaluatedPrimaryType)); + assert !primaryExecutes.isEmpty(); + builder.tree(createCastingExecute(builder, specialization, execType, primaryExecutes.get(0))); } else { return null; } @@ -1420,7 +1442,7 @@ return false; } - private ExecutableTypeData findFunctionalExecutableType(SpecializationData specialization, int evaluatedCount) { + private List findFunctionalExecutableType(SpecializationData specialization, int evaluatedCount) { TypeData primaryType = specialization.getReturnType().getTypeSystemType(); List otherTypes = specialization.getNode().getExecutableTypes(evaluatedCount); @@ -1432,19 +1454,24 @@ filteredTypes.add(compareType); } - for (ExecutableTypeData compareType : filteredTypes) { - if (compareType.startsWithSignature(specialization)) { - return compareType; + // no direct matches found use generic where the type is Object + if (filteredTypes.isEmpty()) { + for (ExecutableTypeData compareType : otherTypes) { + if (compareType.getType().isGeneric() && !compareType.hasUnexpectedValue(getContext())) { + filteredTypes.add(compareType); + } } } - for (ExecutableTypeData compareType : otherTypes) { - if (compareType.startsWithSignature(specialization)) { - return compareType; + if (filteredTypes.isEmpty()) { + for (ExecutableTypeData compareType : otherTypes) { + if (compareType.getType().isGeneric()) { + filteredTypes.add(compareType); + } } } - return null; + return filteredTypes; } private CodeTree createCastingExecute(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData executable, ExecutableTypeData castExecutable) { diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeData.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeData.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeData.java Tue May 21 19:51:00 2013 +0200 @@ -51,6 +51,8 @@ private List shortCircuits; private List assumptions; + private String shortName; + public NodeData(TypeElement type, String id) { super(type, null, null); this.nodeId = id; @@ -72,6 +74,14 @@ this.assumptions = splitSource.assumptions; } + void setShortName(String shortName) { + this.shortName = shortName; + } + + public String getShortName() { + return shortName; + } + public boolean isSplitByMethodName() { return splitByMethodName; } diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeParser.java Tue May 21 19:51:00 2013 +0200 @@ -32,6 +32,7 @@ import com.oracle.truffle.api.codegen.*; import com.oracle.truffle.api.codegen.NodeClass.InheritNode; +import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.codegen.processor.*; import com.oracle.truffle.codegen.processor.node.NodeChildData.Cardinality; import com.oracle.truffle.codegen.processor.node.NodeChildData.ExecutionKind; @@ -577,6 +578,11 @@ } } } + AnnotationMirror nodeInfoMirror = findFirstAnnotation(lookupTypes, NodeInfo.class); + if (nodeInfoMirror != null) { + nodeData.setShortName(Utils.getAnnotationValue(String.class, nodeInfoMirror, "shortName")); + } + nodeData.setAssumptions(new ArrayList<>(assumptionsList)); nodeData.setNodeType(nodeType); nodeData.setSplitByMethodName(splitByMethodName); diff -r 05b719a4ae09 -r 5402504894fe graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/ParameterSpec.java --- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/ParameterSpec.java Tue May 21 12:39:40 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/ParameterSpec.java Tue May 21 19:51:00 2013 +0200 @@ -55,6 +55,16 @@ this.allowedTypes = allowedTypes; } + public ParameterSpec(ParameterSpec o, List allowedTypes) { + this.name = o.name; + this.cardinality = o.cardinality; + this.signature = o.signature; + this.indexed = o.indexed; + this.local = o.local; + this.typeDefinition = o.typeDefinition; + this.allowedTypes = allowedTypes; + } + void setTypeDefinition(TypeDef typeDefinition) { this.typeDefinition = typeDefinition; }