SilverSight/Core/SilverSight/Semantics/LayoutBridge.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

46 lines
1.5 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.LayoutBridge
A LayoutBridge converts between two wire formats of the same schema and
preserves meaning. The `correct` field is a Lean proof that converting the
encoding in layout L1 yields exactly the encoding in layout L2.
The Core only provides the bridge interface and identity bridges. Concrete
bridges (row-major ↔ columnar, compact expansion, mmap view wrapping) are
library extensions that must each supply a `correct` proof.
-/
import SilverSight.Semantics.Schema
import SilverSight.Semantics.Layout
import SilverSight.Semantics.WireFormat
namespace SilverSight.Semantics
/-- A certified conversion between two wire formats of the same schema. -/
structure LayoutBridge (α : Type) [Schema α] (L1 L2 : Layout) where
wf1 : WireFormat α L1
wf2 : WireFormat α L2
convert : ByteArray → ByteArray
correct : ∀ a, convert (wf1.encode a) = wf2.encode a
namespace LayoutBridge
/-- The identity bridge: encoding in L is already the encoding in L. -/
def identity {α : Type} {L : Layout} [Schema α] (wf : WireFormat α L) :
LayoutBridge α L L where
wf1 := wf
wf2 := wf
convert := id
correct := by simp
/-- Identity bridge for `Bool` row-major. -/
def boolRowMajor : LayoutBridge Bool rowMajor rowMajor :=
identity WireFormat.boolRowMajor
/-- Identity bridge for `UInt8` row-major. -/
def uint8RowMajor : LayoutBridge UInt8 rowMajor rowMajor :=
identity WireFormat.uint8RowMajor
end LayoutBridge
end SilverSight.Semantics