A detector that identifies read-only variables and fields.

These variables could typically be replaced with constants to optimize performance. Alternatively, identifying read-only variables may reveal issues where unused values are being replaced unintentionally.

fun calculateFinalPrice(price: Int): Int {
  // Warning: the developer uses a read-only variable that could be a constant
  let DISCOUNT_AMOUNT: Int = 10;
  return price - DISCOUNT_AMOUNT;
}

Use instead:

const DISCOUNT_AMOUNT: Int = 10;

fun calculateFinalPrice(price: Int): Int {
  // OK: Fixed after the analyzer highlighted this warning
  return price - DISCOUNT_AMOUNT;
}

Hierarchy (view full)

Constructors

Properties

Accessors

  • get id(): string
  • Gets the short identifier of the detector, used in analyzer warnings.

    Returns string

    The unique identifier of the detector.

  • get shareImportedWarnings(): WarningsBehavior
  • Defines the behavior of warnings generated by this detector when working with multiple projects within a single Tact configuration.

    Here are the available options:

    1. "union" Leave this value if you don't care about warnings generated in other projects.
    2. "intersect" If the warning is generated for some source location of the imported file, it should be generated by each of the projects. Example: Constants from an imported file should not be reported iff they are unused in all the projects, so you need "intersect".

    Returns WarningsBehavior

  • get usesSouffle(): boolean
  • Checks whether this detector needs the Soufflé binary to be executed.

    Returns boolean

Methods

  • Collects facts based on the IR to populate the Souffle program.

    Parameters

    • cu: CompilationUnit

      The compilation unit containing the CFGs and AST information.

    • ctx: SouffleContext<SrcInfo>

      The Souffle program to which the facts are added.

    Returns void

  • Adds declarations to the Souffle program to represent the properties of variables.

    Parameters

    • ctx: SouffleContext<SrcInfo>

      The Souffle program where the relations are to be added.

    Returns void

  • Creates a Soufflé context with unique name.

    Parameters

    • cu: CompilationUnit
    • docstring: undefined | string | string[] = ...

      A comment introduced on the top of the generated program if ctx.config.souffleVerbose is set.

      It should be used to avoid name clashes in the Soufflé directory when working with multiple projects.

    Returns SouffleContext<SrcInfo>