@informalsystems/quint
Version:
Core tool for the Quint specification language
116 lines (115 loc) • 5.03 kB
TypeScript
/**
* An evaluator for Quint in Node TS runtime.
*
* Testing and simulation are heavily based on the original `compilerImpl.ts` file written by Igor Konnov.
*
* @author Igor Konnov, Gabriela Moreira
*
* @module
*/
import { Either } from '@sweet-monads/either';
import { QuintEx } from '../../ir/quintIr';
import { LookupDefinition, LookupTable } from '../../names/base';
import { QuintError } from '../../quintError';
import { TraceRecorder } from '../trace';
import { Trace } from './trace';
import { RuntimeValue } from './runtimeValue';
import { Context } from './Context';
import { TestResult } from '../testing';
import { Rng } from '../../rng';
import { Outcome } from '../../simulation';
import { TraceHook } from '../../cliReporting';
/**
* An evaluator for Quint in Node TS runtime.
*/
export declare class Evaluator {
ctx: Context;
recorder: TraceRecorder;
private rng;
private builder;
/**
* Constructs an Evaluator that can be re-used across evaluations.
*
* @param table - The lookup table for definitions.
* @param recorder - The trace recorder to log evaluation traces.
* @param rng - The random number generator to use for evaluation.
* @param storeMetadata - Optional, whether to store `actionTaken` and `nondetPicks`. Default is false.
*/
constructor(table: LookupTable, recorder: TraceRecorder, rng: Rng, storeMetadata?: boolean);
/**
* Get the current trace from the context
*/
get trace(): Trace;
/**
* Update the lookup table, if the same table is used for multiple evaluations but there are new definitions.
*
* @param table
*/
updateTable(table: LookupTable): void;
updateState(state: QuintEx): void;
/**
* Shift the context to the next state. That is, updated variables in the next state are moved to the current state,
* and the trace is extended.
*/
shift(): void;
/**
* Shift the context to the next state. That is, updated variables in the next state are moved to the current state,
* and the trace is extended.
*
* @returns a boolean indicating if there were any next variables that got
* shifted, and names of the variables that don't have values in the new
* state (empty list if no shifting happened).
*/
shiftAndCheck(): [boolean, string[]];
/**
* Evaluate a Quint expression.
*
* @param expr
* @returns the result of the evaluation, if successful, or an error if the evaluation failed.
*/
evaluate(expr: QuintEx): Either<QuintError, QuintEx>;
/**
* Reset the evaluator to its initial state (in terms of trace and variables)
*/
reset(): void;
/**
* Simulates the execution of an initial expression followed by a series of step expressions,
* while checking an invariant expression at each step. The simulation is run multiple times,
* up to a specified number of runs, and each run is executed for a specified number of steps.
* The simulation stops if a specified number of traces with errors are found.
*
* @param init - The initial expression to evaluate.
* @param step - The step expression to evaluate repeatedly.
* @param inv - The invariant expression to check after each step.
* @param nruns - The number of simulation runs to perform.
* @param nsteps - The number of steps to perform in each simulation run.
* @param ntraces - The number of error traces to collect before stopping the simulation.
* @param onTrace - A callback function to be called with trace information for each simulation run.
* @returns a simulation outcome with all data to report
*/
simulate(init: QuintEx, step: QuintEx, inv: QuintEx, witnesses: QuintEx[], nruns: number, nsteps: number, ntraces: number, onTrace?: TraceHook): Outcome;
/**
* Run a specified test definition a given number of times, and report the result.
*
* @param testDef - The definition of the test to be run.
* @param maxSamples - The maximum number of times to run the test.
* @param onTrace - A callback function to be called with trace information for each test run.
* @returns The result of the test, including its name, status, any errors, the seed used, frames,
and the number of samples run.
*/
test(testDef: LookupDefinition, maxSamples: number, index: number, onTrace: TraceHook): TestResult;
/**
* Variable names in context
* @returns the names of all variables in the current context.
*/
varNames(): string[];
/**
* Special case of `evaluate` where the expression is a call to a simulation.
*
* @param expr
* @returns the result of the simulation, or an error if the simulation cannot be completed.
*/
private evaluateSimulation;
}
export declare function isTrue(value: Either<QuintError, RuntimeValue>): boolean;
export declare function isFalse(value: Either<QuintError, RuntimeValue>): boolean;