SilverSight/Core/SilverSight/Semantics/View.lean
allaun 3504bca392 feat(lean): add SilverSight Semantics core modules (Schema, Layout, WireFormat, View, LayoutBridge, CanalLayout)
Implements the YaFF-inspired separation of schema, layout, and access pattern
in Core/SilverSight/Semantics/:

- Schema.lean: fixed-size Schema typeclass with byteSize and wellFormed.
- Layout.lean: Layout enum, AccessProfile cost model, and cost-based selector
  with an ε-suboptimality theorem.
- WireFormat.lean: certified encode/decode/roundTrip/encode_size structure.
- View.lean: zero-copy View with address-arithmetic invariant.
- LayoutBridge.lean: certified layout-conversion structure and identity bridges.
- CanalLayout.lean: CanalRegime enum and regime-aware layout selection.

Also updates:
- lakefile.lean: adds SilverSight.Semantics.* roots to SilverSightCore.
- docs/ARCHITECTURE.md, RRC_REFACTOR_READINESS.md, PROJECT_MAP.{md,json},
  build_logs/2026-06-21_session_build_baseline.md, and GLOSSARY.md.
- AGENTS.md: build baseline, blessed surfaces, and pending proof work.

Build: 2987 jobs, 0 errors (lake build)
Tests: Python 21/21, Lean/C 35/35
2026-06-21 14:00:56 -05:00

48 lines
1.4 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
SilverSight.Semantics.View
A View is a structured value read from a byte range without copying the
underlying buffer. The Core defines the address-arithmetic contract; the
zero-copy property is a theorem about offsets and schema sizes.
Only fixed-size Core schemas have built-in accessors. Variable-length views
are a library extension that must preserve the same address-arithmetic
invariant.
-/
import SilverSight.Semantics.Schema
namespace SilverSight.Semantics
/-- A zero-copy view of a fixed-size schema value inside a byte buffer.
`valid` is the address-arithmetic invariant: the schema's byte range
fits entirely inside the buffer starting at `offset`. -/
structure View (α : Type) [Schema α] where
base : ByteArray
offset : Nat
valid : offset + byteSize α ≤ base.size
namespace View
/-- Read a UInt8 through a one-byte view. The result is the byte at the
view's offset; no copy of the underlying buffer occurs. -/
def readUInt8 (v : View UInt8) : UInt8 :=
v.base.get v.offset (by
have h : byteSize UInt8 = 1 := rfl
have hv := v.valid
omega
)
/-- Reading a UInt8 view returns exactly the byte at the stored offset. -/
@[simp]
theorem readUInt8_eq_get (v : View UInt8) :
readUInt8 v = v.base.get v.offset (by
have h : byteSize UInt8 = 1 := rfl
have hv := v.valid
omega
) := rfl
end View
end SilverSight.Semantics