@runtimeverificationinc/tsk
Version:
TypeScript/JavaScript library for K Framework functionality
207 lines (206 loc) • 9.22 kB
TypeScript
import { KInner, Subst } from "../kast/inner";
import { KClaim, KDefinition, KRule } from "../kast/outer";
/**
* Represent a symbolic program state, obtained and manipulated using symbolic execution.
*
* Contains the data:
* - `config`: the _configuration_ (structural component of the state, potentially containing free variables)
* - `constraints`: conditions which limit/constraint the free variables from the `config`
*/
export declare class CTerm {
readonly config: KInner;
readonly constraints: readonly KInner[];
constructor(config: KInner, constraints?: Iterable<KInner>);
/**
* Interpret a given `KInner` as a `CTerm` by splitting the `config` and `constraints` (see `CTerm.kast`).
*/
static fromKast(kast: KInner): CTerm;
/**
* Deserialize a `CTerm` from its dictionary representation.
*/
static fromDict(dct: Record<string, any>): CTerm;
/**
* Construct a `CTerm` representing all possible states.
*/
static top(): CTerm;
/**
* Construct a `CTerm` representing no possible states.
*/
static bottom(): CTerm;
private static _checkConfig;
private static _normalizeConstraints;
/**
* Check if a given `CTerm` is trivially empty.
*/
get isBottom(): boolean;
private static _constraintSortKey;
/**
* Return an iterator with the head being the `config` and the tail being the `constraints`.
*/
[Symbol.iterator](): Iterator<KInner>;
/**
* Serialize a `CTerm` to dictionary representation.
*/
toDict(): Record<string, any>;
/**
* Return the unstructured bare `KInner` representation of a `CTerm` (see `CTerm.fromKast`).
*/
get kast(): KInner;
/**
* Return the unstructured bare `KInner` representation of the constraints.
*/
get constraint(): KInner;
/**
* Return the set of free variable names contained in this `CTerm`.
*/
get freeVars(): Set<string>;
/**
* Unique hash representing the contents of this `CTerm`.
*/
get hash(): string;
/**
* Return key-value store of the contents of each cell in the `config`.
*/
get cells(): Subst;
/**
* Access the contents of a named cell in the `config`, die on failure.
*/
cell(cell: string): KInner;
/**
* Access the contents of a named cell in the `config`, return `null` on failure.
*/
tryCell(cell: string): KInner | null;
/**
* Find `Subst` instantiating this `CTerm` to the other, return `null` if no such `Subst` exists.
*/
match(cterm: CTerm): Subst | null;
/**
* Find `CSubst` instantiating this `CTerm` to the other, return `null` if no such `CSubst` exists.
*/
matchWithConstraint(cterm: CTerm): CSubst | null;
private static _mlImpl;
/**
* Return a new `CTerm` with the additional constraints.
*/
addConstraint(newConstraint: KInner): CTerm;
/**
* Given two `CTerm` instances, find a more general `CTerm` which can instantiate to both.
*
* @param other - other `CTerm` to consider for finding a more general `CTerm` with this one.
* @param keepValues - do not discard information about abstracted variables in returned result.
* @param kdef - `KDefinition` to make analysis more precise.
* @returns A tuple `[cterm, csubst1, csubst2]` where
* - `cterm`: More general `CTerm` than either `this` or `other`.
* - `csubst1`: Constrained substitution to apply to `cterm` to obtain `this`.
* - `csubst2`: Constrained substitution to apply to `cterm` to obtain `other`.
*/
antiUnify(other: CTerm, keepValues?: boolean, kdef?: KDefinition): [CTerm, CSubst, CSubst];
/**
* Return a new `CTerm` with constraints over unbound variables removed.
*
* @param keepVars - List of variables to keep constraints for even if unbound in the `CTerm`.
* @returns A `CTerm` with the constraints over unbound variables removed.
*/
removeUselessConstraints(keepVars?: Iterable<string>): CTerm;
}
/**
* Return a generalized state over the two input states.
*
* @param state1 - State to generalize over, represented as bare `KInner`.
* @param state2 - State to generalize over, represented as bare `KInner`.
* @param kdef - `KDefinition` to make the analysis more precise.
* @returns A tuple `[state, subst1, subst2]` such that
* - `state`: A symbolic state represented as `KInner` which is more general than `state1` or `state2`.
* - `subst1`: A `Subst` which, when applied to `state`, recovers `state1`.
* - `subst2`: A `Subst` which, when applied to `state`, recovers `state2`.
*
* Note: Both `state1` and `state2` are expected to be bare configurations with no constraints attached.
*/
export declare function antiUnify(state1: KInner, state2: KInner, kdef?: KDefinition): [KInner, Subst, Subst];
/**
* Store information about instantiation of a symbolic state (`CTerm`) to a more specific one.
*
* Contains the data:
* - `subst`: assignment to apply to free variables in the state to achieve more specific one
* - `constraints`: additional constraints over the free variables of the original state and the `subst` to add to the new state
*/
export declare class CSubst {
readonly subst: Subst;
readonly constraints: readonly KInner[];
constructor(subst?: Subst, constraints?: Iterable<KInner>);
/**
* Return an iterator with the head being the `subst` and the tail being the `constraints`.
*/
[Symbol.iterator](): Iterator<Subst | KInner>;
/**
* Serialize `CSubst` to dictionary representation.
*/
toDict(): Record<string, any>;
/**
* Deserialize `CSubst` from a dictionary representation.
*/
static fromDict(dct: Record<string, any>): CSubst;
/**
* Extract from a boolean predicate a CSubst.
*/
static fromPred(pred: KInner): CSubst;
/**
* Return an ML predicate representing this substitution.
*/
pred(sortWith?: KDefinition, subst?: boolean, constraints?: boolean): KInner;
/**
* Return the set of constraints as a single flattened constraint using `mlAnd`.
*/
get constraint(): KInner;
/**
* Return this `CSubst` with an additional constraint added.
*/
addConstraint(constraint: KInner): CSubst;
/**
* Apply this `CSubst` to the given `CTerm` (instantiating the free variables, and adding the constraints).
*/
apply(cterm: CTerm): CTerm;
/**
* Overload for `CSubst.apply`.
*/
call(cterm: CTerm): CTerm;
}
/**
* Return a `KClaim` between the supplied initial and final states.
*
* @param claimId - Label to give the claim.
* @param initCterm - State to put on LHS of the rule (constraints interpreted as `requires` clause).
* @param finalCterm - State to put on RHS of the rule (constraints interpreted as `ensures` clause).
* @param keepVars - Variables to leave in the side-conditions even if not bound in the configuration.
* @returns A tuple `[claim, varMap]` where
* - `claim`: A `KClaim` with variable naming conventions applied so that it should be parseable by the K Frontend.
* - `varMap`: The variable renamings applied to make the claim parseable by the K Frontend
* (which can be undone to recover original variables).
*/
export declare function ctermBuildClaim(claimId: string, initCterm: CTerm, finalCterm: CTerm, keepVars?: Iterable<string>): [KClaim, Subst];
/**
* Return a `KRule` between the supplied initial and final states.
*
* @param ruleId - Label to give the rule.
* @param initCterm - State to put on LHS of the rule (constraints interpreted as `requires` clause).
* @param finalCterm - State to put on RHS of the rule (constraints interpreted as `ensures` clause).
* @param priority - Priority index to use for generated rules.
* @param keepVars - Variables to leave in the side-conditions even if not bound in the configuration.
* @param defuncWith - KDefinition to be able to defunctionalize LHS appropriately.
* @returns A tuple `[rule, varMap]` where
* - `rule`: A `KRule` with variable naming conventions applied so that it should be parseable by the K Frontend.
* - `varMap`: The variable renamings applied to make the rule parseable by the K Frontend
* (which can be undone to recover original variables).
*/
export declare function ctermBuildRule(ruleId: string, initCterm: CTerm, finalCterm: CTerm, priority?: number, keepVars?: Iterable<string>, defuncWith?: KDefinition): [KRule, Subst];
/**
* Given many `CTerm` instances, find a more general `CTerm` which can instantiate to all.
*
* @param cterms - `CTerm`s to consider for finding a more general `CTerm` with this one.
* @param keepValues - do not discard information about abstracted variables in returned result.
* @param kdef - `KDefinition` to make analysis more precise.
* @returns A tuple `[cterm, csubsts]` where
* - `cterm`: More general `CTerm` than any of the input `CTerm`s.
* - `csubsts`: List of `CSubst` which, when applied to `cterm`, yield the input `CTerm`s.
*/
export declare function ctermsAntiUnify(cterms: Iterable<CTerm>, keepValues?: boolean, kdef?: KDefinition): [CTerm, CSubst[]];