ProgramState encapsulates a concrete, non-symbolic state of a program, tracking global variables and intermediate object instances ("heap"). ObjectState and VariableState represent individual object and variable snapshots, respectively, with custom hashing for efficient full-state comparison and/or memoization.
The micro_svm.state module and ProgramState in particular describes a (partial) program's state.
The micro_svm.state module provides the fundamental data structures for representing and analyzing program states throughout the defect detection lifecycle. These structures serve as the foundation for:
- Path validation: Verifying whether a sequence of instructions produces the (un)desired target state
- State serialization: Persisting and restoring program states in JSON format
- Type consistency:
ObjectState.typemust be one of the container or structure type descriptors defined intypes.py(ArrayTypeInfo, SetTypeInfo, MapTypeInfo, TransformTypeInfo, or StructureTypeInfo) - State compatibility:
ObjectState.statemust be compatible with the declaredObjectState.type- e.g., array types expect list of primitive values, map types expect list of pairs, structure types expect dictionary states - Reference handling: Object IDs in
ProgramState.objectsandProgramState.expected_objectsare string identifiers that must match; "expected" object ID should be present in the "objects" pool - Global variable references: Global variable values can be either
null/0or an object ID string, never a direct object state description
Represents the complete state of a single object instance, including its type information and current field/container values.
- Fields:
id: str- Unique identifier for this object instance, typically a string representation of a pointer/reference valuestate: InitializerValueType- Current state value, which varies by type: list for arrays, list of pairs for maps, dictionary for structures, or a single value for primitivestype: ArrayTypeInfo | SetTypeInfo | MapTypeInfo | TransformTypeInfo | StructureTypeInfo- Type descriptor defining the structure, fields, and container properties of this object
ObjectState uses hash_str() function for computing hash values which implements simple Java-like hashing algorithm.
Represents the current value of a (global) variable in the program state, including its name and symbolic value.
- Fields:
name: str- Global variable namestate: ValueType- Current symbolic value, which can be a primitive (integer, boolean, string, etc.) or a reference to an object ID
VariableState uses hash_str() function for computing hash values.
Represents the complete program state, encompassing global variables, all instantiated objects, and target state expectations.
- Fields:
allow_object_reuse: bool- Flag controlling whether object instances can be reused across multiple locations (default:True)expected_objects: dict[str, ObjectState]- Dictionary mapping top-level object IDs to their expected target states (values reference instances inobjectspool)global_variables: dict[str, VariableState]- Dictionary mapping global variable names to their current symbolic valuesobjects: dict[str, ObjectState]- Dictionary mapping all instantiated object IDs to their current states
hash_str(s: str | object) -> int- Java-like string hashing function (basich = 31 * h + ord(c)for each character)
AI usage disclosure: this document was generated by a large language model, all text has been validated and edited by a human developer.