@informalsystems/quint
Version:
Core tool for the Quint specification language
105 lines (104 loc) • 3.73 kB
TypeScript
/**
* A storage to keep track of Quint state variables in the current and next state.
*
* @author Gabriela Moreira
*
* @module
*/
import { Either } from '@sweet-monads/either';
import { QuintError } from '../../quintError';
import { RuntimeValue } from './runtimeValue';
import { Map as ImmutableMap } from 'immutable';
import { CachedValue, Register } from './Context';
/**
* A named pointer to a value, so we can use the same reference in multiple places, and just update the value.
* The name is used for error messages.
*/
export interface NamedRegister extends Register {
name: string;
}
/**
* A snapshot of the VarStorage at a given point in time. Stores only information that is needed to backtrack.
*/
interface Snapshot {
nextVars: ImmutableMap<string, NamedRegister>;
nondetPicks: Map<string, RuntimeValue | undefined>;
actionTaken: string | undefined;
}
/**
* Initializes the register value for a given variable name.
*
* @param name - The name of the variable to initialize, to be used in error messages
* @returns a QuintError indicating the variable is not set
*/
export declare function initialRegisterValue(name: string): Either<QuintError, RuntimeValue>;
/**
* A storage to keep track of Quint state variables in the current and next state.
*/
export declare class VarStorage {
/**
* An immutable map with registers for the current state variables.
*/
vars: ImmutableMap<string, NamedRegister>;
/**
* An immutable map with registers for the next state variables.
*/
nextVars: ImmutableMap<string, NamedRegister>;
/**
* Non-deterministic picks and their values for the current step.
*/
nondetPicks: Map<string, RuntimeValue | undefined>;
/**
* The action taken in the current step.
*/
actionTaken: string | undefined;
/**
* Cached values that need to be cleared when shifting.
*/
cachesToClear: CachedValue[];
/**
* Indicates whether to store metadata.
*/
private storeMetadata;
/**
* Constructs a new VarStorage instance.
*
* @param storeMetadata - Indicates whether to store metadata.
* @param nondetPicks - Non-deterministic picks and their values for the current step. Should be
the one constructed in the builder.
*/
constructor(storeMetadata: boolean, nondetPicks: Map<string, RuntimeValue | undefined>);
/**
* Shifts the current state variables to the next state variables.
* This method updates the current state variable registers with the values
* from the next state variable registers, initializes the next state variable
* registers, and clears cached values.
*/
shiftVars(): void;
/**
* Converts the current state variables and metadata into a RuntimeValue record.
*
* @returns A RuntimeValue representing the current state variables and metadata.
*/
asRecord(): RuntimeValue;
fromRecord(record: RuntimeValue): void;
/**
* Resets the current and next state variable registers to their initial values.
* This method sets the value of each register in both the current and next state
* variable maps to an undefined (error) value.
*/
reset(): void;
/**
* Creates a snapshot of the current state of the VarStorage, with the relevant information to backtrack.
* @returns A snapshot of the current state of the VarStorage.
*/
snapshot(): Snapshot;
/**
* Recovers the state of the VarStorage from a snapshot.
*
* @param snapshot - the snapshot to recover the state from
*/
recoverSnapshot(snapshot: Snapshot): void;
private clearCaches;
}
export {};