Interface Assumption

All Known Implementing Classes:
AbstractAssumption, AlwaysValidAssumption, NeverValidAssumption, UnionAssumption

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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Checks that this assumption is still valid.
    A name for the assumption that is used for debug output.
    void
    Invalidates this assumption.
    boolean
    Checks whether the assumption is still valid.
  • Method Details

    • check

      void check() throws InvalidAssumptionException
      Checks 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.
    • isValid

      boolean isValid()
      Checks whether the assumption is still valid.
      Returns:
      a boolean value indicating the validity of the assumption
    • invalidate

      void invalidate()
      Invalidates this assumption. Performs no operation, if the assumption is already invalid.
    • getName

      String getName()
      A name for the assumption that is used for debug output.
      Returns:
      the name of the assumption