Normative Semantics Contract

This chapter distills the normative rules from SEMANTICS.md. In Architectura, semantic conformance is defined by this contract; Rust types and .asem syntax are implementations of it.

1. Semantic Objects & Behavior Sets

An instruction semantic definition maps:

  • Exact instruction bytes and decoded operands
  • A typed DecodeContext (architecture, mode, canonical EnabledFeatures, endianness, and bounded, revisioned DecodeArchitectureState)
  • Initial architectural state
  • Architectural-choice and environment provider selections

to a behavior set B(X, P) under observation profile P. Each member execution consists of:

  1. An acyclic instruction-local event trace and typed EventGraph.
  2. One coherent terminal outcome (fallthrough, control transfer, or architectural fault/trap).
  3. The architecturally visible state delta at that outcome.

Decode context transitions MUST be explicit outputs; hidden mutable decoder state MUST NOT influence semantics.

2. Architectural Observables & Consumer Flag Demand

Under the full-observation profile, observables include:

  • Writes, undefinedness, and preservation of architectural register slices and flags (distinguishing preserved vs. unwritten-unknown, at bit-slice granularity).
  • Guest-memory reads, writes, atomics, reservations, fences, and declared memory events (retaining exact bit widths and byte masks).
  • Direct and indirect control transfers, predicates, fallthroughs, link effects, delay-slot/repeat behavior, and mode transitions.
  • Faults/traps, their class, priority, trigger point, and visible pre-fault state.
  • Transaction checkpoints, partial-progress markers, memory ordering, and atomicity.
  • Structured opaque effects and choice observations.

Consumer Flag Demand (FlagDemand)

  • FlagDemand is a consumer assertion about surrounding liveness, never an Architectura inference.
  • A consumer MAY drop a status flag from demand only when that flag is overwritten before any read on every path leaving the instruction—including fault, trap, exception, unwind, call, return, indirect transfer, and incomplete boundaries.
  • Narrowing removes whole per-flag computations (and pure intermediates reaching only suppressed flag writes); it never rewrites a demanded flag's computation or suppresses memory, fault, fence, intrinsic, or register-read events.
  • Repeat (REP) body/latch programs always execute under full flag demand.

3. Values, Widths & Partial Operations

  • Positive Bit Widths: Every value has a positive width (1..=512 bits). Int(1) is the predicate type. Arithmetic wraps modulo 2^width; signedness is an operation property, not type state.
  • No Inherited Backend UB: Architectura never inherits undefined behavior or poison from Rust, C, or LLVM. Partial operations MUST have explicit boundary handling:
    • Shifts/rotates require count < width
    • Unsigned division/remainder requires divisor != 0
    • Signed division requires divisor != 0 and representable quotient (not INT_MIN / -1)
    • ExtractElement, InsertElement, and IndexedRegisterBank accesses require in-bounds lanes/indices
  • Mandatory Trust-Boundary Verification: Builder finalization, generated tables, and deserialized artifacts MUST pass the canonical semantic-program verifier before the first emitter call.

4. Effects, Guards, Transactions & Control

  • Trace Order vs. Memory Order: Instruction-local trace order governs same-instruction visibility, exception priority, and checkpoint prefixes; inter-thread ordering MUST be stated explicitly via MemoryOrdering / FenceRequest.
  • Guarded Suppression: A false guard on LoadCond, StoreCond, LoadTry, ProbeWrite, TrapIf, or WriteRegCond suppresses the event, its memory access, ordering edges, and associated faults (LoadCond yields 0; LoadTry yields (0, false)).
  • Transaction & Progress Matrix:
TransactionModelProgressModelContract
RestartableExactEntry state or latest explicit Commit is visible on fault
ProgressiveExactEvery preceding effect is visible in authored order
ProgressiveCanonicalPrefixEmitted prefix is guaranteed visible; later permitted effects may also have completed
PermittedMemorySubsetExactRegisters/non-memory roll back to checkpoint; an implementation-selected subset of other memory mutations in the segment may be visible (excluding the faulting mutation)

Combinations (Restartable, CanonicalPrefix) and (PermittedMemorySubset, CanonicalPrefix) are illegal. Commit requires at least one pending observable effect site since entry or the prior commit.

  • Control Transfer: Every completed instruction has one coherent terminal record (SemanticControl) retaining kind, direct/indirect destination, predicate, fallthrough, trap payload, link timing, delay-slot/repeat policy, mode switch, and fidelity/choice dependencies.

5. Architectural Choices

A Choice is a typed, domain-constrained source of allowed behaviors—never backend undef or poison:

  • Kinds: Unspecified, ConstrainedUnpredictable, ImplementationDefined, Environment, Entropy, Uninitialized.
  • Correlation Scopes: FreshPerObservation, ProducedValue, InstructionExecution, ExecutionSession, MachineProfile, ExternallySupplied.
  • Lifecycle & Predeclaration: InstructionExecution choices begin at begin_instruction (or explicit InstructionExecutionGroup Root/RepeatBody/RepeatLatch boundaries). Persistent scopes (ExecutionSession, MachineProfile, ExternallySupplied) require deterministic 128-bit ChoiceBindingNamespaces via ChoiceBindingEnvironment and MUST be predeclared before emitter mutation.
  • DCE Rule: Only an Unspecified choice at ProducedValue scope with no correlation key and zero remaining uses may be deleted as dead pure computation; all other choices MUST be retained.

6. Faults, Unsupported Boundaries & Malformed Semantics

  • Architectural Faults/Traps belong to the behavior set (carrying kind, class, priority, and visible prefix; OS exception dispatch is outside archsem).
  • Unsupported Dispositions (UnsupportedSemantics, BackendCapabilityError) fail closed before destination mutation—never silently becoming no-ops or unconstrained values.
  • Malformed Semantics (width mismatch, uninitialized slot, unhandled partial op, invalid domain, cycle, incoherent transaction) are rejected by validation before emission.
  • Incompleteness Metadata: Partial CFGs carry explicit IncompletenessState (Absent, Complete, Unknown, Unresolved) and finite IncompletenessRecords; unknown/unresolved functions cannot be marked Complete and are rejected by destructive transforms and executable replay.

7. Equivalence, Refinement & Fidelity Review Labels

Behavior-set relations compare B(L, P) and B(R, P):

  • Equivalent: B(L, P) = B(R, P)
  • LeftRefinesRight: B(L, P) ⊂ B(R, P)
  • RightRefinesLeft: B(R, P) ⊂ B(L, P)
  • Unknown: insufficient evidence or bounds (MUST NOT be reported as Equivalent)

Architecture catalogs map (SemanticCoverage, SemanticImplementationDisposition) to exactly one reviewed CoverageLabel:

CoverageLabelRequired SemanticCoverageRequired Disposition
FaithfulExactModeled semantics
PartialConservativeOverapproximation, Underapproximation, or MixedPartialModeled semantics
OpaqueOpaqueDataflowStructured opaque semantics
AbsentUnsupportedNo executable semantics provider

8. Resource Limits (ResourceLimits)

All decoding, validation, artifact loading, provenance construction, and CFG discovery enforce explicit finite bounds (ResourceLimits: input_bytes, string_bytes, decode_rows, decode_fields, program_ops, expression_nodes, nesting_depth, expansion_ops, value_slots, intrinsic_arguments, identifiers, lookup_table_bytes, permutation_elements, register_list_entries, instruction_bytes, instruction_operands, ir_values, ir_events, dependency_edges, cfg_blocks, cfg_edges, diagnostics). Exceeding a bound fails cleanly with LimitExceeded before mutation.