java.lang.Object
org.checkerframework.framework.util.typeinference8.bound.BoundSet
All Implemented Interfaces:
ReductionResult

public class BoundSet extends Object implements ReductionResult
Manages a set of bounds. Bounds are stored in the variable to which they apply, except for capture bounds which are stored in this class.
  • Field Details

    • MAX_INCORPORATION_STEPS

      public static final int MAX_INCORPORATION_STEPS
      Max number of incorporation loops. Use same constant as Infer.MAX_INCORPORATION_STEPS
      See Also:
    • annoInferenceFailed

      public boolean annoInferenceFailed
      If true, then type argument inference failed because an annotated type could not be inferred.
    • errorMsg

      public String errorMsg
      The error message to report to users.
  • Constructor Details

    • BoundSet

      public BoundSet(Java8InferenceContext context)
      Creates a bound set.
      Parameters:
      context - the context
    • BoundSet

      public BoundSet(BoundSet toCopy)
      Copy constructor.
      Parameters:
      toCopy - bound set to copy
  • Method Details

    • saveBounds

      public void saveBounds()
      Save the current state of the variables so they can be restored if the first attempt at resolution fails.
    • restore

      public void restore()
      Restore the bounds to the last saved state. This method is called if the first attempt at resolution fails.
    • initialBounds

      public static BoundSet initialBounds(Theta theta, Java8InferenceContext context)
      Creates a new bound set for the variables in theta. (The initial bounds for the variables were added to the variables when theta was created.)
      Parameters:
      theta - a Map from type variable to inference variable
      context - inference context
      Returns:
      initial bounds
    • merge

      public boolean merge(BoundSet newSet)
      Merges newSet into this bound set.
      Parameters:
      newSet - bound set to merge
      Returns:
      true if the merge changed this bound set
    • addFalse

      public void addFalse()
      Adds the false bound to this bound set.
    • containsFalse

      public boolean containsFalse()
      Returns true if this bound set contains false.
      Returns:
      true if this bound set contains false
    • hasPendingUncheckedConversion

      public boolean hasPendingUncheckedConversion()
      Returns true if unchecked conversion was necessary to reduce and incorporate this bound set, and recordUncheckedConversionFor(com.sun.source.tree.ExpressionTree) has not yet recorded which expression needs that unchecked conversion.
      Returns:
      true if this bound set has pending unchecked conversion
    • setPendingUncheckedConversion

      public void setPendingUncheckedConversion(boolean pendingUncheckedConversion)
      Sets whether this bound set has pending unchecked conversion: unchecked conversion that was necessary to reduce and incorporate this bound set, for which recordUncheckedConversionFor(com.sun.source.tree.ExpressionTree) has not yet recorded which expression needs it.
      Parameters:
      pendingUncheckedConversion - true if this bound set has pending unchecked conversion
    • recordUncheckedConversionFor

      public void recordUncheckedConversionFor(ExpressionTree expression)
      If this bound set has pending unchecked conversion, records that expression needs unchecked conversion. That is, if hasPendingUncheckedConversion() is true, adds expression to Java8InferenceContext.needUncheckedConversion and sets hasPendingUncheckedConversion() to false; otherwise, does nothing.

      The caller passes the expression whose own arguments gave rise to the pending unchecked conversion; see Java8InferenceContext.needUncheckedConversion. The return type of that expression's invocation type is erased (JLS 15.12.2.6). Setting hasPendingUncheckedConversion() to false prevents an enclosing expression from also being recorded as needing the same unchecked conversion.

      Parameters:
      expression - a method invocation, class instance creation, or method reference
      See Also:
    • addCapture

      public void addCapture(CaptureBound capture)
      Adds capture to this bound set.
      Parameters:
      capture - a capture bound
    • containsCapture

      public boolean containsCapture(Collection<Variable> as)
      Does the bound set contain a bound of the form G<..., ai, ...> = capture(G<...>) for any variable in as?
      Parameters:
      as - a collection of variables
      Returns:
      true if the bound set contains a bound of the form G<..., ai, ...> = capture(G<...>) for any variable in as
    • getInstantiationsInAlphas

      public List<Variable> getInstantiationsInAlphas(Collection<Variable> alphas)
      Returns a list of variables in alphas that are instantiated.
      Parameters:
      alphas - a list of variables
      Returns:
      a list of variables in alphas that are instantiated
    • getInstantiatedVariables

      public List<Variable> getInstantiatedVariables()
      Returns a list of all variables in this bound set that are instantiated.
      Returns:
      a list of all variables in this bound set that are instantiated
    • resolve

      public List<Variable> resolve()
      Resolve all inference variables mentioned in any bound.
      Returns:
      a list of resolved variables in this bounds set
    • getDependencies

      public Dependencies getDependencies()
      Returns the dependencies between variables. This method has the same side effect on this bound set as getDependencies(Collection).
      Returns:
      the dependencies between variables
    • getDependencies

      public Dependencies getDependencies(Collection<Variable> additionalVars)
      Returns the dependencies between all variables in this bound set and in additionalVars. The additionalVars are used only to compute the result; they are not added to this bound set.

      As a side effect, this method adds to this bound set every variable of every Theta created so far in this inference context. That is how variables created by a nested inference problem become part of this bound set and therefore get resolved by Resolution; without that side effect, those variables would never be instantiated.

      Parameters:
      additionalVars - variables to include in the dependency computation, in addition to the variables of this bound set
      Returns:
      the dependencies between all variables in this bound set and in additionalVars
    • incorporateToFixedPoint

      public void incorporateToFixedPoint(BoundSet newBounds)
      Incorporates newBounds into this bounds set.

      Incorporation creates new constraints that are then reduced to a bound set which is further incorporated into this bound set. Incorporation terminates when the bounds set has reached a fixed point. JLS 18.3 defines this fixed point and further explains incorporation.

      Parameters:
      newBounds - bounds to incorporate
      Throws:
      BugInCF - if incorporation does not reach a fixed point within MAX_INCORPORATION_STEPS steps
    • reachFixedPoint

      public void reachFixedPoint()
      Incorporates this bound set into itself until it reaches a fixed point. Use this method after adding bounds directly to the variables of this bound set, rather than via a BoundSet that can be passed to incorporateToFixedPoint(org.checkerframework.framework.util.typeinference8.bound.BoundSet).
    • removeCaptures

      public void removeCaptures(Set<Variable> as)
      Remove any capture bound that mentions any variable in as.
      Parameters:
      as - a set of variables
    • toString

      public String toString()
      Overrides:
      toString in class Object