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, canonicalEnabledFeatures, endianness, and bounded, revisionedDecodeArchitectureState) - 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:
- An acyclic instruction-local event trace and typed
EventGraph. - One coherent terminal outcome (fallthrough, control transfer, or architectural fault/trap).
- 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)
FlagDemandis 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..=512bits).Int(1)is the predicate type. Arithmetic wraps modulo2^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 != 0and representable quotient (notINT_MIN / -1) ExtractElement,InsertElement, andIndexedRegisterBankaccesses require in-bounds lanes/indices
- Shifts/rotates require
- 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, orWriteRegCondsuppresses the event, its memory access, ordering edges, and associated faults (LoadCondyields0;LoadTryyields(0, false)). - Transaction & Progress Matrix:
TransactionModel | ProgressModel | Contract |
|---|---|---|
Restartable | Exact | Entry state or latest explicit Commit is visible on fault |
Progressive | Exact | Every preceding effect is visible in authored order |
Progressive | CanonicalPrefix | Emitted prefix is guaranteed visible; later permitted effects may also have completed |
PermittedMemorySubset | Exact | Registers/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:
InstructionExecutionchoices begin atbegin_instruction(or explicitInstructionExecutionGroupRoot/RepeatBody/RepeatLatchboundaries). Persistent scopes (ExecutionSession,MachineProfile,ExternallySupplied) require deterministic 128-bitChoiceBindingNamespacesviaChoiceBindingEnvironmentand MUST be predeclared before emitter mutation. - DCE Rule: Only an
Unspecifiedchoice atProducedValuescope 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 finiteIncompletenessRecords; unknown/unresolved functions cannot be markedCompleteand 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 asEquivalent)
Architecture catalogs map (SemanticCoverage, SemanticImplementationDisposition) to exactly one reviewed CoverageLabel:
CoverageLabel | Required SemanticCoverage | Required Disposition |
|---|---|---|
Faithful | Exact | Modeled semantics |
Partial | ConservativeOverapproximation, Underapproximation, or MixedPartial | Modeled semantics |
Opaque | OpaqueDataflow | Structured opaque semantics |
Absent | Unsupported | No 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.