Interface Assumption
public interface Assumption
An assumption is a global boolean flag that starts with the value true (i.e., the assumption is
valid) and can subsequently be invalidated (using
invalidate()). Once
invalidated, an assumption can never get valid again. Assumptions can be created using the
TruffleRuntime.createAssumption() or the TruffleRuntime.createAssumption(String)
method. The Truffle compiler has special knowledge of this class in order to produce efficient
machine code for checking an assumption in case the assumption object is a compile time constant.
Therefore, assumptions should be stored in final fields in Truffle nodes.
All instances of classes implementing Assumption must be held in final fields for
compiler optimizations to take effect.
Do not manually subclass the Assumption interface. This class is only intended to be
subclassed by Truffle runtime implementations to avoid polymorphism in performance sensitive
methods.
- Since:
- 0.8 or earlier
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AssumptionAn assumption that is always valid and fails with anUnsupportedOperationExceptionif invalidated.static final AssumptionAn assumption that is never valid. -
Method Summary
Modifier and TypeMethodDescriptionvoidcheck()Checks that this assumption is still valid.static Assumptioncreate()Creates a new assumption with a name.static AssumptionCreates a new assumption with a name.getName()A name for the assumption that is used for debug output.voidInvalidates this assumption.default voidinvalidate(String message) Invalidates this assumption.booleanisValid()Checks whether the assumption is still valid.static booleanisValidAssumption(Assumption assumption) Checks whether an assumption is notnulland valid.static booleanisValidAssumption(Assumption[] assumptions) Checks whether all assumptions in an array are notnulland valid.
-
Field Details
-
ALWAYS_VALID
An assumption that is always valid and fails with anUnsupportedOperationExceptionif invalidated.- Since:
- 22.1
-
NEVER_VALID
-
-
Method Details
-
check
Checks that this assumption is still valid. The method throws an exception, if this is no longer the case. This method is preferred over theisValid()method when writing guest language interpreter code. The catch block should perform a node rewrite (seeNode.replace(Node)) with a node that no longer relies on the assumption.- Throws:
InvalidAssumptionException- If the assumption is no longer valid.- Since:
- 0.8 or earlier
-
isValid
boolean isValid()Checks whether the assumption is still valid.- Returns:
- a boolean value indicating the validity of the assumption
- Since:
- 0.8 or earlier
-
invalidate
void invalidate()Invalidates this assumption. Performs no operation, if the assumption is already invalid.- Since:
- 0.8 or earlier
-
invalidate
Invalidates this assumption. Performs no operation, if the assumption is already invalid.- Parameters:
message- a message stating the reason of the invalidation- Since:
- 0.33
-
getName
String getName()A name for the assumption that is used for debug output.- Returns:
- the name of the assumption
- Since:
- 0.8 or earlier
-
isValidAssumption
Checks whether an assumption is notnulland valid.- Since:
- 19.0
-
isValidAssumption
Checks whether all assumptions in an array are notnulland valid. Returnsfalseif the assumptions array itself isnull. This method is designed for compilation. Note that the provided assumptions array must be a compilation final array withdimensionsset to one.- Since:
- 19.0
-
create
Creates a new assumption with a name. Shortcut forTruffleRuntime.createAssumption().- Since:
- 22.1
-
create
Creates a new assumption with a name. Shortcut forTruffleRuntime.createAssumption(String).- Since:
- 22.1
-