Class BoundSet
- All Implemented Interfaces:
ReductionResult
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.checkerframework.framework.util.typeinference8.constraint.ReductionResult
ReductionResult.ReductionResultPair -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanIf true, then type argument inference failed because an annotated type could not be inferred.The error message to report to users.static final intMax number of incorporation loops.Fields inherited from interface org.checkerframework.framework.util.typeinference8.constraint.ReductionResult
UNCHECKED_CONVERSION -
Constructor Summary
ConstructorsConstructorDescriptionCopy constructor.BoundSet(Java8InferenceContext context) Creates a bound set. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCapture(CaptureBound capture) Addscaptureto this bound set.voidaddFalse()Adds the false bound to this bound set.booleanReturns true if the bound set contains a bound of the formG<..., ai, ...> = capture(G<...>)for any variable inas.booleanReturns true if this bound set contains false.Returns the dependencies between variables.getDependencies(Collection<Variable> additionalVars) Returns the dependencies between all variables in this bound set and inadditionalVars.Returns a list of all variables in this bound set that are instantiated.getInstantiationsInAlphas(Collection<Variable> alphas) Returns a list of variables inalphasthat are instantiated.booleanReturns true if unchecked conversion was necessary to reduce and incorporate this bound set, andrecordUncheckedConversionFor(com.sun.source.tree.ExpressionTree)has not yet recorded which expression needs that unchecked conversion.voidincorporateToFixedPoint(BoundSet newBounds) IncorporatesnewBoundsinto this bound set.static BoundSetinitialBounds(Theta theta, Java8InferenceContext context) Creates a new bound set for the variables in theta.booleanMergesnewSetinto this bound set.voidIncorporates this bound set into itself until it reaches a fixed point.voidrecordUncheckedConversionFor(ExpressionTree expression) If this bound set has pending unchecked conversion, records thatexpressionneeds unchecked conversion.voidremoveCaptures(Set<Variable> as) Removes any capture bound that contains any variable inas.resolve()Resolves all inference variables contained in any bound.voidrestore()Restores the bounds to the last saved state.voidSaves the current state of the variables so they can be restored if the first attempt at resolution fails.voidsetPendingUncheckedConversion(boolean pendingUncheckedConversion) Sets whether this bound set has pending unchecked conversion: unchecked conversion that was necessary to reduce and incorporate this bound set, for whichrecordUncheckedConversionFor(com.sun.source.tree.ExpressionTree)has not yet recorded which expression needs it.toString()
-
Field Details
-
MAX_INCORPORATION_STEPS
public static final int MAX_INCORPORATION_STEPSMax number of incorporation loops. Uses the same constant asInfer.MAX_INCORPORATION_STEPS.- See Also:
-
annoInferenceFailed
public boolean annoInferenceFailedIf true, then type argument inference failed because an annotated type could not be inferred. -
errorMsg
The error message to report to users.
-
-
Constructor Details
-
BoundSet
Creates a bound set.- Parameters:
context- the context
-
BoundSet
Copy constructor.- Parameters:
toCopy- bound set to copy
-
-
Method Details
-
saveBounds
public void saveBounds()Saves the current state of the variables so they can be restored if the first attempt at resolution fails. -
restore
public void restore()Restores the bounds to the last saved state. This method is called if the first attempt at resolution fails. -
initialBounds
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 variablecontext- inference context- Returns:
- initial bounds
-
merge
MergesnewSetinto 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, andrecordUncheckedConversionFor(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 whichrecordUncheckedConversionFor(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
If this bound set has pending unchecked conversion, records thatexpressionneeds unchecked conversion. That is, ifhasPendingUncheckedConversion()is true, addsexpressiontoJava8InferenceContext.needUncheckedConversionand setshasPendingUncheckedConversion()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). SettinghasPendingUncheckedConversion()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
Addscaptureto this bound set.- Parameters:
capture- a capture bound
-
containsCapture
Returns true if the bound set contains a bound of the formG<..., ai, ...> = capture(G<...>)for any variable inas.- 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 inas
-
getInstantiationsInAlphas
Returns a list of variables inalphasthat are instantiated.- Parameters:
alphas- a list of variables- Returns:
- a list of variables in
alphasthat are instantiated
-
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
Resolves all inference variables contained in any bound.- Returns:
- a list of resolved variables in this bound set
-
getDependencies
Returns the dependencies between variables. This method has the same side effect on this bound set asgetDependencies(Collection).- Returns:
- the dependencies between variables
-
getDependencies
Returns the dependencies between all variables in this bound set and inadditionalVars. TheadditionalVarsare 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
Thetacreated 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 byResolution; 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
IncorporatesnewBoundsinto this bound 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 bound 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 withinMAX_INCORPORATION_STEPSsteps
-
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 aBoundSetthat can be passed toincorporateToFixedPoint(org.checkerframework.framework.util.typeinference8.bound.BoundSet). -
removeCaptures
Removes any capture bound that contains any variable inas.- Parameters:
as- a set of variables
-
toString
-