Execution, Recording & Lowering

Architectura provides four execution and backend consumers alongside archsem-ir:

  1. archsem-ref — Independent bounded concrete reference oracle
  2. archsem-symex — Self-contained bounded symbolic & concolic execution and proof obligations
  3. archsem-record — Action-stream recorder (IrEmitter → serializable RecordedInstruction)
  4. archsem-llvm — Reference LLVM IR emitter and Register-SSA lowering backend

Concrete Reference Execution (archsem-ref)

archsem-ref is an independent concrete interpreter (#![forbid(unsafe_code)]) used as a common-mode-failure oracle against archsem-simplify, archsem-symex, and archsem-llvm. It deliberately maintains its own 1–512-bit BitVector evaluator rather than sharing evaluation code with archsem-simplify or archsem-symex.

  • Definedness: Raw shifts/rotates with count >= width, division/remainder by zero, INT_MIN / -1, and invalid lane indices return PartialOperation instead of panicking or inheriting host overflow.
  • Pluggable Environment (ReferenceEnvironment): Composes RegisterEnvironment, MemoryEnvironment, ChoiceEnvironment, FloatingPointEnvironment, and OpaqueEnvironment.
    • The stock ConcreteEnvironment stores exact (RegisterId, bits) cells and byte-addressed sparse memory keyed by (AddrSpace, BitVector).
    • Optional arm64-guest feature connects ConcreteEnvironment::with_arm64_bindings and with_arm64_services to exact AArch64 FP, SVE/SME VL/SVL, MOPS, MTE, RCW/LSFE, LS64, and TIndex policies.
  • Fault Visibility (ReferenceExecution::visible_state): ReferenceExecution separates raw environment mutations (outcome: ExecutionOutcome) from ArchitecturallyVisibleState (Exact, CanonicalPrefix, PermittedMemorySubset, or Unsupported(ReferenceVisibilityBoundary) when an eager environment cannot roll back a Restartable fault).
  • Suspensible Opaque Execution: ReferenceEmitter::suspend() / ReferenceEmitterState::resume() allows embeddings (such as archsem-lua/runtime) to complete reentrant guest services without losing session counters, choices, or transaction state.

Bounded Symbolic & Concolic Execution (archsem-symex)

archsem-symex lowers a complete Function via RegisterSsa into SymbolicProgram block templates and explores paths deterministically within explicit ExecutionConfig budgets—without requiring LLVM or an external SMT solver.

[!WARNING] Licensing: archsem-symex depends on bitwright (PolyForm-Noncommercial-1.0.0). Noncommercial use is free; commercial use requires a license from bitwright's licensor.

Symbolic Engine & bitwright Integration

  • Context-Owned Arena (ExprArena): Structurally interned 1–512-bit expressions with exact widths, ternary selects, conservative symbols, and scoped Choices (FreshPerObservation, ProducedValue, InstructionExecution, persistent scopes).
  • Total Translation + Definedness Guards: Each node translates into a total bitwright bitvector value paired with a 1-bit invalidness guard (1 iff a partial operation is violated). Invalid operations are excluded from path-condition input inference so path pruning never erases a shift/division definedness obligation.
  • Deterministic Constraint Solving & Simplification: Each path maintains bitwright constraints (known bits, signed/unsigned ranges, equality classes) and prunes only proven contradictions. Reported expressions are simplified (and optionally equality-saturated via SimplificationBudgets::max_saturation_work_per_expression) deterministically.
  • Nested Resource Budgets (ExecutionConfig): Independently caps PathBudgets (max_steps_per_path, max_paths, max_block_visits_per_path), ExpressionBudgets, SubstitutionBudgets, RecursionBudgets, MemoryBudgets, SimplificationBudgets, and DiagnosticBudgets. Each limit produces a typed BudgetKind exit.
  • Policy Boundaries (ExecutionContext): Unmodeled memory, opaque intrinsics, calls, fences, atomics, reservations, transactions, and faults fail closed with PathExit::Unsupported(UnsupportedReason) unless the caller injects a path-local MemoryPolicy (e.g., ExactByteMemory for concrete bytes), IntrinsicPolicy, CallPolicy, or EffectPolicy. All policy mutations are staged transactionally per path.

Concolic Execution (execute_concolic)

execute_concolic executes a single deterministic path guided by a ConcolicTrace of typed branch, switch, indirect-target, and concrete ordinary-memory observations. It returns the consumed observations, exact path condition, and negated exploration alternatives, stopping cleanly at any missing, mismatched, or ambiguous boundary.

Proof Obligations & Validation Artifacts

  • ProofObligation / ProofObligationArtifact: Projects caller-selected inputs and one path's reachable outputs into solver-neutral ProofTermOp DAGs (tN topological names, per-term provenance/fidelity, typed assumption/definedness/fault/output roots) exportable to bounded JSON/RON.
  • InstructionValidationObligation & InstructionCounterexampleArtifact: Packages a complete instruction/case validation handoff (inputs, choices, preconditions, observable roots, faults, register deltas, rewrite mappings, and bounds). External solver models can be replayed against InstructionCounterexampleArtifact to verify mismatches and map them backward through rewrite provenance.
  • Rewrite Checking (transform-check feature): check_fragment_transform and check_function_transform provide translation-validation checks for fragment/function rewrites during fuzzing and testing.

Action Recording (archsem-record)

ActionRecorder implements IrEmitter<Value = ValueRef> to record every emitted semantic action as a self-typed SemanticAction trace without committing to any compiler IR:

  • ActionRecorder::finish(control) validates definition order, widths (1..=512), choice identities, memory contracts, transaction/progress placement, and terminal consistency, returning a RecordedInstruction with stable EventIds, interned SemanticSites, and RecordedControlEffect.
  • With the serde feature enabled, RecordedInstruction serializes cleanly to JSON for inspection, cross-architecture diffing, or external transpilation.

Reference LLVM Backend (archsem-llvm)

archsem-llvm (publish = false, host-only, linking LLVM 21.1 via llvm-sys) provides LlvmEmitter, proving the framework's IR-agnostic design on a production compiler IR:

  • Uniform Integer Values: Every IrEmitter::Value is an LLVM integer of exact bit width (1..=512); registers use width-typed allocas in the prologue initialized with freeze undef (never raw per-use undef or poison); floating-point ops bitcast across float/double.
  • Choice Bindings: LlvmEmitter::new accepts non-persistent choices; LlvmEmitter::new_with_choice_bindings takes a ChoiceBindingEnvironment to declare and load immutable external symbols for persistent scopes (ExecutionSession, MachineProfile, ExternallySupplied).
  • Conservative Lowering of Unmodeled Contracts: Unsupported guest-memory contracts, fences, and valid fall-through OpaqueIntrinsics lower to single observable external calls retaining full typed diagnostics (MemoryLoweringDiagnostic, FenceLoweringDiagnostic, OpaqueLoweringDiagnostic). Opt-in enable_guest_fault_reporting_loads() lowers LoadTry to packed (data, fault) guest helper calls.
  • Register-SSA Lowering (RegisterSsaReplaySink): Function::replay_register_ssa lowers complete functions into LLVM basic blocks and phi nodes (using bridge predecessors where needed) and emits external ABI boundaries @archsem.return, @archsem.jump.*, and @archsem.call.*.