com.sun.tools.javac.code.Type.UndetVar.InferenceBound Java Examples

The following examples show how to use com.sun.tools.javac.code.Type.UndetVar.InferenceBound. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Infer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getDependencyName(GraphUtils.Node<ListBuffer<Type>> to, GraphUtils.DependencyKind dk) {
    if (dk == DependencyKind.STUCK) return "";
    else {
        StringBuilder buf = new StringBuilder();
        String sep = "";
        for (Type from : data) {
            UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from);
            for (Type bound : uv.getBounds(InferenceBound.values())) {
                if (bound.containsAny(List.from(to.data))) {
                    buf.append(sep);
                    buf.append(bound);
                    sep = ",";
                }
            }
        }
        return buf.toString();
    }
}
 
Example #2
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Properties dependencyAttributes(Node sink, GraphUtils.DependencyKind dk) {
    Properties p = new Properties();
    p.put("style", ((DependencyKind)dk).dotSyle);
    StringBuilder buf = new StringBuilder();
    String sep = "";
    for (Type from : data) {
        UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from);
        for (Type bound : uv.getBounds(InferenceBound.values())) {
            if (bound.containsAny(List.from(sink.data))) {
                buf.append(sep);
                buf.append(bound);
                sep = ",";
            }
        }
    }
    p.put("label", "\"" + buf.toString() + "\"");
    return p;
}
 
Example #3
Source File: Infer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Type generateReturnConstraintsPrimitive(JCTree tree, UndetVar from,
        Type to, Attr.ResultInfo resultInfo, InferenceContext inferenceContext) {
    if (!allowGraphInference) {
        //if legacy, just return boxed type
        return types.boxedClass(to).type;
    }
    //if graph inference we need to skip conflicting boxed bounds...
    for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.UPPER,
            InferenceBound.LOWER)) {
        Type boundAsPrimitive = types.unboxedType(t);
        if (boundAsPrimitive == null || boundAsPrimitive.hasTag(NONE)) {
            continue;
        }
        return generateReferenceToTargetConstraint(tree, from, to,
                resultInfo, inferenceContext);
    }
    return types.boxedClass(to).type;
}
 
Example #4
Source File: Infer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
    if ((t.qtype.tsym.flags() & Flags.THROWS) == 0) {
        //not a throws undet var
        return false;
    }
    if (t.getBounds(InferenceBound.EQ, InferenceBound.LOWER, InferenceBound.UPPER)
                .diff(t.getDeclaredBounds()).nonEmpty()) {
        //not an unbounded undet var
        return false;
    }
    Infer infer = inferenceContext.infer();
    for (Type db : t.getDeclaredBounds()) {
        if (t.isInterface()) continue;
        if (infer.types.asSuper(infer.syms.runtimeExceptionType, db.tsym) != null) {
            //declared bound is a supertype of RuntimeException
            return true;
        }
    }
    //declared bound is more specific then RuntimeException - give up
    return false;
}
 
Example #5
Source File: Types.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Is t a supertype of s?
 */
public boolean isSuperType(Type t, Type s) {
    switch (t.getTag()) {
    case ERROR:
        return true;
    case UNDETVAR: {
        UndetVar undet = (UndetVar)t;
        if (t == s ||
            undet.qtype == s ||
            s.hasTag(ERROR) ||
            s.hasTag(BOT)) {
            return true;
        }
        undet.addBound(InferenceBound.LOWER, s, this);
        return true;
    }
    default:
        return isSubtype(s, t);
    }
}
 
Example #6
Source File: Infer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) {
    Infer infer = inferenceContext.infer();
    for (Type b : uv.getBounds(InferenceBound.UPPER)) {
        if (inferenceContext.inferenceVars().contains(b)) {
            UndetVar uv2 = (UndetVar)inferenceContext.asFree(b);
            if (uv2.isCaptured()) continue;
            //alpha <: beta
            //0. set beta :> alpha
            addBound(InferenceBound.LOWER, uv2, inferenceContext.asInstType(uv.qtype), infer);
            //1. copy alpha's lower to beta's
            for (Type l : uv.getBounds(InferenceBound.LOWER)) {
                addBound(InferenceBound.LOWER, uv2, inferenceContext.asInstType(l), infer);
            }
            //2. copy beta's upper to alpha's
            for (Type u : uv2.getBounds(InferenceBound.UPPER)) {
                addBound(InferenceBound.UPPER, uv, inferenceContext.asInstType(u), infer);
            }
        }
    }
}
 
Example #7
Source File: Infer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) {
    Infer infer = inferenceContext.infer();
    for (Type b : uv.getBounds(InferenceBound.LOWER)) {
        if (inferenceContext.inferenceVars().contains(b)) {
            UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b);
            if (uv2.isCaptured()) continue;
            //alpha :> beta
            //0. set beta <: alpha
            addBound(InferenceBound.UPPER, uv2, inferenceContext.asInstType(uv.qtype), infer);
            //1. copy alpha's upper to beta's
            for (Type u : uv.getBounds(InferenceBound.UPPER)) {
                addBound(InferenceBound.UPPER, uv2, inferenceContext.asInstType(u), infer);
            }
            //2. copy beta's lower to alpha's
            for (Type l : uv2.getBounds(InferenceBound.LOWER)) {
                addBound(InferenceBound.LOWER, uv, inferenceContext.asInstType(l), infer);
            }
        }
    }
}
 
Example #8
Source File: Infer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Save the state of this inference context
 */
List<Type> save() {
    ListBuffer<Type> buf = new ListBuffer<>();
    for (Type t : undetvars) {
        UndetVar uv = (UndetVar)t;
        UndetVar uv2 = new UndetVar((TypeVar)uv.qtype, types);
        for (InferenceBound ib : InferenceBound.values()) {
            for (Type b : uv.getBounds(ib)) {
                uv2.addBound(ib, b, types);
            }
        }
        uv2.inst = uv.inst;
        buf.add(uv2);
    }
    return buf.toList();
}
 
Example #9
Source File: Infer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
Type returnConstraintTarget(Type from, Type to) {
    if (from.hasTag(VOID)) {
        return syms.voidType;
    } else if (to.hasTag(NONE)) {
        return from.isPrimitive() ? from : syms.objectType;
    } else if (from.hasTag(UNDETVAR) && to.isPrimitive()) {
        if (!allowGraphInference) {
            //if legacy, just return boxed type
            return types.boxedClass(to).type;
        }
        //if graph inference we need to skip conflicting boxed bounds...
        UndetVar uv = (UndetVar)from;
        for (Type t : uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) {
            Type boundAsPrimitive = types.unboxedType(t);
            if (boundAsPrimitive == null) continue;
            if (types.isConvertible(boundAsPrimitive, to)) {
                //effectively skip return-type constraint generation (compatibility)
                return syms.objectType;
            }
        }
        return types.boxedClass(to).type;
    } else {
        return to;
    }
}
 
Example #10
Source File: Infer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) {
    Infer infer = inferenceContext.infer();
    for (Type b : uv.getBounds(InferenceBound.UPPER)) {
        if (inferenceContext.inferenceVars().contains(b)) {
            UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b);
            if (uv2.isCaptured()) continue;
            //alpha <: beta
            //0. set beta :> alpha
            addBound(InferenceBound.LOWER, uv2, inferenceContext.asInstType(uv.qtype), infer);
            //1. copy alpha's lower to beta's
            for (Type l : uv.getBounds(InferenceBound.LOWER)) {
                addBound(InferenceBound.LOWER, uv2, inferenceContext.asInstType(l), infer);
            }
            //2. copy beta's upper to alpha's
            for (Type u : uv2.getBounds(InferenceBound.UPPER)) {
                addBound(InferenceBound.UPPER, uv, inferenceContext.asInstType(u), infer);
            }
        }
    }
}
 
Example #11
Source File: Infer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
    if ((t.qtype.tsym.flags() & Flags.THROWS) == 0) {
        //not a throws undet var
        return false;
    }
    if (t.getBounds(InferenceBound.EQ, InferenceBound.LOWER, InferenceBound.UPPER)
                .diff(t.getDeclaredBounds()).nonEmpty()) {
        //not an unbounded undet var
        return false;
    }
    Infer infer = inferenceContext.infer();
    for (Type db : t.getDeclaredBounds()) {
        if (t.isInterface()) continue;
        if (infer.types.asSuper(infer.syms.runtimeExceptionType, db.tsym) != null) {
            //declared bound is a supertype of RuntimeException
            return true;
        }
    }
    //declared bound is more specific then RuntimeException - give up
    return false;
}
 
Example #12
Source File: Infer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Save the state of this inference context
 */
List<Type> save() {
    ListBuffer<Type> buf = new ListBuffer<>();
    for (Type t : undetvars) {
        UndetVar uv = (UndetVar)t;
        UndetVar uv2 = new UndetVar((TypeVar)uv.qtype, types);
        for (InferenceBound ib : InferenceBound.values()) {
            for (Type b : uv.getBounds(ib)) {
                uv2.addBound(ib, b, types);
            }
        }
        uv2.inst = uv.inst;
        buf.add(uv2);
    }
    return buf.toList();
}
 
Example #13
Source File: Types.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Is t a supertype of s?
 */
public boolean isSuperType(Type t, Type s) {
    switch (t.getTag()) {
    case ERROR:
        return true;
    case UNDETVAR: {
        UndetVar undet = (UndetVar)t;
        if (t == s ||
            undet.qtype == s ||
            s.hasTag(ERROR) ||
            s.hasTag(BOT)) {
            return true;
        }
        undet.addBound(InferenceBound.LOWER, s, this);
        return true;
    }
    default:
        return isSubtype(s, t);
    }
}
 
Example #14
Source File: Infer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) {
    Infer infer = inferenceContext.infer();
    Type eq = null;
    for (Type e : uv.getBounds(InferenceBound.EQ)) {
        Assert.check(!inferenceContext.free(e));
        if (eq != null && !isSameType(e, eq, infer)) {
            infer.reportBoundError(uv, BoundErrorKind.EQ);
        }
        eq = e;
        for (Type l : uv.getBounds(InferenceBound.LOWER)) {
            Assert.check(!inferenceContext.free(l));
            if (!isSubtype(l, e, warn, infer)) {
                infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER);
            }
        }
        for (Type u : uv.getBounds(InferenceBound.UPPER)) {
            if (inferenceContext.free(u)) continue;
            if (!isSubtype(e, u, warn, infer)) {
                infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER);
            }
        }
    }
}
 
Example #15
Source File: Infer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) {
    Infer infer = inferenceContext.infer();
    Type eq = null;
    for (Type e : uv.getBounds(InferenceBound.EQ)) {
        Assert.check(!inferenceContext.free(e));
        if (eq != null && !isSameType(e, eq, infer)) {
            infer.reportBoundError(uv, BoundErrorKind.EQ);
        }
        eq = e;
        for (Type l : uv.getBounds(InferenceBound.LOWER)) {
            Assert.check(!inferenceContext.free(l));
            if (!isSubtype(l, e, warn, infer)) {
                infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER);
            }
        }
        for (Type u : uv.getBounds(InferenceBound.UPPER)) {
            if (inferenceContext.free(u)) continue;
            if (!isSubtype(e, u, warn, infer)) {
                infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER);
            }
        }
    }
}
 
Example #16
Source File: Types.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Is t a supertype of s?
 */
public boolean isSuperType(Type t, Type s) {
    switch (t.getTag()) {
    case ERROR:
        return true;
    case UNDETVAR: {
        UndetVar undet = (UndetVar)t;
        if (t == s ||
            undet.qtype == s ||
            s.hasTag(ERROR) ||
            s.hasTag(BOT)) {
            return true;
        }
        undet.addBound(InferenceBound.LOWER, s, this);
        return true;
    }
    default:
        return isSubtype(s, t);
    }
}
 
Example #17
Source File: Infer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Make sure that the upper bounds we got so far lead to a solvable inference
 * variable by making sure that a glb exists.
 */
void checkCompatibleUpperBounds(UndetVar uv, InferenceContext inferenceContext) {
    List<Type> hibounds =
            Type.filter(uv.getBounds(InferenceBound.UPPER), new BoundFilter(inferenceContext));
    Type hb = null;
    if (hibounds.isEmpty())
        hb = syms.objectType;
    else if (hibounds.tail.isEmpty())
        hb = hibounds.head;
    else
        hb = types.glb(hibounds);
    if (hb == null || hb.isErroneous())
        reportBoundError(uv, BoundErrorKind.BAD_UPPER);
}
 
Example #18
Source File: Types.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
    if (s.hasTag(WILDCARD)) {
        // FIXME, this might be leftovers from before capture conversion
        return false;
    }

    if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) {
        return true;
    }

    t.addBound(InferenceBound.EQ, s, Types.this);

    return true;
}
 
Example #19
Source File: Infer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
IncorporationBinaryOpKind opFor(InferenceBound boundKind) {
    switch (boundKind) {
        case EQ:
            return IncorporationBinaryOpKind.ADD_EQ_BOUND;
        case LOWER:
            return IncorporationBinaryOpKind.ADD_LOWER_BOUND;
        case UPPER:
            return IncorporationBinaryOpKind.ADD_UPPER_BOUND;
        default:
            Assert.error("Can't get here!");
            return null;
    }
}
 
Example #20
Source File: Infer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) {
    Infer infer = inferenceContext.infer();
    for (Type b1 : uv.getBounds(InferenceBound.EQ)) {
        for (Type b2 : uv.getBounds(InferenceBound.EQ)) {
            if (b1 != b2) {
                isSameType(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), infer);
            }
        }
    }
}
 
Example #21
Source File: Types.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
    //todo: test against origin needed? or replace with substitution?
    if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) {
        return true;
    } else if (s.hasTag(BOT)) {
        //if 's' is 'null' there's no instantiated type U for which
        //U <: s (but 'null' itself, which is not a valid type)
        return false;
    }

    t.addBound(InferenceBound.UPPER, s, Types.this);
    return true;
}
 
Example #22
Source File: Types.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
    if (s.hasTag(WILDCARD)) {
        // FIXME, this might be leftovers from before capture conversion
        return false;
    }

    if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) {
        return true;
    }

    t.addBound(InferenceBound.EQ, s, Types.this);

    return true;
}
 
Example #23
Source File: Infer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) {
    Infer infer = inferenceContext.infer();
    for (Type b1 : uv.getBounds(InferenceBound.UPPER)) {
        for (Type b2 : uv.getBounds(InferenceBound.LOWER)) {
            isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn , infer);
        }
    }
}
 
Example #24
Source File: Infer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Debugging: dot representation of this graph
 */
String toDot() {
    StringBuilder buf = new StringBuilder();
    for (Type t : inferenceContext.undetvars) {
        UndetVar uv = (UndetVar)t;
        buf.append(String.format("var %s - upper bounds = %s, lower bounds = %s, eq bounds = %s\\n",
                uv.qtype, uv.getBounds(InferenceBound.UPPER), uv.getBounds(InferenceBound.LOWER),
                uv.getBounds(InferenceBound.EQ)));
    }
    return GraphUtils.toDot(nodes, "inferenceGraph" + hashCode(), buf.toString());
}
 
Example #25
Source File: Types.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
    if (s.hasTag(WILDCARD)) {
        // FIXME, this might be leftovers from before capture conversion
        return false;
    }

    if (t == s || t.qtype == s || s.hasTag(ERROR) || s.hasTag(UNKNOWN)) {
        return true;
    }

    t.addBound(InferenceBound.EQ, s, Types.this);

    return true;
}
 
Example #26
Source File: Infer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the graph nodes. First a simple node is created for every inference
 * variables to be solved. Then Tarjan is used to found all connected components
 * in the graph. For each component containing more than one node, a super node is
 * created, effectively replacing the original cyclic nodes.
 */
void initNodes(Map<Type, Set<Type>> stuckDeps) {
    //add nodes
    nodes = new ArrayList<Node>();
    for (Type t : inferenceContext.restvars()) {
        nodes.add(new Node(t));
    }
    //add dependencies
    for (Node n_i : nodes) {
        Type i = n_i.data.first();
        Set<Type> optDepsByNode = stuckDeps.get(i);
        for (Node n_j : nodes) {
            Type j = n_j.data.first();
            UndetVar uv_i = (UndetVar)inferenceContext.asFree(i);
            if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) {
                //update i's bound dependencies
                n_i.addDependency(DependencyKind.BOUND, n_j);
            }
            if (optDepsByNode != null && optDepsByNode.contains(j)) {
                //update i's stuck dependencies
                n_i.addDependency(DependencyKind.STUCK, n_j);
            }
        }
    }
    //merge cyclic nodes
    ArrayList<Node> acyclicNodes = new ArrayList<Node>();
    for (List<? extends Node> conSubGraph : GraphUtils.tarjan(nodes)) {
        if (conSubGraph.length() > 1) {
            Node root = conSubGraph.head;
            root.mergeWith(conSubGraph.tail);
            for (Node n : conSubGraph) {
                notifyUpdate(n, root);
            }
        }
        acyclicNodes.add(conSubGraph.head);
    }
    nodes = acyclicNodes;
}
 
Example #27
Source File: Infer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restore the state of this inference context to the previous known checkpoint
 */
void rollback(List<Type> saved_undet) {
     Assert.check(saved_undet != null && saved_undet.length() == undetvars.length());
    //restore bounds (note: we need to preserve the old instances)
    for (Type t : undetvars) {
        UndetVar uv = (UndetVar)t;
        UndetVar uv_saved = (UndetVar)saved_undet.head;
        for (InferenceBound ib : InferenceBound.values()) {
            uv.setBounds(ib, uv_saved.getBounds(ib));
        }
        uv.inst = uv_saved.inst;
        saved_undet = saved_undet.tail;
    }
}
 
Example #28
Source File: Infer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) {
    Infer infer = inferenceContext.infer();
    for (Type b1 : uv.getBounds(InferenceBound.UPPER)) {
        for (Type b2 : uv.getBounds(InferenceBound.EQ)) {
            isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer);
        }
    }
}
 
Example #29
Source File: Infer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
IncorporationBinaryOpKind opFor(InferenceBound boundKind) {
    switch (boundKind) {
        case EQ:
            return IncorporationBinaryOpKind.ADD_EQ_BOUND;
        case LOWER:
            return IncorporationBinaryOpKind.ADD_LOWER_BOUND;
        case UPPER:
            return IncorporationBinaryOpKind.ADD_UPPER_BOUND;
        default:
            Assert.error("Can't get here!");
            return null;
    }
}
 
Example #30
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Debugging: dot representation of this graph
 */
String toDot() {
    StringBuilder buf = new StringBuilder();
    for (Type t : inferenceContext.undetvars) {
        UndetVar uv = (UndetVar)t;
        buf.append(String.format("var %s - upper bounds = %s, lower bounds = %s, eq bounds = %s\\n",
                uv.qtype, uv.getBounds(InferenceBound.UPPER), uv.getBounds(InferenceBound.LOWER),
                uv.getBounds(InferenceBound.EQ)));
    }
    return GraphUtils.toDot(nodes, "inferenceGraph" + hashCode(), buf.toString());
}