Assumption
public interface AssumptionAn assumption is a global boolean flag that starts with the value true (i.e., the assumption is valid) and can subsequently be invalidated (using Assumption.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.
Fields2
Assumption ALWAYS_VALID
ALWAYS_VALID
since 22.1Assumption ALWAYS_VALIDAn assumption that is always valid and fails with an UnsupportedOperationException if invalidated.
Assumption NEVER_VALID
Methods9
void check()
check
since 0.8 or earliervoid check() throws InvalidAssumptionExceptionChecks that this assumption is still valid. The method throws an exception, if this is no longer the case. This method is preferred over the isValid() method when writing guest language interpreter code. The catch block should perform a node rewrite (see Node.replace(Node)) with a node that no longer relies on the assumption.
Throws
InvalidAssumptionException- If the assumption is no longer valid.
boolean isValid()
isValid
since 0.8 or earlierboolean isValid()Checks whether the assumption is still valid.
Returns
boolean- a boolean value indicating the validity of the assumption
void invalidate()
invalidate
since 0.8 or earliervoid invalidate()Invalidates this assumption. Performs no operation, if the assumption is already invalid.
void invalidate(String)
invalidate
defaultsince 0.33default void invalidate(String message)Invalidates this assumption. Performs no operation, if the assumption is already invalid.
Parameters
messageString- a message stating the reason of the invalidation
String getName()
static boolean isValidAssumption(Assumption)
isValidAssumption
staticsince 19.0static boolean isValidAssumption(Assumption assumption)Checks whether an assumption is not null and valid.
Parameters
assumptionAssumption- No description.
Returns
boolean- No description.
static boolean isValidAssumption(Assumption[])
isValidAssumption
staticsince 19.0static boolean isValidAssumption(Assumption[] assumptions)Checks whether all assumptions in an array are not null and valid. Returns false if the assumptions array itself is null. This method is designed for compilation. Note that the provided assumptions array must be a compilation final array with dimensions set to one.
Parameters
assumptionsAssumption[]- No description.
Returns
boolean- No description.
static Assumption create()
create
staticsince 22.1static Assumption create()Creates a new assumption with a name. Shortcut for TruffleRuntime.createAssumption().
Returns
Assumption- No description.
static Assumption create(String)
create
staticsince 22.1static Assumption create(String name)Creates a new assumption with a name. Shortcut for TruffleRuntime.createAssumption(String).
Parameters
nameString- No description.
Returns
Assumption- No description.