Class TypeInferenceAnalyzer


  • public class TypeInferenceAnalyzer
    extends Object
    Dataflow analyzer that infers types and nullability for SSA values, narrowing them at instanceof checks and null comparisons.
    • Constructor Detail

      • TypeInferenceAnalyzer

        public TypeInferenceAnalyzer​(IRMethod method)
        Creates an analyzer with no state computed; call analyze() to populate it.
        Parameters:
        method - SSA method to analyze
    • Method Detail

      • analyze

        public void analyze()
        Seeds parameter types, indexes instanceof checks and runs the dataflow to fixpoint.
      • getTypeState

        public TypeState getTypeState​(SSAValue value)
        Runs the analysis if needed and gets the inferred type state for a value.
        Parameters:
        value - the SSA value to query
        Returns:
        the inferred state, or TypeState.BOTTOM if the value was never seen
      • getInferredType

        public IRType getInferredType​(SSAValue value)
        Gets a single inferred type for a value, picking one when several are possible.
        Parameters:
        value - the SSA value to query
        Returns:
        the inferred type, or null when nothing was inferred
      • getNullability

        public Nullability getNullability​(SSAValue value)
        Gets the nullability state for a value.
        Parameters:
        value - the SSA value to query
        Returns:
        the inferred nullability
      • isDefinitelyNull

        public boolean isDefinitelyNull​(SSAValue value)
        Checks if a value is definitely null.
        Parameters:
        value - the SSA value to query
        Returns:
        true when the inferred nullability is null on every path
      • isDefinitelyNotNull

        public boolean isDefinitelyNotNull​(SSAValue value)
        Checks if a value is definitely not null.
        Parameters:
        value - the SSA value to query
        Returns:
        true when the inferred nullability rules out null
      • getPossibleTypes

        public TypeSet getPossibleTypes​(SSAValue value)
        Gets all possible types for a polymorphic value.
        Parameters:
        value - the SSA value to query
        Returns:
        the inferred type set
      • getTypeStateAtBlockEntry

        public TypeState getTypeStateAtBlockEntry​(IRBlock block,
                                                  SSAValue value)
        Gets the type state a value holds on entering a block.
        Parameters:
        block - the block whose entry state is read
        value - the SSA value to query
        Returns:
        the recorded entry state, or TypeState.BOTTOM if the block or value has none
      • getTypeStateAtBlockExit

        public TypeState getTypeStateAtBlockExit​(IRBlock block,
                                                 SSAValue value)
        Gets the type state a value holds on leaving a block.
        Parameters:
        block - the block whose exit state is read
        value - the SSA value to query
        Returns:
        the recorded exit state, or TypeState.BOTTOM if the block or value has none
      • getNullValues

        public Set<SSAValue> getNullValues()
        Runs the analysis if needed and collects the values proven null.
        Returns:
        the values whose inferred nullability is definitely null
      • getNonNullValues

        public Set<SSAValue> getNonNullValues()
        Runs the analysis if needed and collects the values proven non-null.
        Returns:
        the values whose inferred nullability is definitely not null
      • getAllTypeStates

        public Map<SSAValue,​TypeState> getAllTypeStates()
        Runs the analysis if needed and exposes every value's type state.
        Returns:
        an unmodifiable view of the value-to-type-state map
      • hasPreciseType

        public boolean hasPreciseType​(SSAValue value)
        Checks if a value has a precise (exact) type known.
        Parameters:
        value - the SSA value to query
        Returns:
        true when the inferred type set holds exactly one type