Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions Ix/Cli/DiffCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
/-
`ix diff <old.ixe> <new.ixe>`: structured diff of two serialized Ixon
environments.

The diff itself is computed in Rust (`rs_diff_env_files` →
`ixon::diff`): both files are memory-mapped and lazily parsed
(constant windows stay zero-copy mmap slices; `ConstantMeta` is never
bulk-materialized) and compared on anonymous structure — names serve
as join/display keys, constants compare by content address with
per-field classification (type/value/lvls/…, `block.*` for projection
targets, `"encoding"` when only the representation moved). `--meta`
additionally compares named metadata (`ConstantMeta`/`original`) via
a streaming merge-join over both files' §5 named sections.

Every changed row carries a root-vs-rippled verdict: one edited
constant re-addresses its whole reverse-dependency cone, so most
changed rows are *rippled* (fully explained by dependency
re-addressing) and only the *roots* are intrinsic edits. The default
display lists roots and summarizes the rippled count; `--verbose`
lists rippled rows too, and in `--meta` mode rippled rows carrying
metadata edits stay visible.

Exit codes (GNU diff convention): 0 = no difference found in the
selected mode, 1 = differences found, 2 = error.
-/
module
public import Cli
public import Ix.Address
public import Ix.Common
public import Ix.Ixon

public section

namespace Ix.Cli.DiffCmd

private def pad (s : String) (w : Nat) : String :=
s.pushn ' ' (w - s.length)

private def shortAddr (verbose : Bool) (a : Address) : String :=
if verbose then toString a else ((toString a).take 12).toString ++ "…"

/-- Synthetic mutual-block names embed the block hash as their second
component (`Ix.<64-hex>.…`); a changed block churns one such pair
per block, so the default display groups them into a count. -/
private def isSyntheticMuts (s : String) : Bool :=
match s.splitOn "." with
| "Ix" :: h :: _ =>
h.length == 64 && h.all fun c => c.isDigit || ('a' ≤ c && c ≤ 'f')
| _ => false

private def printStats (path : String) (s : Ixon.EnvStats) : IO Unit :=
IO.println
s!"[diff] {path}: {s.consts} consts, {s.named} named, {s.blobs} blobs, {s.comms} comms"

/-- Print up to `cap` addresses (all when `verbose`), one per line. -/
private def printAddrList
(linePrefix : String) (addrs : Array Address) (verbose : Bool) :
IO Unit := do
let cap := if verbose then addrs.size else min addrs.size 10
for a in addrs[0:cap] do
IO.println s!"{linePrefix}{shortAddr verbose a}"
if addrs.size > cap then
IO.println s!"{linePrefix}… and {addrs.size - cap} more"

private def brackets (labels : Array String) : String :=
"[" ++ ", ".intercalate labels.toList ++ "]"

private def printNamedSection
(d : Ixon.EnvDiff) (wantMeta verbose : Bool) : IO Unit := do
let keep (s : String) : Bool := verbose || !isSyntheticMuts s
let added := d.namedAdded.filter (keep ·.1)
let removed := d.namedRemoved.filter (keep ·.1)
let synAdded := d.namedAdded.size - added.size
let synRemoved := d.namedRemoved.size - removed.size
let roots := d.namedChanged.filter (!·.rippled)
let rippleCount :=
if d.namedChanged.isEmpty then ""
else s!" ({roots.size} roots, {d.namedChanged.size - roots.size} rippled)"
let metaCount :=
if wantMeta then s!", {d.namedMetaOnly.size} metadata-only" else ""
IO.println
s!"named: {d.namedAdded.size} added, {d.namedRemoved.size} removed, {d.namedChanged.size} changed{rippleCount}{metaCount}"
if synAdded + synRemoved > 0 then
IO.println
s!" (synthetic mutual-block names: {synAdded} added, {synRemoved} removed — --verbose lists)"
-- Changed rows shown by default: the roots, plus (under --meta)
-- rippled rows carrying metadata edits — `namedMetaOnly` only covers
-- same-addr rows, so hiding those would hide real metadata changes.
let shown := d.namedChanged.filter fun c =>
verbose || !c.rippled || (wantMeta && !c.metaFields.isEmpty)
-- Column width over everything we are about to print.
let mut wMax := 0
for (n, _) in added do wMax := max wMax n.length
for (n, _) in removed do wMax := max wMax n.length
for c in shown do wMax := max wMax c.name.length
for (n, _) in d.namedMetaOnly do wMax := max wMax n.length
let w := min wMax 40
for (n, addr) in added do
IO.println s!" + {pad n w} {shortAddr verbose addr}"
for (n, addr) in removed do
IO.println s!" - {pad n w} {shortAddr verbose addr}"
for c in shown do
let kind :=
if c.oldKind == c.newKind then c.oldKind
else s!"{c.oldKind}→{c.newKind}"
let ripTag := if c.rippled then " (rippled)" else ""
IO.println
s!" ~ {pad c.name w} {pad kind 9} {shortAddr verbose c.oldAddr} → {shortAddr verbose c.newAddr} {brackets c.fields}{ripTag}"
if wantMeta && !c.metaFields.isEmpty then
IO.println s!" meta: {brackets c.metaFields}"
let hidden := d.namedChanged.size - shown.size
if hidden > 0 then
IO.println
s!" ({hidden} rippled rows hidden — address changes fully explained by dependency re-addressing; --verbose lists)"
for (n, labels) in d.namedMetaOnly do
IO.println s!" m {pad n w} {brackets labels}"
if shown.any (·.fields.contains "encoding") then
IO.println
" (encoding = representation changed; no semantic field difference detected)"

def runDiffCmd (p : Cli.Parsed) : IO UInt32 := do
let some oldArg := p.positionalArg? "old"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let some newArg := p.positionalArg? "new"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let oldPath := oldArg.as! String
let newPath := newArg.as! String
let wantMeta := p.hasFlag "meta"
if wantMeta && p.hasFlag "anon" then
IO.eprintln "error: --anon and --meta are mutually exclusive"
return 2
let verbose := p.hasFlag "verbose"
-- Byte-equal fast path and the diff itself both run over mmapped
-- files — nothing is read into Lean ByteArrays.
let d ← try
if ← Ixon.rsIxeFilesEqual oldPath newPath then
IO.println "identical"
return (0 : UInt32)
Ixon.rsDiffEnvFiles oldPath newPath wantMeta
catch e =>
IO.eprintln s!"error: {e.toString}"
return (2 : UInt32)
printStats oldPath d.statsA
printStats newPath d.statsB
if d.isEmpty then
if wantMeta then
IO.println "files differ in bytes but no semantic difference found"
else
IO.println
"files differ in bytes but no anonymous-structure difference found (try --meta)"
return 0
if let some (oldMain, newMain) := d.mainChanged then
let fmt : Option Address → String
| none => "∅"
| some a => shortAddr verbose a
IO.println s!"main: {fmt oldMain} → {fmt newMain}"
unless d.assumptionsAdded.isEmpty && d.assumptionsRemoved.isEmpty do
IO.println
s!"assumptions: +{d.assumptionsAdded.size} −{d.assumptionsRemoved.size}"
printAddrList " + " d.assumptionsAdded verbose
printAddrList " - " d.assumptionsRemoved verbose
unless d.namedAdded.isEmpty && d.namedRemoved.isEmpty
&& d.namedChanged.isEmpty && d.namedMetaOnly.isEmpty do
printNamedSection d wantMeta verbose
unless d.commsAdded.isEmpty && d.commsRemoved.isEmpty
&& d.commsChanged.isEmpty do
IO.println
s!"comms: +{d.commsAdded.size} −{d.commsRemoved.size} ~{d.commsChanged.size}"
printAddrList " + " d.commsAdded verbose
printAddrList " - " d.commsRemoved verbose
printAddrList " ~ " d.commsChanged verbose
unless d.constsOnlyA.isEmpty && d.constsOnlyB.isEmpty do
let note :=
if verbose then "" else " (mutual blocks/projections; --verbose lists)"
IO.println
s!"consts: {d.constsOnlyA.size} only in {oldPath}, {d.constsOnlyB.size} only in {newPath}{note}"
if verbose then
printAddrList " - " d.constsOnlyA verbose
printAddrList " + " d.constsOnlyB verbose
unless d.blobsOnlyA.isEmpty && d.blobsOnlyB.isEmpty do
IO.println
s!"blobs: {d.blobsOnlyA.size} only in {oldPath}, {d.blobsOnlyB.size} only in {newPath}"
if verbose then
printAddrList " - " d.blobsOnlyA verbose
printAddrList " + " d.blobsOnlyB verbose
unless d.hintsChanged.isEmpty do
IO.println s!"hints changed: {d.hintsChanged.size}"
let cap := if verbose then d.hintsChanged.size else min d.hintsChanged.size 10
for (a, oldH, newH) in d.hintsChanged[0:cap] do
IO.println s!" {shortAddr verbose a} {oldH} → {newH}"
if d.hintsChanged.size > cap then
IO.println s!" … and {d.hintsChanged.size - cap} more"
IO.println s!"[diff] {oldPath} ≠ {newPath}"
return 1

end Ix.Cli.DiffCmd

open Ix.Cli.DiffCmd in
def diffCmd : Cli.Cmd := `[Cli|
diff VIA runDiffCmd;
"Print a structured diff of two serialized Ixon environments (`.ixe`). By default only anonymous structure is compared: constants by content address (joined through names, with per-field change classification), consts/blobs sets, comms, main/assumptions, and reducibility hints. Changed names are root-caused: rows fully explained by dependency re-addressing are counted as `rippled` and hidden by default, so the listing shows the intrinsic edits (roots). Exit codes: 0 = no difference, 1 = differences found, 2 = error."

FLAGS:
anon; "Compare only anonymous structure (the default; accepted for explicitness)."
«meta»; "Additionally compare named metadata (binder names, originals, kv-maps)."
verbose; "Print full addresses, uncapped lists, synthetic mutual-block names, and rippled changed rows."

ARGS:
old : String; "Path to the first (old) serialized env (`.ixe`)."
new : String; "Path to the second (new) serialized env (`.ixe`)."
]

end
76 changes: 76 additions & 0 deletions Ix/Cli/PackCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
/-
`ix pack <env.ixe> <name>`: prune a serialized env to the self-contained
bundle pinning one named constant, and write it as a standalone `.ixe`.

A bundle is an `.ixe` whose `main` points at a distinguished constant;
because a constant's address is a merkle root over its whole dependency
DAG, `main`'s 32 bytes alone pin the value — the bundle is the
data-availability artifact that ships the bytes. `--assume` declares
trust-boundary cut-points: reached cut-points are recorded in the
bundle's `assumptions` instead of being carried (thin bundles).

The heavy lifting is `Env::prune_to_closure` (3-edge value closure of
`main`, display metadata carried to fixpoint) followed by
`Env::validate_closed` — the same check a receiver runs — so a written
bundle is closed by construction.

Different from `ix shard extract`: extract produces a general sub-env
for the kernel-check pipeline (no `main`, no `assumptions`, anon-work
block closure); pack produces a verified bundle with a root and an
explicit trust boundary.
-/
module
public import Cli
public import Ix.Ixon
public import Ix.Cli.ConstsFile

public section

namespace Ix.Cli.PackCmd

def runPackCmd (p : Cli.Parsed) : IO UInt32 := do
let some pathArg := p.positionalArg? "path"
| p.printError "error: must specify <path> to a source .ixe file"
return 1
let envPath := pathArg.as! String
let some nameArg := p.positionalArg? "name"
| p.printError "error: must specify <name> of the bundle root constant"
return 1
let mainName := nameArg.as! String
let assume ← Ix.Cli.ConstsFile.gather p "assume" "assume-file"
let outPath : String :=
match p.flag? "out" with
| some flag => flag.as! String
| none => s!"{mainName}.ixe"
let anon := p.hasFlag "anon"
let verbose := p.hasFlag "verbose"
try
Ixon.rsPackEnv envPath mainName assume outPath anon verbose
let mode := if anon then " [anon]" else ""
IO.println s!"[pack] wrote {outPath} (main {mainName}, \
{assume.size} assumption cut(s) declared){mode}"
return (0 : UInt32)
catch e =>
IO.eprintln s!"error: {e.toString}"
return (1 : UInt32)

end Ix.Cli.PackCmd

open Ix.Cli.PackCmd in
def packCmd : Cli.Cmd := `[Cli|
pack VIA runPackCmd;
"Prune a `.ixe` env to the self-contained bundle pinning one constant (sets `main`; validated closed)"

FLAGS:
anon; "Pack only anonymous structure — no names or metadata (§4/§5 empty; §3 hints still carried). The minimal artifact a receiver needs to typecheck/evaluate the pinned value."
assume : String; "Comma-separated cut-point constants — displayed names or 64-hex addresses. Reached cut-points are recorded in the bundle's `assumptions` instead of carried (thin bundle)."
"assume-file" : String; "Additionally read cut-points from a file (one per line; `#` comments and blank lines ignored). Unions with --assume."
out : String; "Output `.ixe` path. Defaults to `<name>.ixe` (e.g. `Nat.add.ixe`)."
verbose; "Print pack details (source stats, kept counts, bytes written) to stderr."

ARGS:
path : String; "Path to the source `.ixe` (e.g. from `ix compile`)."
name : String; "Displayed name of the bundle root constant (e.g. `Nat.add`)."
]

end
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions Ix/Cli/DiffCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
/-
`ix diff <old.ixe> <new.ixe>`: structured diff of two serialized Ixon
environments.

The diff itself is computed in Rust (`rs_diff_env_files` →
`ixon::diff`): both files are memory-mapped and lazily parsed
(constant windows stay zero-copy mmap slices; `ConstantMeta` is never
bulk-materialized) and compared on anonymous structure — names serve
as join/display keys, constants compare by content address with
per-field classification (type/value/lvls/…, `block.*` for projection
targets, `"encoding"` when only the representation moved). `--meta`
additionally compares named metadata (`ConstantMeta`/`original`) via
a streaming merge-join over both files' §5 named sections.

Every changed row carries a root-vs-rippled verdict: one edited
constant re-addresses its whole reverse-dependency cone, so most
changed rows are *rippled* (fully explained by dependency
re-addressing) and only the *roots* are intrinsic edits. The default
display lists roots and summarizes the rippled count; `--verbose`
lists rippled rows too, and in `--meta` mode rippled rows carrying
metadata edits stay visible.

Exit codes (GNU diff convention): 0 = no difference found in the
selected mode, 1 = differences found, 2 = error.
-/
module
public import Cli
public import Ix.Address
public import Ix.Common
public import Ix.Ixon

public section

namespace Ix.Cli.DiffCmd

private def pad (s : String) (w : Nat) : String :=
s.pushn ' ' (w - s.length)

private def shortAddr (verbose : Bool) (a : Address) : String :=
if verbose then toString a else ((toString a).take 12).toString ++ "…"

/-- Synthetic mutual-block names embed the block hash as their second
component (`Ix.<64-hex>.…`); a changed block churns one such pair
per block, so the default display groups them into a count. -/
private def isSyntheticMuts (s : String) : Bool :=
match s.splitOn "." with
| "Ix" :: h :: _ =>
h.length == 64 && h.all fun c => c.isDigit || ('a' ≤ c && c ≤ 'f')
| _ => false

private def printStats (path : String) (s : Ixon.EnvStats) : IO Unit :=
IO.println
s!"[diff] {path}: {s.consts} consts, {s.named} named, {s.blobs} blobs, {s.comms} comms"

/-- Print up to `cap` addresses (all when `verbose`), one per line. -/
private def printAddrList
(linePrefix : String) (addrs : Array Address) (verbose : Bool) :
IO Unit := do
let cap := if verbose then addrs.size else min addrs.size 10
for a in addrs[0:cap] do
IO.println s!"{linePrefix}{shortAddr verbose a}"
if addrs.size > cap then
IO.println s!"{linePrefix}… and {addrs.size - cap} more"

private def brackets (labels : Array String) : String :=
"[" ++ ", ".intercalate labels.toList ++ "]"

private def printNamedSection
(d : Ixon.EnvDiff) (wantMeta verbose : Bool) : IO Unit := do
let keep (s : String) : Bool := verbose || !isSyntheticMuts s
let added := d.namedAdded.filter (keep ·.1)
let removed := d.namedRemoved.filter (keep ·.1)
let synAdded := d.namedAdded.size - added.size
let synRemoved := d.namedRemoved.size - removed.size
let roots := d.namedChanged.filter (!·.rippled)
let rippleCount :=
if d.namedChanged.isEmpty then ""
else s!" ({roots.size} roots, {d.namedChanged.size - roots.size} rippled)"
let metaCount :=
if wantMeta then s!", {d.namedMetaOnly.size} metadata-only" else ""
IO.println
s!"named: {d.namedAdded.size} added, {d.namedRemoved.size} removed, {d.namedChanged.size} changed{rippleCount}{metaCount}"
if synAdded + synRemoved > 0 then
IO.println
s!" (synthetic mutual-block names: {synAdded} added, {synRemoved} removed — --verbose lists)"
-- Changed rows shown by default: the roots, plus (under --meta)
-- rippled rows carrying metadata edits — `namedMetaOnly` only covers
-- same-addr rows, so hiding those would hide real metadata changes.
let shown := d.namedChanged.filter fun c =>
verbose || !c.rippled || (wantMeta && !c.metaFields.isEmpty)
-- Column width over everything we are about to print.
let mut wMax := 0
for (n, _) in added do wMax := max wMax n.length
for (n, _) in removed do wMax := max wMax n.length
for c in shown do wMax := max wMax c.name.length
for (n, _) in d.namedMetaOnly do wMax := max wMax n.length
let w := min wMax 40
for (n, addr) in added do
IO.println s!" + {pad n w} {shortAddr verbose addr}"
for (n, addr) in removed do
IO.println s!" - {pad n w} {shortAddr verbose addr}"
for c in shown do
let kind :=
if c.oldKind == c.newKind then c.oldKind
else s!"{c.oldKind}→{c.newKind}"
let ripTag := if c.rippled then " (rippled)" else ""
IO.println
s!" ~ {pad c.name w} {pad kind 9} {shortAddr verbose c.oldAddr} → {shortAddr verbose c.newAddr} {brackets c.fields}{ripTag}"
if wantMeta && !c.metaFields.isEmpty then
IO.println s!" meta: {brackets c.metaFields}"
let hidden := d.namedChanged.size - shown.size
if hidden > 0 then
IO.println
s!" ({hidden} rippled rows hidden — address changes fully explained by dependency re-addressing; --verbose lists)"
for (n, labels) in d.namedMetaOnly do
IO.println s!" m {pad n w} {brackets labels}"
if shown.any (·.fields.contains "encoding") then
IO.println
" (encoding = representation changed; no semantic field difference detected)"

def runDiffCmd (p : Cli.Parsed) : IO UInt32 := do
let some oldArg := p.positionalArg? "old"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let some newArg := p.positionalArg? "new"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let oldPath := oldArg.as! String
let newPath := newArg.as! String
let wantMeta := p.hasFlag "meta"
if wantMeta && p.hasFlag "anon" then
IO.eprintln "error: --anon and --meta are mutually exclusive"
return 2
let verbose := p.hasFlag "verbose"
-- Byte-equal fast path and the diff itself both run over mmapped
-- files — nothing is read into Lean ByteArrays.
let d ← try
if ← Ixon.rsIxeFilesEqual oldPath newPath then
IO.println "identical"
return (0 : UInt32)
Ixon.rsDiffEnvFiles oldPath newPath wantMeta
catch e =>
IO.eprintln s!"error: {e.toString}"
return (2 : UInt32)
printStats oldPath d.statsA
printStats newPath d.statsB
if d.isEmpty then
if wantMeta then
IO.println "files differ in bytes but no semantic difference found"
else
IO.println
"files differ in bytes but no anonymous-structure difference found (try --meta)"
return 0
if let some (oldMain, newMain) := d.mainChanged then
let fmt : Option Address → String
| none => "∅"
| some a => shortAddr verbose a
IO.println s!"main: {fmt oldMain} → {fmt newMain}"
unless d.assumptionsAdded.isEmpty && d.assumptionsRemoved.isEmpty do
IO.println
s!"assumptions: +{d.assumptionsAdded.size} −{d.assumptionsRemoved.size}"
printAddrList " + " d.assumptionsAdded verbose
printAddrList " - " d.assumptionsRemoved verbose
unless d.namedAdded.isEmpty && d.namedRemoved.isEmpty
&& d.namedChanged.isEmpty && d.namedMetaOnly.isEmpty do
printNamedSection d wantMeta verbose
unless d.commsAdded.isEmpty && d.commsRemoved.isEmpty
&& d.commsChanged.isEmpty do
IO.println
s!"comms: +{d.commsAdded.size} −{d.commsRemoved.size} ~{d.commsChanged.size}"
printAddrList " + " d.commsAdded verbose
printAddrList " - " d.commsRemoved verbose
printAddrList " ~ " d.commsChanged verbose
unless d.constsOnlyA.isEmpty && d.constsOnlyB.isEmpty do
let note :=
if verbose then "" else " (mutual blocks/projections; --verbose lists)"
IO.println
s!"consts: {d.constsOnlyA.size} only in {oldPath}, {d.constsOnlyB.size} only in {newPath}{note}"
if verbose then
printAddrList " - " d.constsOnlyA verbose
printAddrList " + " d.constsOnlyB verbose
unless d.blobsOnlyA.isEmpty && d.blobsOnlyB.isEmpty do
IO.println
s!"blobs: {d.blobsOnlyA.size} only in {oldPath}, {d.blobsOnlyB.size} only in {newPath}"
if verbose then
printAddrList " - " d.blobsOnlyA verbose
printAddrList " + " d.blobsOnlyB verbose
unless d.hintsChanged.isEmpty do
IO.println s!"hints changed: {d.hintsChanged.size}"
let cap := if verbose then d.hintsChanged.size else min d.hintsChanged.size 10
for (a, oldH, newH) in d.hintsChanged[0:cap] do
IO.println s!" {shortAddr verbose a} {oldH} → {newH}"
if d.hintsChanged.size > cap then
IO.println s!" … and {d.hintsChanged.size - cap} more"
IO.println s!"[diff] {oldPath} ≠ {newPath}"
return 1

end Ix.Cli.DiffCmd

open Ix.Cli.DiffCmd in
def diffCmd : Cli.Cmd := `[Cli|
diff VIA runDiffCmd;
"Print a structured diff of two serialized Ixon environments (`.ixe`). By default only anonymous structure is compared: constants by content address (joined through names, with per-field change classification), consts/blobs sets, comms, main/assumptions, and reducibility hints. Changed names are root-caused: rows fully explained by dependency re-addressing are counted as `rippled` and hidden by default, so the listing shows the intrinsic edits (roots). Exit codes: 0 = no difference, 1 = differences found, 2 = error."

FLAGS:
anon; "Compare only anonymous structure (the default; accepted for explicitness)."
«meta»; "Additionally compare named metadata (binder names, originals, kv-maps)."
verbose; "Print full addresses, uncapped lists, synthetic mutual-block names, and rippled changed rows."

ARGS:
old : String; "Path to the first (old) serialized env (`.ixe`)."
new : String; "Path to the second (new) serialized env (`.ixe`)."
]

end
76 changes: 76 additions & 0 deletions Ix/Cli/PackCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
/-
`ix pack <env.ixe> <name>`: prune a serialized env to the self-contained
bundle pinning one named constant, and write it as a standalone `.ixe`.

A bundle is an `.ixe` whose `main` points at a distinguished constant;
because a constant's address is a merkle root over its whole dependency
DAG, `main`'s 32 bytes alone pin the value — the bundle is the
data-availability artifact that ships the bytes. `--assume` declares
trust-boundary cut-points: reached cut-points are recorded in the
bundle's `assumptions` instead of being carried (thin bundles).

The heavy lifting is `Env::prune_to_closure` (3-edge value closure of
`main`, display metadata carried to fixpoint) followed by
`Env::validate_closed` — the same check a receiver runs — so a written
bundle is closed by construction.

Different from `ix shard extract`: extract produces a general sub-env
for the kernel-check pipeline (no `main`, no `assumptions`, anon-work
block closure); pack produces a verified bundle with a root and an
explicit trust boundary.
-/
module
public import Cli
public import Ix.Ixon
public import Ix.Cli.ConstsFile

public section

namespace Ix.Cli.PackCmd

def runPackCmd (p : Cli.Parsed) : IO UInt32 := do
let some pathArg := p.positionalArg? "path"
| p.printError "error: must specify <path> to a source .ixe file"
return 1
let envPath := pathArg.as! String
let some nameArg := p.positionalArg? "name"
| p.printError "error: must specify <name> of the bundle root constant"
return 1
let mainName := nameArg.as! String
let assume ← Ix.Cli.ConstsFile.gather p "assume" "assume-file"
let outPath : String :=
match p.flag? "out" with
| some flag => flag.as! String
| none => s!"{mainName}.ixe"
let anon := p.hasFlag "anon"
let verbose := p.hasFlag "verbose"
try
Ixon.rsPackEnv envPath mainName assume outPath anon verbose
let mode := if anon then " [anon]" else ""
IO.println s!"[pack] wrote {outPath} (main {mainName}, \
{assume.size} assumption cut(s) declared){mode}"
return (0 : UInt32)
catch e =>
IO.eprintln s!"error: {e.toString}"
return (1 : UInt32)

end Ix.Cli.PackCmd

open Ix.Cli.PackCmd in
def packCmd : Cli.Cmd := `[Cli|
pack VIA runPackCmd;
"Prune a `.ixe` env to the self-contained bundle pinning one constant (sets `main`; validated closed)"

FLAGS:
anon; "Pack only anonymous structure — no names or metadata (§4/§5 empty; §3 hints still carried). The minimal artifact a receiver needs to typecheck/evaluate the pinned value."
assume : String; "Comma-separated cut-point constants — displayed names or 64-hex addresses. Reached cut-points are recorded in the bundle's `assumptions` instead of carried (thin bundle)."
"assume-file" : String; "Additionally read cut-points from a file (one per line; `#` comments and blank lines ignored). Unions with --assume."
out : String; "Output `.ixe` path. Defaults to `<name>.ixe` (e.g. `Nat.add.ixe`)."
verbose; "Print pack details (source stats, kept counts, bytes written) to stderr."

ARGS:
path : String; "Path to the source `.ixe` (e.g. from `ix compile`)."
name : String; "Displayed name of the bundle root constant (e.g. `Nat.add`)."
]

end
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions Ix/Cli/DiffCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
/-
`ix diff <old.ixe> <new.ixe>`: structured diff of two serialized Ixon
environments.

The diff itself is computed in Rust (`rs_diff_env_files` →
`ixon::diff`): both files are memory-mapped and lazily parsed
(constant windows stay zero-copy mmap slices; `ConstantMeta` is never
bulk-materialized) and compared on anonymous structure — names serve
as join/display keys, constants compare by content address with
per-field classification (type/value/lvls/…, `block.*` for projection
targets, `"encoding"` when only the representation moved). `--meta`
additionally compares named metadata (`ConstantMeta`/`original`) via
a streaming merge-join over both files' §5 named sections.

Every changed row carries a root-vs-rippled verdict: one edited
constant re-addresses its whole reverse-dependency cone, so most
changed rows are *rippled* (fully explained by dependency
re-addressing) and only the *roots* are intrinsic edits. The default
display lists roots and summarizes the rippled count; `--verbose`
lists rippled rows too, and in `--meta` mode rippled rows carrying
metadata edits stay visible.

Exit codes (GNU diff convention): 0 = no difference found in the
selected mode, 1 = differences found, 2 = error.
-/
module
public import Cli
public import Ix.Address
public import Ix.Common
public import Ix.Ixon

public section

namespace Ix.Cli.DiffCmd

private def pad (s : String) (w : Nat) : String :=
s.pushn ' ' (w - s.length)

private def shortAddr (verbose : Bool) (a : Address) : String :=
if verbose then toString a else ((toString a).take 12).toString ++ "…"

/-- Synthetic mutual-block names embed the block hash as their second
component (`Ix.<64-hex>.…`); a changed block churns one such pair
per block, so the default display groups them into a count. -/
private def isSyntheticMuts (s : String) : Bool :=
match s.splitOn "." with
| "Ix" :: h :: _ =>
h.length == 64 && h.all fun c => c.isDigit || ('a' ≤ c && c ≤ 'f')
| _ => false

private def printStats (path : String) (s : Ixon.EnvStats) : IO Unit :=
IO.println
s!"[diff] {path}: {s.consts} consts, {s.named} named, {s.blobs} blobs, {s.comms} comms"

/-- Print up to `cap` addresses (all when `verbose`), one per line. -/
private def printAddrList
(linePrefix : String) (addrs : Array Address) (verbose : Bool) :
IO Unit := do
let cap := if verbose then addrs.size else min addrs.size 10
for a in addrs[0:cap] do
IO.println s!"{linePrefix}{shortAddr verbose a}"
if addrs.size > cap then
IO.println s!"{linePrefix}… and {addrs.size - cap} more"

private def brackets (labels : Array String) : String :=
"[" ++ ", ".intercalate labels.toList ++ "]"

private def printNamedSection
(d : Ixon.EnvDiff) (wantMeta verbose : Bool) : IO Unit := do
let keep (s : String) : Bool := verbose || !isSyntheticMuts s
let added := d.namedAdded.filter (keep ·.1)
let removed := d.namedRemoved.filter (keep ·.1)
let synAdded := d.namedAdded.size - added.size
let synRemoved := d.namedRemoved.size - removed.size
let roots := d.namedChanged.filter (!·.rippled)
let rippleCount :=
if d.namedChanged.isEmpty then ""
else s!" ({roots.size} roots, {d.namedChanged.size - roots.size} rippled)"
let metaCount :=
if wantMeta then s!", {d.namedMetaOnly.size} metadata-only" else ""
IO.println
s!"named: {d.namedAdded.size} added, {d.namedRemoved.size} removed, {d.namedChanged.size} changed{rippleCount}{metaCount}"
if synAdded + synRemoved > 0 then
IO.println
s!" (synthetic mutual-block names: {synAdded} added, {synRemoved} removed — --verbose lists)"
-- Changed rows shown by default: the roots, plus (under --meta)
-- rippled rows carrying metadata edits — `namedMetaOnly` only covers
-- same-addr rows, so hiding those would hide real metadata changes.
let shown := d.namedChanged.filter fun c =>
verbose || !c.rippled || (wantMeta && !c.metaFields.isEmpty)
-- Column width over everything we are about to print.
let mut wMax := 0
for (n, _) in added do wMax := max wMax n.length
for (n, _) in removed do wMax := max wMax n.length
for c in shown do wMax := max wMax c.name.length
for (n, _) in d.namedMetaOnly do wMax := max wMax n.length
let w := min wMax 40
for (n, addr) in added do
IO.println s!" + {pad n w} {shortAddr verbose addr}"
for (n, addr) in removed do
IO.println s!" - {pad n w} {shortAddr verbose addr}"
for c in shown do
let kind :=
if c.oldKind == c.newKind then c.oldKind
else s!"{c.oldKind}→{c.newKind}"
let ripTag := if c.rippled then " (rippled)" else ""
IO.println
s!" ~ {pad c.name w} {pad kind 9} {shortAddr verbose c.oldAddr} → {shortAddr verbose c.newAddr} {brackets c.fields}{ripTag}"
if wantMeta && !c.metaFields.isEmpty then
IO.println s!" meta: {brackets c.metaFields}"
let hidden := d.namedChanged.size - shown.size
if hidden > 0 then
IO.println
s!" ({hidden} rippled rows hidden — address changes fully explained by dependency re-addressing; --verbose lists)"
for (n, labels) in d.namedMetaOnly do
IO.println s!" m {pad n w} {brackets labels}"
if shown.any (·.fields.contains "encoding") then
IO.println
" (encoding = representation changed; no semantic field difference detected)"

def runDiffCmd (p : Cli.Parsed) : IO UInt32 := do
let some oldArg := p.positionalArg? "old"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let some newArg := p.positionalArg? "new"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let oldPath := oldArg.as! String
let newPath := newArg.as! String
let wantMeta := p.hasFlag "meta"
if wantMeta && p.hasFlag "anon" then
IO.eprintln "error: --anon and --meta are mutually exclusive"
return 2
let verbose := p.hasFlag "verbose"
-- Byte-equal fast path and the diff itself both run over mmapped
-- files — nothing is read into Lean ByteArrays.
let d ← try
if ← Ixon.rsIxeFilesEqual oldPath newPath then
IO.println "identical"
return (0 : UInt32)
Ixon.rsDiffEnvFiles oldPath newPath wantMeta
catch e =>
IO.eprintln s!"error: {e.toString}"
return (2 : UInt32)
printStats oldPath d.statsA
printStats newPath d.statsB
if d.isEmpty then
if wantMeta then
IO.println "files differ in bytes but no semantic difference found"
else
IO.println
"files differ in bytes but no anonymous-structure difference found (try --meta)"
return 0
if let some (oldMain, newMain) := d.mainChanged then
let fmt : Option Address → String
| none => "∅"
| some a => shortAddr verbose a
IO.println s!"main: {fmt oldMain} → {fmt newMain}"
unless d.assumptionsAdded.isEmpty && d.assumptionsRemoved.isEmpty do
IO.println
s!"assumptions: +{d.assumptionsAdded.size} −{d.assumptionsRemoved.size}"
printAddrList " + " d.assumptionsAdded verbose
printAddrList " - " d.assumptionsRemoved verbose
unless d.namedAdded.isEmpty && d.namedRemoved.isEmpty
&& d.namedChanged.isEmpty && d.namedMetaOnly.isEmpty do
printNamedSection d wantMeta verbose
unless d.commsAdded.isEmpty && d.commsRemoved.isEmpty
&& d.commsChanged.isEmpty do
IO.println
s!"comms: +{d.commsAdded.size} −{d.commsRemoved.size} ~{d.commsChanged.size}"
printAddrList " + " d.commsAdded verbose
printAddrList " - " d.commsRemoved verbose
printAddrList " ~ " d.commsChanged verbose
unless d.constsOnlyA.isEmpty && d.constsOnlyB.isEmpty do
let note :=
if verbose then "" else " (mutual blocks/projections; --verbose lists)"
IO.println
s!"consts: {d.constsOnlyA.size} only in {oldPath}, {d.constsOnlyB.size} only in {newPath}{note}"
if verbose then
printAddrList " - " d.constsOnlyA verbose
printAddrList " + " d.constsOnlyB verbose
unless d.blobsOnlyA.isEmpty && d.blobsOnlyB.isEmpty do
IO.println
s!"blobs: {d.blobsOnlyA.size} only in {oldPath}, {d.blobsOnlyB.size} only in {newPath}"
if verbose then
printAddrList " - " d.blobsOnlyA verbose
printAddrList " + " d.blobsOnlyB verbose
unless d.hintsChanged.isEmpty do
IO.println s!"hints changed: {d.hintsChanged.size}"
let cap := if verbose then d.hintsChanged.size else min d.hintsChanged.size 10
for (a, oldH, newH) in d.hintsChanged[0:cap] do
IO.println s!" {shortAddr verbose a} {oldH} → {newH}"
if d.hintsChanged.size > cap then
IO.println s!" … and {d.hintsChanged.size - cap} more"
IO.println s!"[diff] {oldPath} ≠ {newPath}"
return 1

end Ix.Cli.DiffCmd

open Ix.Cli.DiffCmd in
def diffCmd : Cli.Cmd := `[Cli|
diff VIA runDiffCmd;
"Print a structured diff of two serialized Ixon environments (`.ixe`). By default only anonymous structure is compared: constants by content address (joined through names, with per-field change classification), consts/blobs sets, comms, main/assumptions, and reducibility hints. Changed names are root-caused: rows fully explained by dependency re-addressing are counted as `rippled` and hidden by default, so the listing shows the intrinsic edits (roots). Exit codes: 0 = no difference, 1 = differences found, 2 = error."

FLAGS:
anon; "Compare only anonymous structure (the default; accepted for explicitness)."
«meta»; "Additionally compare named metadata (binder names, originals, kv-maps)."
verbose; "Print full addresses, uncapped lists, synthetic mutual-block names, and rippled changed rows."

ARGS:
old : String; "Path to the first (old) serialized env (`.ixe`)."
new : String; "Path to the second (new) serialized env (`.ixe`)."
]

end
76 changes: 76 additions & 0 deletions Ix/Cli/PackCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
/-
`ix pack <env.ixe> <name>`: prune a serialized env to the self-contained
bundle pinning one named constant, and write it as a standalone `.ixe`.

A bundle is an `.ixe` whose `main` points at a distinguished constant;
because a constant's address is a merkle root over its whole dependency
DAG, `main`'s 32 bytes alone pin the value — the bundle is the
data-availability artifact that ships the bytes. `--assume` declares
trust-boundary cut-points: reached cut-points are recorded in the
bundle's `assumptions` instead of being carried (thin bundles).

The heavy lifting is `Env::prune_to_closure` (3-edge value closure of
`main`, display metadata carried to fixpoint) followed by
`Env::validate_closed` — the same check a receiver runs — so a written
bundle is closed by construction.

Different from `ix shard extract`: extract produces a general sub-env
for the kernel-check pipeline (no `main`, no `assumptions`, anon-work
block closure); pack produces a verified bundle with a root and an
explicit trust boundary.
-/
module
public import Cli
public import Ix.Ixon
public import Ix.Cli.ConstsFile

public section

namespace Ix.Cli.PackCmd

def runPackCmd (p : Cli.Parsed) : IO UInt32 := do
let some pathArg := p.positionalArg? "path"
| p.printError "error: must specify <path> to a source .ixe file"
return 1
let envPath := pathArg.as! String
let some nameArg := p.positionalArg? "name"
| p.printError "error: must specify <name> of the bundle root constant"
return 1
let mainName := nameArg.as! String
let assume ← Ix.Cli.ConstsFile.gather p "assume" "assume-file"
let outPath : String :=
match p.flag? "out" with
| some flag => flag.as! String
| none => s!"{mainName}.ixe"
let anon := p.hasFlag "anon"
let verbose := p.hasFlag "verbose"
try
Ixon.rsPackEnv envPath mainName assume outPath anon verbose
let mode := if anon then " [anon]" else ""
IO.println s!"[pack] wrote {outPath} (main {mainName}, \
{assume.size} assumption cut(s) declared){mode}"
return (0 : UInt32)
catch e =>
IO.eprintln s!"error: {e.toString}"
return (1 : UInt32)

end Ix.Cli.PackCmd

open Ix.Cli.PackCmd in
def packCmd : Cli.Cmd := `[Cli|
pack VIA runPackCmd;
"Prune a `.ixe` env to the self-contained bundle pinning one constant (sets `main`; validated closed)"

FLAGS:
anon; "Pack only anonymous structure — no names or metadata (§4/§5 empty; §3 hints still carried). The minimal artifact a receiver needs to typecheck/evaluate the pinned value."
assume : String; "Comma-separated cut-point constants — displayed names or 64-hex addresses. Reached cut-points are recorded in the bundle's `assumptions` instead of carried (thin bundle)."
"assume-file" : String; "Additionally read cut-points from a file (one per line; `#` comments and blank lines ignored). Unions with --assume."
out : String; "Output `.ixe` path. Defaults to `<name>.ixe` (e.g. `Nat.add.ixe`)."
verbose; "Print pack details (source stats, kept counts, bytes written) to stderr."

ARGS:
path : String; "Path to the source `.ixe` (e.g. from `ix compile`)."
name : String; "Displayed name of the bundle root constant (e.g. `Nat.add`)."
]

end
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions Ix/Cli/DiffCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
/-
`ix diff <old.ixe> <new.ixe>`: structured diff of two serialized Ixon
environments.

The diff itself is computed in Rust (`rs_diff_env_files` →
`ixon::diff`): both files are memory-mapped and lazily parsed
(constant windows stay zero-copy mmap slices; `ConstantMeta` is never
bulk-materialized) and compared on anonymous structure — names serve
as join/display keys, constants compare by content address with
per-field classification (type/value/lvls/…, `block.*` for projection
targets, `"encoding"` when only the representation moved). `--meta`
additionally compares named metadata (`ConstantMeta`/`original`) via
a streaming merge-join over both files' §5 named sections.

Every changed row carries a root-vs-rippled verdict: one edited
constant re-addresses its whole reverse-dependency cone, so most
changed rows are *rippled* (fully explained by dependency
re-addressing) and only the *roots* are intrinsic edits. The default
display lists roots and summarizes the rippled count; `--verbose`
lists rippled rows too, and in `--meta` mode rippled rows carrying
metadata edits stay visible.

Exit codes (GNU diff convention): 0 = no difference found in the
selected mode, 1 = differences found, 2 = error.
-/
module
public import Cli
public import Ix.Address
public import Ix.Common
public import Ix.Ixon

public section

namespace Ix.Cli.DiffCmd

private def pad (s : String) (w : Nat) : String :=
s.pushn ' ' (w - s.length)

private def shortAddr (verbose : Bool) (a : Address) : String :=
if verbose then toString a else ((toString a).take 12).toString ++ "…"

/-- Synthetic mutual-block names embed the block hash as their second
component (`Ix.<64-hex>.…`); a changed block churns one such pair
per block, so the default display groups them into a count. -/
private def isSyntheticMuts (s : String) : Bool :=
match s.splitOn "." with
| "Ix" :: h :: _ =>
h.length == 64 && h.all fun c => c.isDigit || ('a' ≤ c && c ≤ 'f')
| _ => false

private def printStats (path : String) (s : Ixon.EnvStats) : IO Unit :=
IO.println
s!"[diff] {path}: {s.consts} consts, {s.named} named, {s.blobs} blobs, {s.comms} comms"

/-- Print up to `cap` addresses (all when `verbose`), one per line. -/
private def printAddrList
(linePrefix : String) (addrs : Array Address) (verbose : Bool) :
IO Unit := do
let cap := if verbose then addrs.size else min addrs.size 10
for a in addrs[0:cap] do
IO.println s!"{linePrefix}{shortAddr verbose a}"
if addrs.size > cap then
IO.println s!"{linePrefix}… and {addrs.size - cap} more"

private def brackets (labels : Array String) : String :=
"[" ++ ", ".intercalate labels.toList ++ "]"

private def printNamedSection
(d : Ixon.EnvDiff) (wantMeta verbose : Bool) : IO Unit := do
let keep (s : String) : Bool := verbose || !isSyntheticMuts s
let added := d.namedAdded.filter (keep ·.1)
let removed := d.namedRemoved.filter (keep ·.1)
let synAdded := d.namedAdded.size - added.size
let synRemoved := d.namedRemoved.size - removed.size
let roots := d.namedChanged.filter (!·.rippled)
let rippleCount :=
if d.namedChanged.isEmpty then ""
else s!" ({roots.size} roots, {d.namedChanged.size - roots.size} rippled)"
let metaCount :=
if wantMeta then s!", {d.namedMetaOnly.size} metadata-only" else ""
IO.println
s!"named: {d.namedAdded.size} added, {d.namedRemoved.size} removed, {d.namedChanged.size} changed{rippleCount}{metaCount}"
if synAdded + synRemoved > 0 then
IO.println
s!" (synthetic mutual-block names: {synAdded} added, {synRemoved} removed — --verbose lists)"
-- Changed rows shown by default: the roots, plus (under --meta)
-- rippled rows carrying metadata edits — `namedMetaOnly` only covers
-- same-addr rows, so hiding those would hide real metadata changes.
let shown := d.namedChanged.filter fun c =>
verbose || !c.rippled || (wantMeta && !c.metaFields.isEmpty)
-- Column width over everything we are about to print.
let mut wMax := 0
for (n, _) in added do wMax := max wMax n.length
for (n, _) in removed do wMax := max wMax n.length
for c in shown do wMax := max wMax c.name.length
for (n, _) in d.namedMetaOnly do wMax := max wMax n.length
let w := min wMax 40
for (n, addr) in added do
IO.println s!" + {pad n w} {shortAddr verbose addr}"
for (n, addr) in removed do
IO.println s!" - {pad n w} {shortAddr verbose addr}"
for c in shown do
let kind :=
if c.oldKind == c.newKind then c.oldKind
else s!"{c.oldKind}→{c.newKind}"
let ripTag := if c.rippled then " (rippled)" else ""
IO.println
s!" ~ {pad c.name w} {pad kind 9} {shortAddr verbose c.oldAddr} → {shortAddr verbose c.newAddr} {brackets c.fields}{ripTag}"
if wantMeta && !c.metaFields.isEmpty then
IO.println s!" meta: {brackets c.metaFields}"
let hidden := d.namedChanged.size - shown.size
if hidden > 0 then
IO.println
s!" ({hidden} rippled rows hidden — address changes fully explained by dependency re-addressing; --verbose lists)"
for (n, labels) in d.namedMetaOnly do
IO.println s!" m {pad n w} {brackets labels}"
if shown.any (·.fields.contains "encoding") then
IO.println
" (encoding = representation changed; no semantic field difference detected)"

def runDiffCmd (p : Cli.Parsed) : IO UInt32 := do
let some oldArg := p.positionalArg? "old"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let some newArg := p.positionalArg? "new"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let oldPath := oldArg.as! String
let newPath := newArg.as! String
let wantMeta := p.hasFlag "meta"
if wantMeta && p.hasFlag "anon" then
IO.eprintln "error: --anon and --meta are mutually exclusive"
return 2
let verbose := p.hasFlag "verbose"
-- Byte-equal fast path and the diff itself both run over mmapped
-- files — nothing is read into Lean ByteArrays.
let d ← try
if ← Ixon.rsIxeFilesEqual oldPath newPath then
IO.println "identical"
return (0 : UInt32)
Ixon.rsDiffEnvFiles oldPath newPath wantMeta
catch e =>
IO.eprintln s!"error: {e.toString}"
return (2 : UInt32)
printStats oldPath d.statsA
printStats newPath d.statsB
if d.isEmpty then
if wantMeta then
IO.println "files differ in bytes but no semantic difference found"
else
IO.println
"files differ in bytes but no anonymous-structure difference found (try --meta)"
return 0
if let some (oldMain, newMain) := d.mainChanged then
let fmt : Option Address → String
| none => "∅"
| some a => shortAddr verbose a
IO.println s!"main: {fmt oldMain} → {fmt newMain}"
unless d.assumptionsAdded.isEmpty && d.assumptionsRemoved.isEmpty do
IO.println
s!"assumptions: +{d.assumptionsAdded.size} −{d.assumptionsRemoved.size}"
printAddrList " + " d.assumptionsAdded verbose
printAddrList " - " d.assumptionsRemoved verbose
unless d.namedAdded.isEmpty && d.namedRemoved.isEmpty
&& d.namedChanged.isEmpty && d.namedMetaOnly.isEmpty do
printNamedSection d wantMeta verbose
unless d.commsAdded.isEmpty && d.commsRemoved.isEmpty
&& d.commsChanged.isEmpty do
IO.println
s!"comms: +{d.commsAdded.size} −{d.commsRemoved.size} ~{d.commsChanged.size}"
printAddrList " + " d.commsAdded verbose
printAddrList " - " d.commsRemoved verbose
printAddrList " ~ " d.commsChanged verbose
unless d.constsOnlyA.isEmpty && d.constsOnlyB.isEmpty do
let note :=
if verbose then "" else " (mutual blocks/projections; --verbose lists)"
IO.println
s!"consts: {d.constsOnlyA.size} only in {oldPath}, {d.constsOnlyB.size} only in {newPath}{note}"
if verbose then
printAddrList " - " d.constsOnlyA verbose
printAddrList " + " d.constsOnlyB verbose
unless d.blobsOnlyA.isEmpty && d.blobsOnlyB.isEmpty do
IO.println
s!"blobs: {d.blobsOnlyA.size} only in {oldPath}, {d.blobsOnlyB.size} only in {newPath}"
if verbose then
printAddrList " - " d.blobsOnlyA verbose
printAddrList " + " d.blobsOnlyB verbose
unless d.hintsChanged.isEmpty do
IO.println s!"hints changed: {d.hintsChanged.size}"
let cap := if verbose then d.hintsChanged.size else min d.hintsChanged.size 10
for (a, oldH, newH) in d.hintsChanged[0:cap] do
IO.println s!" {shortAddr verbose a} {oldH} → {newH}"
if d.hintsChanged.size > cap then
IO.println s!" … and {d.hintsChanged.size - cap} more"
IO.println s!"[diff] {oldPath} ≠ {newPath}"
return 1

end Ix.Cli.DiffCmd

open Ix.Cli.DiffCmd in
def diffCmd : Cli.Cmd := `[Cli|
diff VIA runDiffCmd;
"Print a structured diff of two serialized Ixon environments (`.ixe`). By default only anonymous structure is compared: constants by content address (joined through names, with per-field change classification), consts/blobs sets, comms, main/assumptions, and reducibility hints. Changed names are root-caused: rows fully explained by dependency re-addressing are counted as `rippled` and hidden by default, so the listing shows the intrinsic edits (roots). Exit codes: 0 = no difference, 1 = differences found, 2 = error."

FLAGS:
anon; "Compare only anonymous structure (the default; accepted for explicitness)."
«meta»; "Additionally compare named metadata (binder names, originals, kv-maps)."
verbose; "Print full addresses, uncapped lists, synthetic mutual-block names, and rippled changed rows."

ARGS:
old : String; "Path to the first (old) serialized env (`.ixe`)."
new : String; "Path to the second (new) serialized env (`.ixe`)."
]

end
76 changes: 76 additions & 0 deletions Ix/Cli/PackCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
/-
`ix pack <env.ixe> <name>`: prune a serialized env to the self-contained
bundle pinning one named constant, and write it as a standalone `.ixe`.

A bundle is an `.ixe` whose `main` points at a distinguished constant;
because a constant's address is a merkle root over its whole dependency
DAG, `main`'s 32 bytes alone pin the value — the bundle is the
data-availability artifact that ships the bytes. `--assume` declares
trust-boundary cut-points: reached cut-points are recorded in the
bundle's `assumptions` instead of being carried (thin bundles).

The heavy lifting is `Env::prune_to_closure` (3-edge value closure of
`main`, display metadata carried to fixpoint) followed by
`Env::validate_closed` — the same check a receiver runs — so a written
bundle is closed by construction.

Different from `ix shard extract`: extract produces a general sub-env
for the kernel-check pipeline (no `main`, no `assumptions`, anon-work
block closure); pack produces a verified bundle with a root and an
explicit trust boundary.
-/
module
public import Cli
public import Ix.Ixon
public import Ix.Cli.ConstsFile

public section

namespace Ix.Cli.PackCmd

def runPackCmd (p : Cli.Parsed) : IO UInt32 := do
let some pathArg := p.positionalArg? "path"
| p.printError "error: must specify <path> to a source .ixe file"
return 1
let envPath := pathArg.as! String
let some nameArg := p.positionalArg? "name"
| p.printError "error: must specify <name> of the bundle root constant"
return 1
let mainName := nameArg.as! String
let assume ← Ix.Cli.ConstsFile.gather p "assume" "assume-file"
let outPath : String :=
match p.flag? "out" with
| some flag => flag.as! String
| none => s!"{mainName}.ixe"
let anon := p.hasFlag "anon"
let verbose := p.hasFlag "verbose"
try
Ixon.rsPackEnv envPath mainName assume outPath anon verbose
let mode := if anon then " [anon]" else ""
IO.println s!"[pack] wrote {outPath} (main {mainName}, \
{assume.size} assumption cut(s) declared){mode}"
return (0 : UInt32)
catch e =>
IO.eprintln s!"error: {e.toString}"
return (1 : UInt32)

end Ix.Cli.PackCmd

open Ix.Cli.PackCmd in
def packCmd : Cli.Cmd := `[Cli|
pack VIA runPackCmd;
"Prune a `.ixe` env to the self-contained bundle pinning one constant (sets `main`; validated closed)"

FLAGS:
anon; "Pack only anonymous structure — no names or metadata (§4/§5 empty; §3 hints still carried). The minimal artifact a receiver needs to typecheck/evaluate the pinned value."
assume : String; "Comma-separated cut-point constants — displayed names or 64-hex addresses. Reached cut-points are recorded in the bundle's `assumptions` instead of carried (thin bundle)."
"assume-file" : String; "Additionally read cut-points from a file (one per line; `#` comments and blank lines ignored). Unions with --assume."
out : String; "Output `.ixe` path. Defaults to `<name>.ixe` (e.g. `Nat.add.ixe`)."
verbose; "Print pack details (source stats, kept counts, bytes written) to stderr."

ARGS:
path : String; "Path to the source `.ixe` (e.g. from `ix compile`)."
name : String; "Displayed name of the bundle root constant (e.g. `Nat.add`)."
]

end
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions Ix/Cli/DiffCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
/-
`ix diff <old.ixe> <new.ixe>`: structured diff of two serialized Ixon
environments.

The diff itself is computed in Rust (`rs_diff_env_files` →
`ixon::diff`): both files are memory-mapped and lazily parsed
(constant windows stay zero-copy mmap slices; `ConstantMeta` is never
bulk-materialized) and compared on anonymous structure — names serve
as join/display keys, constants compare by content address with
per-field classification (type/value/lvls/…, `block.*` for projection
targets, `"encoding"` when only the representation moved). `--meta`
additionally compares named metadata (`ConstantMeta`/`original`) via
a streaming merge-join over both files' §5 named sections.

Every changed row carries a root-vs-rippled verdict: one edited
constant re-addresses its whole reverse-dependency cone, so most
changed rows are *rippled* (fully explained by dependency
re-addressing) and only the *roots* are intrinsic edits. The default
display lists roots and summarizes the rippled count; `--verbose`
lists rippled rows too, and in `--meta` mode rippled rows carrying
metadata edits stay visible.

Exit codes (GNU diff convention): 0 = no difference found in the
selected mode, 1 = differences found, 2 = error.
-/
module
public import Cli
public import Ix.Address
public import Ix.Common
public import Ix.Ixon

public section

namespace Ix.Cli.DiffCmd

private def pad (s : String) (w : Nat) : String :=
s.pushn ' ' (w - s.length)

private def shortAddr (verbose : Bool) (a : Address) : String :=
if verbose then toString a else ((toString a).take 12).toString ++ "…"

/-- Synthetic mutual-block names embed the block hash as their second
component (`Ix.<64-hex>.…`); a changed block churns one such pair
per block, so the default display groups them into a count. -/
private def isSyntheticMuts (s : String) : Bool :=
match s.splitOn "." with
| "Ix" :: h :: _ =>
h.length == 64 && h.all fun c => c.isDigit || ('a' ≤ c && c ≤ 'f')
| _ => false

private def printStats (path : String) (s : Ixon.EnvStats) : IO Unit :=
IO.println
s!"[diff] {path}: {s.consts} consts, {s.named} named, {s.blobs} blobs, {s.comms} comms"

/-- Print up to `cap` addresses (all when `verbose`), one per line. -/
private def printAddrList
(linePrefix : String) (addrs : Array Address) (verbose : Bool) :
IO Unit := do
let cap := if verbose then addrs.size else min addrs.size 10
for a in addrs[0:cap] do
IO.println s!"{linePrefix}{shortAddr verbose a}"
if addrs.size > cap then
IO.println s!"{linePrefix}… and {addrs.size - cap} more"

private def brackets (labels : Array String) : String :=
"[" ++ ", ".intercalate labels.toList ++ "]"

private def printNamedSection
(d : Ixon.EnvDiff) (wantMeta verbose : Bool) : IO Unit := do
let keep (s : String) : Bool := verbose || !isSyntheticMuts s
let added := d.namedAdded.filter (keep ·.1)
let removed := d.namedRemoved.filter (keep ·.1)
let synAdded := d.namedAdded.size - added.size
let synRemoved := d.namedRemoved.size - removed.size
let roots := d.namedChanged.filter (!·.rippled)
let rippleCount :=
if d.namedChanged.isEmpty then ""
else s!" ({roots.size} roots, {d.namedChanged.size - roots.size} rippled)"
let metaCount :=
if wantMeta then s!", {d.namedMetaOnly.size} metadata-only" else ""
IO.println
s!"named: {d.namedAdded.size} added, {d.namedRemoved.size} removed, {d.namedChanged.size} changed{rippleCount}{metaCount}"
if synAdded + synRemoved > 0 then
IO.println
s!" (synthetic mutual-block names: {synAdded} added, {synRemoved} removed — --verbose lists)"
-- Changed rows shown by default: the roots, plus (under --meta)
-- rippled rows carrying metadata edits — `namedMetaOnly` only covers
-- same-addr rows, so hiding those would hide real metadata changes.
let shown := d.namedChanged.filter fun c =>
verbose || !c.rippled || (wantMeta && !c.metaFields.isEmpty)
-- Column width over everything we are about to print.
let mut wMax := 0
for (n, _) in added do wMax := max wMax n.length
for (n, _) in removed do wMax := max wMax n.length
for c in shown do wMax := max wMax c.name.length
for (n, _) in d.namedMetaOnly do wMax := max wMax n.length
let w := min wMax 40
for (n, addr) in added do
IO.println s!" + {pad n w} {shortAddr verbose addr}"
for (n, addr) in removed do
IO.println s!" - {pad n w} {shortAddr verbose addr}"
for c in shown do
let kind :=
if c.oldKind == c.newKind then c.oldKind
else s!"{c.oldKind}→{c.newKind}"
let ripTag := if c.rippled then " (rippled)" else ""
IO.println
s!" ~ {pad c.name w} {pad kind 9} {shortAddr verbose c.oldAddr} → {shortAddr verbose c.newAddr} {brackets c.fields}{ripTag}"
if wantMeta && !c.metaFields.isEmpty then
IO.println s!" meta: {brackets c.metaFields}"
let hidden := d.namedChanged.size - shown.size
if hidden > 0 then
IO.println
s!" ({hidden} rippled rows hidden — address changes fully explained by dependency re-addressing; --verbose lists)"
for (n, labels) in d.namedMetaOnly do
IO.println s!" m {pad n w} {brackets labels}"
if shown.any (·.fields.contains "encoding") then
IO.println
" (encoding = representation changed; no semantic field difference detected)"

def runDiffCmd (p : Cli.Parsed) : IO UInt32 := do
let some oldArg := p.positionalArg? "old"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let some newArg := p.positionalArg? "new"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let oldPath := oldArg.as! String
let newPath := newArg.as! String
let wantMeta := p.hasFlag "meta"
if wantMeta && p.hasFlag "anon" then
IO.eprintln "error: --anon and --meta are mutually exclusive"
return 2
let verbose := p.hasFlag "verbose"
-- Byte-equal fast path and the diff itself both run over mmapped
-- files — nothing is read into Lean ByteArrays.
let d ← try
if ← Ixon.rsIxeFilesEqual oldPath newPath then
IO.println "identical"
return (0 : UInt32)
Ixon.rsDiffEnvFiles oldPath newPath wantMeta
catch e =>
IO.eprintln s!"error: {e.toString}"
return (2 : UInt32)
printStats oldPath d.statsA
printStats newPath d.statsB
if d.isEmpty then
if wantMeta then
IO.println "files differ in bytes but no semantic difference found"
else
IO.println
"files differ in bytes but no anonymous-structure difference found (try --meta)"
return 0
if let some (oldMain, newMain) := d.mainChanged then
let fmt : Option Address → String
| none => "∅"
| some a => shortAddr verbose a
IO.println s!"main: {fmt oldMain} → {fmt newMain}"
unless d.assumptionsAdded.isEmpty && d.assumptionsRemoved.isEmpty do
IO.println
s!"assumptions: +{d.assumptionsAdded.size} −{d.assumptionsRemoved.size}"
printAddrList " + " d.assumptionsAdded verbose
printAddrList " - " d.assumptionsRemoved verbose
unless d.namedAdded.isEmpty && d.namedRemoved.isEmpty
&& d.namedChanged.isEmpty && d.namedMetaOnly.isEmpty do
printNamedSection d wantMeta verbose
unless d.commsAdded.isEmpty && d.commsRemoved.isEmpty
&& d.commsChanged.isEmpty do
IO.println
s!"comms: +{d.commsAdded.size} −{d.commsRemoved.size} ~{d.commsChanged.size}"
printAddrList " + " d.commsAdded verbose
printAddrList " - " d.commsRemoved verbose
printAddrList " ~ " d.commsChanged verbose
unless d.constsOnlyA.isEmpty && d.constsOnlyB.isEmpty do
let note :=
if verbose then "" else " (mutual blocks/projections; --verbose lists)"
IO.println
s!"consts: {d.constsOnlyA.size} only in {oldPath}, {d.constsOnlyB.size} only in {newPath}{note}"
if verbose then
printAddrList " - " d.constsOnlyA verbose
printAddrList " + " d.constsOnlyB verbose
unless d.blobsOnlyA.isEmpty && d.blobsOnlyB.isEmpty do
IO.println
s!"blobs: {d.blobsOnlyA.size} only in {oldPath}, {d.blobsOnlyB.size} only in {newPath}"
if verbose then
printAddrList " - " d.blobsOnlyA verbose
printAddrList " + " d.blobsOnlyB verbose
unless d.hintsChanged.isEmpty do
IO.println s!"hints changed: {d.hintsChanged.size}"
let cap := if verbose then d.hintsChanged.size else min d.hintsChanged.size 10
for (a, oldH, newH) in d.hintsChanged[0:cap] do
IO.println s!" {shortAddr verbose a} {oldH} → {newH}"
if d.hintsChanged.size > cap then
IO.println s!" … and {d.hintsChanged.size - cap} more"
IO.println s!"[diff] {oldPath} ≠ {newPath}"
return 1

end Ix.Cli.DiffCmd

open Ix.Cli.DiffCmd in
def diffCmd : Cli.Cmd := `[Cli|
diff VIA runDiffCmd;
"Print a structured diff of two serialized Ixon environments (`.ixe`). By default only anonymous structure is compared: constants by content address (joined through names, with per-field change classification), consts/blobs sets, comms, main/assumptions, and reducibility hints. Changed names are root-caused: rows fully explained by dependency re-addressing are counted as `rippled` and hidden by default, so the listing shows the intrinsic edits (roots). Exit codes: 0 = no difference, 1 = differences found, 2 = error."

FLAGS:
anon; "Compare only anonymous structure (the default; accepted for explicitness)."
«meta»; "Additionally compare named metadata (binder names, originals, kv-maps)."
verbose; "Print full addresses, uncapped lists, synthetic mutual-block names, and rippled changed rows."

ARGS:
old : String; "Path to the first (old) serialized env (`.ixe`)."
new : String; "Path to the second (new) serialized env (`.ixe`)."
]

end
76 changes: 76 additions & 0 deletions Ix/Cli/PackCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
/-
`ix pack <env.ixe> <name>`: prune a serialized env to the self-contained
bundle pinning one named constant, and write it as a standalone `.ixe`.

A bundle is an `.ixe` whose `main` points at a distinguished constant;
because a constant's address is a merkle root over its whole dependency
DAG, `main`'s 32 bytes alone pin the value — the bundle is the
data-availability artifact that ships the bytes. `--assume` declares
trust-boundary cut-points: reached cut-points are recorded in the
bundle's `assumptions` instead of being carried (thin bundles).

The heavy lifting is `Env::prune_to_closure` (3-edge value closure of
`main`, display metadata carried to fixpoint) followed by
`Env::validate_closed` — the same check a receiver runs — so a written
bundle is closed by construction.

Different from `ix shard extract`: extract produces a general sub-env
for the kernel-check pipeline (no `main`, no `assumptions`, anon-work
block closure); pack produces a verified bundle with a root and an
explicit trust boundary.
-/
module
public import Cli
public import Ix.Ixon
public import Ix.Cli.ConstsFile

public section

namespace Ix.Cli.PackCmd

def runPackCmd (p : Cli.Parsed) : IO UInt32 := do
let some pathArg := p.positionalArg? "path"
| p.printError "error: must specify <path> to a source .ixe file"
return 1
let envPath := pathArg.as! String
let some nameArg := p.positionalArg? "name"
| p.printError "error: must specify <name> of the bundle root constant"
return 1
let mainName := nameArg.as! String
let assume ← Ix.Cli.ConstsFile.gather p "assume" "assume-file"
let outPath : String :=
match p.flag? "out" with
| some flag => flag.as! String
| none => s!"{mainName}.ixe"
let anon := p.hasFlag "anon"
let verbose := p.hasFlag "verbose"
try
Ixon.rsPackEnv envPath mainName assume outPath anon verbose
let mode := if anon then " [anon]" else ""
IO.println s!"[pack] wrote {outPath} (main {mainName}, \
{assume.size} assumption cut(s) declared){mode}"
return (0 : UInt32)
catch e =>
IO.eprintln s!"error: {e.toString}"
return (1 : UInt32)

end Ix.Cli.PackCmd

open Ix.Cli.PackCmd in
def packCmd : Cli.Cmd := `[Cli|
pack VIA runPackCmd;
"Prune a `.ixe` env to the self-contained bundle pinning one constant (sets `main`; validated closed)"

FLAGS:
anon; "Pack only anonymous structure — no names or metadata (§4/§5 empty; §3 hints still carried). The minimal artifact a receiver needs to typecheck/evaluate the pinned value."
assume : String; "Comma-separated cut-point constants — displayed names or 64-hex addresses. Reached cut-points are recorded in the bundle's `assumptions` instead of carried (thin bundle)."
"assume-file" : String; "Additionally read cut-points from a file (one per line; `#` comments and blank lines ignored). Unions with --assume."
out : String; "Output `.ixe` path. Defaults to `<name>.ixe` (e.g. `Nat.add.ixe`)."
verbose; "Print pack details (source stats, kept counts, bytes written) to stderr."

ARGS:
path : String; "Path to the source `.ixe` (e.g. from `ix compile`)."
name : String; "Displayed name of the bundle root constant (e.g. `Nat.add`)."
]

end
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions Ix/Cli/DiffCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
/-
`ix diff <old.ixe> <new.ixe>`: structured diff of two serialized Ixon
environments.

The diff itself is computed in Rust (`rs_diff_env_files` →
`ixon::diff`): both files are memory-mapped and lazily parsed
(constant windows stay zero-copy mmap slices; `ConstantMeta` is never
bulk-materialized) and compared on anonymous structure — names serve
as join/display keys, constants compare by content address with
per-field classification (type/value/lvls/…, `block.*` for projection
targets, `"encoding"` when only the representation moved). `--meta`
additionally compares named metadata (`ConstantMeta`/`original`) via
a streaming merge-join over both files' §5 named sections.

Every changed row carries a root-vs-rippled verdict: one edited
constant re-addresses its whole reverse-dependency cone, so most
changed rows are *rippled* (fully explained by dependency
re-addressing) and only the *roots* are intrinsic edits. The default
display lists roots and summarizes the rippled count; `--verbose`
lists rippled rows too, and in `--meta` mode rippled rows carrying
metadata edits stay visible.

Exit codes (GNU diff convention): 0 = no difference found in the
selected mode, 1 = differences found, 2 = error.
-/
module
public import Cli
public import Ix.Address
public import Ix.Common
public import Ix.Ixon

public section

namespace Ix.Cli.DiffCmd

private def pad (s : String) (w : Nat) : String :=
s.pushn ' ' (w - s.length)

private def shortAddr (verbose : Bool) (a : Address) : String :=
if verbose then toString a else ((toString a).take 12).toString ++ "…"

/-- Synthetic mutual-block names embed the block hash as their second
component (`Ix.<64-hex>.…`); a changed block churns one such pair
per block, so the default display groups them into a count. -/
private def isSyntheticMuts (s : String) : Bool :=
match s.splitOn "." with
| "Ix" :: h :: _ =>
h.length == 64 && h.all fun c => c.isDigit || ('a' ≤ c && c ≤ 'f')
| _ => false

private def printStats (path : String) (s : Ixon.EnvStats) : IO Unit :=
IO.println
s!"[diff] {path}: {s.consts} consts, {s.named} named, {s.blobs} blobs, {s.comms} comms"

/-- Print up to `cap` addresses (all when `verbose`), one per line. -/
private def printAddrList
(linePrefix : String) (addrs : Array Address) (verbose : Bool) :
IO Unit := do
let cap := if verbose then addrs.size else min addrs.size 10
for a in addrs[0:cap] do
IO.println s!"{linePrefix}{shortAddr verbose a}"
if addrs.size > cap then
IO.println s!"{linePrefix}… and {addrs.size - cap} more"

private def brackets (labels : Array String) : String :=
"[" ++ ", ".intercalate labels.toList ++ "]"

private def printNamedSection
(d : Ixon.EnvDiff) (wantMeta verbose : Bool) : IO Unit := do
let keep (s : String) : Bool := verbose || !isSyntheticMuts s
let added := d.namedAdded.filter (keep ·.1)
let removed := d.namedRemoved.filter (keep ·.1)
let synAdded := d.namedAdded.size - added.size
let synRemoved := d.namedRemoved.size - removed.size
let roots := d.namedChanged.filter (!·.rippled)
let rippleCount :=
if d.namedChanged.isEmpty then ""
else s!" ({roots.size} roots, {d.namedChanged.size - roots.size} rippled)"
let metaCount :=
if wantMeta then s!", {d.namedMetaOnly.size} metadata-only" else ""
IO.println
s!"named: {d.namedAdded.size} added, {d.namedRemoved.size} removed, {d.namedChanged.size} changed{rippleCount}{metaCount}"
if synAdded + synRemoved > 0 then
IO.println
s!" (synthetic mutual-block names: {synAdded} added, {synRemoved} removed — --verbose lists)"
-- Changed rows shown by default: the roots, plus (under --meta)
-- rippled rows carrying metadata edits — `namedMetaOnly` only covers
-- same-addr rows, so hiding those would hide real metadata changes.
let shown := d.namedChanged.filter fun c =>
verbose || !c.rippled || (wantMeta && !c.metaFields.isEmpty)
-- Column width over everything we are about to print.
let mut wMax := 0
for (n, _) in added do wMax := max wMax n.length
for (n, _) in removed do wMax := max wMax n.length
for c in shown do wMax := max wMax c.name.length
for (n, _) in d.namedMetaOnly do wMax := max wMax n.length
let w := min wMax 40
for (n, addr) in added do
IO.println s!" + {pad n w} {shortAddr verbose addr}"
for (n, addr) in removed do
IO.println s!" - {pad n w} {shortAddr verbose addr}"
for c in shown do
let kind :=
if c.oldKind == c.newKind then c.oldKind
else s!"{c.oldKind}→{c.newKind}"
let ripTag := if c.rippled then " (rippled)" else ""
IO.println
s!" ~ {pad c.name w} {pad kind 9} {shortAddr verbose c.oldAddr} → {shortAddr verbose c.newAddr} {brackets c.fields}{ripTag}"
if wantMeta && !c.metaFields.isEmpty then
IO.println s!" meta: {brackets c.metaFields}"
let hidden := d.namedChanged.size - shown.size
if hidden > 0 then
IO.println
s!" ({hidden} rippled rows hidden — address changes fully explained by dependency re-addressing; --verbose lists)"
for (n, labels) in d.namedMetaOnly do
IO.println s!" m {pad n w} {brackets labels}"
if shown.any (·.fields.contains "encoding") then
IO.println
" (encoding = representation changed; no semantic field difference detected)"

def runDiffCmd (p : Cli.Parsed) : IO UInt32 := do
let some oldArg := p.positionalArg? "old"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let some newArg := p.positionalArg? "new"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let oldPath := oldArg.as! String
let newPath := newArg.as! String
let wantMeta := p.hasFlag "meta"
if wantMeta && p.hasFlag "anon" then
IO.eprintln "error: --anon and --meta are mutually exclusive"
return 2
let verbose := p.hasFlag "verbose"
-- Byte-equal fast path and the diff itself both run over mmapped
-- files — nothing is read into Lean ByteArrays.
let d ← try
if ← Ixon.rsIxeFilesEqual oldPath newPath then
IO.println "identical"
return (0 : UInt32)
Ixon.rsDiffEnvFiles oldPath newPath wantMeta
catch e =>
IO.eprintln s!"error: {e.toString}"
return (2 : UInt32)
printStats oldPath d.statsA
printStats newPath d.statsB
if d.isEmpty then
if wantMeta then
IO.println "files differ in bytes but no semantic difference found"
else
IO.println
"files differ in bytes but no anonymous-structure difference found (try --meta)"
return 0
if let some (oldMain, newMain) := d.mainChanged then
let fmt : Option Address → String
| none => "∅"
| some a => shortAddr verbose a
IO.println s!"main: {fmt oldMain} → {fmt newMain}"
unless d.assumptionsAdded.isEmpty && d.assumptionsRemoved.isEmpty do
IO.println
s!"assumptions: +{d.assumptionsAdded.size} −{d.assumptionsRemoved.size}"
printAddrList " + " d.assumptionsAdded verbose
printAddrList " - " d.assumptionsRemoved verbose
unless d.namedAdded.isEmpty && d.namedRemoved.isEmpty
&& d.namedChanged.isEmpty && d.namedMetaOnly.isEmpty do
printNamedSection d wantMeta verbose
unless d.commsAdded.isEmpty && d.commsRemoved.isEmpty
&& d.commsChanged.isEmpty do
IO.println
s!"comms: +{d.commsAdded.size} −{d.commsRemoved.size} ~{d.commsChanged.size}"
printAddrList " + " d.commsAdded verbose
printAddrList " - " d.commsRemoved verbose
printAddrList " ~ " d.commsChanged verbose
unless d.constsOnlyA.isEmpty && d.constsOnlyB.isEmpty do
let note :=
if verbose then "" else " (mutual blocks/projections; --verbose lists)"
IO.println
s!"consts: {d.constsOnlyA.size} only in {oldPath}, {d.constsOnlyB.size} only in {newPath}{note}"
if verbose then
printAddrList " - " d.constsOnlyA verbose
printAddrList " + " d.constsOnlyB verbose
unless d.blobsOnlyA.isEmpty && d.blobsOnlyB.isEmpty do
IO.println
s!"blobs: {d.blobsOnlyA.size} only in {oldPath}, {d.blobsOnlyB.size} only in {newPath}"
if verbose then
printAddrList " - " d.blobsOnlyA verbose
printAddrList " + " d.blobsOnlyB verbose
unless d.hintsChanged.isEmpty do
IO.println s!"hints changed: {d.hintsChanged.size}"
let cap := if verbose then d.hintsChanged.size else min d.hintsChanged.size 10
for (a, oldH, newH) in d.hintsChanged[0:cap] do
IO.println s!" {shortAddr verbose a} {oldH} → {newH}"
if d.hintsChanged.size > cap then
IO.println s!" … and {d.hintsChanged.size - cap} more"
IO.println s!"[diff] {oldPath} ≠ {newPath}"
return 1

end Ix.Cli.DiffCmd

open Ix.Cli.DiffCmd in
def diffCmd : Cli.Cmd := `[Cli|
diff VIA runDiffCmd;
"Print a structured diff of two serialized Ixon environments (`.ixe`). By default only anonymous structure is compared: constants by content address (joined through names, with per-field change classification), consts/blobs sets, comms, main/assumptions, and reducibility hints. Changed names are root-caused: rows fully explained by dependency re-addressing are counted as `rippled` and hidden by default, so the listing shows the intrinsic edits (roots). Exit codes: 0 = no difference, 1 = differences found, 2 = error."

FLAGS:
anon; "Compare only anonymous structure (the default; accepted for explicitness)."
«meta»; "Additionally compare named metadata (binder names, originals, kv-maps)."
verbose; "Print full addresses, uncapped lists, synthetic mutual-block names, and rippled changed rows."

ARGS:
old : String; "Path to the first (old) serialized env (`.ixe`)."
new : String; "Path to the second (new) serialized env (`.ixe`)."
]

end
76 changes: 76 additions & 0 deletions Ix/Cli/PackCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
/-
`ix pack <env.ixe> <name>`: prune a serialized env to the self-contained
bundle pinning one named constant, and write it as a standalone `.ixe`.

A bundle is an `.ixe` whose `main` points at a distinguished constant;
because a constant's address is a merkle root over its whole dependency
DAG, `main`'s 32 bytes alone pin the value — the bundle is the
data-availability artifact that ships the bytes. `--assume` declares
trust-boundary cut-points: reached cut-points are recorded in the
bundle's `assumptions` instead of being carried (thin bundles).

The heavy lifting is `Env::prune_to_closure` (3-edge value closure of
`main`, display metadata carried to fixpoint) followed by
`Env::validate_closed` — the same check a receiver runs — so a written
bundle is closed by construction.

Different from `ix shard extract`: extract produces a general sub-env
for the kernel-check pipeline (no `main`, no `assumptions`, anon-work
block closure); pack produces a verified bundle with a root and an
explicit trust boundary.
-/
module
public import Cli
public import Ix.Ixon
public import Ix.Cli.ConstsFile

public section

namespace Ix.Cli.PackCmd

def runPackCmd (p : Cli.Parsed) : IO UInt32 := do
let some pathArg := p.positionalArg? "path"
| p.printError "error: must specify <path> to a source .ixe file"
return 1
let envPath := pathArg.as! String
let some nameArg := p.positionalArg? "name"
| p.printError "error: must specify <name> of the bundle root constant"
return 1
let mainName := nameArg.as! String
let assume ← Ix.Cli.ConstsFile.gather p "assume" "assume-file"
let outPath : String :=
match p.flag? "out" with
| some flag => flag.as! String
| none => s!"{mainName}.ixe"
let anon := p.hasFlag "anon"
let verbose := p.hasFlag "verbose"
try
Ixon.rsPackEnv envPath mainName assume outPath anon verbose
let mode := if anon then " [anon]" else ""
IO.println s!"[pack] wrote {outPath} (main {mainName}, \
{assume.size} assumption cut(s) declared){mode}"
return (0 : UInt32)
catch e =>
IO.eprintln s!"error: {e.toString}"
return (1 : UInt32)

end Ix.Cli.PackCmd

open Ix.Cli.PackCmd in
def packCmd : Cli.Cmd := `[Cli|
pack VIA runPackCmd;
"Prune a `.ixe` env to the self-contained bundle pinning one constant (sets `main`; validated closed)"

FLAGS:
anon; "Pack only anonymous structure — no names or metadata (§4/§5 empty; §3 hints still carried). The minimal artifact a receiver needs to typecheck/evaluate the pinned value."
assume : String; "Comma-separated cut-point constants — displayed names or 64-hex addresses. Reached cut-points are recorded in the bundle's `assumptions` instead of carried (thin bundle)."
"assume-file" : String; "Additionally read cut-points from a file (one per line; `#` comments and blank lines ignored). Unions with --assume."
out : String; "Output `.ixe` path. Defaults to `<name>.ixe` (e.g. `Nat.add.ixe`)."
verbose; "Print pack details (source stats, kept counts, bytes written) to stderr."

ARGS:
path : String; "Path to the source `.ixe` (e.g. from `ix compile`)."
name : String; "Displayed name of the bundle root constant (e.g. `Nat.add`)."
]

end
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions Ix/Cli/DiffCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
/-
`ix diff <old.ixe> <new.ixe>`: structured diff of two serialized Ixon
environments.

The diff itself is computed in Rust (`rs_diff_env_files` →
`ixon::diff`): both files are memory-mapped and lazily parsed
(constant windows stay zero-copy mmap slices; `ConstantMeta` is never
bulk-materialized) and compared on anonymous structure — names serve
as join/display keys, constants compare by content address with
per-field classification (type/value/lvls/…, `block.*` for projection
targets, `"encoding"` when only the representation moved). `--meta`
additionally compares named metadata (`ConstantMeta`/`original`) via
a streaming merge-join over both files' §5 named sections.

Every changed row carries a root-vs-rippled verdict: one edited
constant re-addresses its whole reverse-dependency cone, so most
changed rows are *rippled* (fully explained by dependency
re-addressing) and only the *roots* are intrinsic edits. The default
display lists roots and summarizes the rippled count; `--verbose`
lists rippled rows too, and in `--meta` mode rippled rows carrying
metadata edits stay visible.

Exit codes (GNU diff convention): 0 = no difference found in the
selected mode, 1 = differences found, 2 = error.
-/
module
public import Cli
public import Ix.Address
public import Ix.Common
public import Ix.Ixon

public section

namespace Ix.Cli.DiffCmd

private def pad (s : String) (w : Nat) : String :=
s.pushn ' ' (w - s.length)

private def shortAddr (verbose : Bool) (a : Address) : String :=
if verbose then toString a else ((toString a).take 12).toString ++ "…"

/-- Synthetic mutual-block names embed the block hash as their second
component (`Ix.<64-hex>.…`); a changed block churns one such pair
per block, so the default display groups them into a count. -/
private def isSyntheticMuts (s : String) : Bool :=
match s.splitOn "." with
| "Ix" :: h :: _ =>
h.length == 64 && h.all fun c => c.isDigit || ('a' ≤ c && c ≤ 'f')
| _ => false

private def printStats (path : String) (s : Ixon.EnvStats) : IO Unit :=
IO.println
s!"[diff] {path}: {s.consts} consts, {s.named} named, {s.blobs} blobs, {s.comms} comms"

/-- Print up to `cap` addresses (all when `verbose`), one per line. -/
private def printAddrList
(linePrefix : String) (addrs : Array Address) (verbose : Bool) :
IO Unit := do
let cap := if verbose then addrs.size else min addrs.size 10
for a in addrs[0:cap] do
IO.println s!"{linePrefix}{shortAddr verbose a}"
if addrs.size > cap then
IO.println s!"{linePrefix}… and {addrs.size - cap} more"

private def brackets (labels : Array String) : String :=
"[" ++ ", ".intercalate labels.toList ++ "]"

private def printNamedSection
(d : Ixon.EnvDiff) (wantMeta verbose : Bool) : IO Unit := do
let keep (s : String) : Bool := verbose || !isSyntheticMuts s
let added := d.namedAdded.filter (keep ·.1)
let removed := d.namedRemoved.filter (keep ·.1)
let synAdded := d.namedAdded.size - added.size
let synRemoved := d.namedRemoved.size - removed.size
let roots := d.namedChanged.filter (!·.rippled)
let rippleCount :=
if d.namedChanged.isEmpty then ""
else s!" ({roots.size} roots, {d.namedChanged.size - roots.size} rippled)"
let metaCount :=
if wantMeta then s!", {d.namedMetaOnly.size} metadata-only" else ""
IO.println
s!"named: {d.namedAdded.size} added, {d.namedRemoved.size} removed, {d.namedChanged.size} changed{rippleCount}{metaCount}"
if synAdded + synRemoved > 0 then
IO.println
s!" (synthetic mutual-block names: {synAdded} added, {synRemoved} removed — --verbose lists)"
-- Changed rows shown by default: the roots, plus (under --meta)
-- rippled rows carrying metadata edits — `namedMetaOnly` only covers
-- same-addr rows, so hiding those would hide real metadata changes.
let shown := d.namedChanged.filter fun c =>
verbose || !c.rippled || (wantMeta && !c.metaFields.isEmpty)
-- Column width over everything we are about to print.
let mut wMax := 0
for (n, _) in added do wMax := max wMax n.length
for (n, _) in removed do wMax := max wMax n.length
for c in shown do wMax := max wMax c.name.length
for (n, _) in d.namedMetaOnly do wMax := max wMax n.length
let w := min wMax 40
for (n, addr) in added do
IO.println s!" + {pad n w} {shortAddr verbose addr}"
for (n, addr) in removed do
IO.println s!" - {pad n w} {shortAddr verbose addr}"
for c in shown do
let kind :=
if c.oldKind == c.newKind then c.oldKind
else s!"{c.oldKind}→{c.newKind}"
let ripTag := if c.rippled then " (rippled)" else ""
IO.println
s!" ~ {pad c.name w} {pad kind 9} {shortAddr verbose c.oldAddr} → {shortAddr verbose c.newAddr} {brackets c.fields}{ripTag}"
if wantMeta && !c.metaFields.isEmpty then
IO.println s!" meta: {brackets c.metaFields}"
let hidden := d.namedChanged.size - shown.size
if hidden > 0 then
IO.println
s!" ({hidden} rippled rows hidden — address changes fully explained by dependency re-addressing; --verbose lists)"
for (n, labels) in d.namedMetaOnly do
IO.println s!" m {pad n w} {brackets labels}"
if shown.any (·.fields.contains "encoding") then
IO.println
" (encoding = representation changed; no semantic field difference detected)"

def runDiffCmd (p : Cli.Parsed) : IO UInt32 := do
let some oldArg := p.positionalArg? "old"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let some newArg := p.positionalArg? "new"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let oldPath := oldArg.as! String
let newPath := newArg.as! String
let wantMeta := p.hasFlag "meta"
if wantMeta && p.hasFlag "anon" then
IO.eprintln "error: --anon and --meta are mutually exclusive"
return 2
let verbose := p.hasFlag "verbose"
-- Byte-equal fast path and the diff itself both run over mmapped
-- files — nothing is read into Lean ByteArrays.
let d ← try
if ← Ixon.rsIxeFilesEqual oldPath newPath then
IO.println "identical"
return (0 : UInt32)
Ixon.rsDiffEnvFiles oldPath newPath wantMeta
catch e =>
IO.eprintln s!"error: {e.toString}"
return (2 : UInt32)
printStats oldPath d.statsA
printStats newPath d.statsB
if d.isEmpty then
if wantMeta then
IO.println "files differ in bytes but no semantic difference found"
else
IO.println
"files differ in bytes but no anonymous-structure difference found (try --meta)"
return 0
if let some (oldMain, newMain) := d.mainChanged then
let fmt : Option Address → String
| none => "∅"
| some a => shortAddr verbose a
IO.println s!"main: {fmt oldMain} → {fmt newMain}"
unless d.assumptionsAdded.isEmpty && d.assumptionsRemoved.isEmpty do
IO.println
s!"assumptions: +{d.assumptionsAdded.size} −{d.assumptionsRemoved.size}"
printAddrList " + " d.assumptionsAdded verbose
printAddrList " - " d.assumptionsRemoved verbose
unless d.namedAdded.isEmpty && d.namedRemoved.isEmpty
&& d.namedChanged.isEmpty && d.namedMetaOnly.isEmpty do
printNamedSection d wantMeta verbose
unless d.commsAdded.isEmpty && d.commsRemoved.isEmpty
&& d.commsChanged.isEmpty do
IO.println
s!"comms: +{d.commsAdded.size} −{d.commsRemoved.size} ~{d.commsChanged.size}"
printAddrList " + " d.commsAdded verbose
printAddrList " - " d.commsRemoved verbose
printAddrList " ~ " d.commsChanged verbose
unless d.constsOnlyA.isEmpty && d.constsOnlyB.isEmpty do
let note :=
if verbose then "" else " (mutual blocks/projections; --verbose lists)"
IO.println
s!"consts: {d.constsOnlyA.size} only in {oldPath}, {d.constsOnlyB.size} only in {newPath}{note}"
if verbose then
printAddrList " - " d.constsOnlyA verbose
printAddrList " + " d.constsOnlyB verbose
unless d.blobsOnlyA.isEmpty && d.blobsOnlyB.isEmpty do
IO.println
s!"blobs: {d.blobsOnlyA.size} only in {oldPath}, {d.blobsOnlyB.size} only in {newPath}"
if verbose then
printAddrList " - " d.blobsOnlyA verbose
printAddrList " + " d.blobsOnlyB verbose
unless d.hintsChanged.isEmpty do
IO.println s!"hints changed: {d.hintsChanged.size}"
let cap := if verbose then d.hintsChanged.size else min d.hintsChanged.size 10
for (a, oldH, newH) in d.hintsChanged[0:cap] do
IO.println s!" {shortAddr verbose a} {oldH} → {newH}"
if d.hintsChanged.size > cap then
IO.println s!" … and {d.hintsChanged.size - cap} more"
IO.println s!"[diff] {oldPath} ≠ {newPath}"
return 1

end Ix.Cli.DiffCmd

open Ix.Cli.DiffCmd in
def diffCmd : Cli.Cmd := `[Cli|
diff VIA runDiffCmd;
"Print a structured diff of two serialized Ixon environments (`.ixe`). By default only anonymous structure is compared: constants by content address (joined through names, with per-field change classification), consts/blobs sets, comms, main/assumptions, and reducibility hints. Changed names are root-caused: rows fully explained by dependency re-addressing are counted as `rippled` and hidden by default, so the listing shows the intrinsic edits (roots). Exit codes: 0 = no difference, 1 = differences found, 2 = error."

FLAGS:
anon; "Compare only anonymous structure (the default; accepted for explicitness)."
«meta»; "Additionally compare named metadata (binder names, originals, kv-maps)."
verbose; "Print full addresses, uncapped lists, synthetic mutual-block names, and rippled changed rows."

ARGS:
old : String; "Path to the first (old) serialized env (`.ixe`)."
new : String; "Path to the second (new) serialized env (`.ixe`)."
]

end
76 changes: 76 additions & 0 deletions Ix/Cli/PackCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
/-
`ix pack <env.ixe> <name>`: prune a serialized env to the self-contained
bundle pinning one named constant, and write it as a standalone `.ixe`.

A bundle is an `.ixe` whose `main` points at a distinguished constant;
because a constant's address is a merkle root over its whole dependency
DAG, `main`'s 32 bytes alone pin the value — the bundle is the
data-availability artifact that ships the bytes. `--assume` declares
trust-boundary cut-points: reached cut-points are recorded in the
bundle's `assumptions` instead of being carried (thin bundles).

The heavy lifting is `Env::prune_to_closure` (3-edge value closure of
`main`, display metadata carried to fixpoint) followed by
`Env::validate_closed` — the same check a receiver runs — so a written
bundle is closed by construction.

Different from `ix shard extract`: extract produces a general sub-env
for the kernel-check pipeline (no `main`, no `assumptions`, anon-work
block closure); pack produces a verified bundle with a root and an
explicit trust boundary.
-/
module
public import Cli
public import Ix.Ixon
public import Ix.Cli.ConstsFile

public section

namespace Ix.Cli.PackCmd

def runPackCmd (p : Cli.Parsed) : IO UInt32 := do
let some pathArg := p.positionalArg? "path"
| p.printError "error: must specify <path> to a source .ixe file"
return 1
let envPath := pathArg.as! String
let some nameArg := p.positionalArg? "name"
| p.printError "error: must specify <name> of the bundle root constant"
return 1
let mainName := nameArg.as! String
let assume ← Ix.Cli.ConstsFile.gather p "assume" "assume-file"
let outPath : String :=
match p.flag? "out" with
| some flag => flag.as! String
| none => s!"{mainName}.ixe"
let anon := p.hasFlag "anon"
let verbose := p.hasFlag "verbose"
try
Ixon.rsPackEnv envPath mainName assume outPath anon verbose
let mode := if anon then " [anon]" else ""
IO.println s!"[pack] wrote {outPath} (main {mainName}, \
{assume.size} assumption cut(s) declared){mode}"
return (0 : UInt32)
catch e =>
IO.eprintln s!"error: {e.toString}"
return (1 : UInt32)

end Ix.Cli.PackCmd

open Ix.Cli.PackCmd in
def packCmd : Cli.Cmd := `[Cli|
pack VIA runPackCmd;
"Prune a `.ixe` env to the self-contained bundle pinning one constant (sets `main`; validated closed)"

FLAGS:
anon; "Pack only anonymous structure — no names or metadata (§4/§5 empty; §3 hints still carried). The minimal artifact a receiver needs to typecheck/evaluate the pinned value."
assume : String; "Comma-separated cut-point constants — displayed names or 64-hex addresses. Reached cut-points are recorded in the bundle's `assumptions` instead of carried (thin bundle)."
"assume-file" : String; "Additionally read cut-points from a file (one per line; `#` comments and blank lines ignored). Unions with --assume."
out : String; "Output `.ixe` path. Defaults to `<name>.ixe` (e.g. `Nat.add.ixe`)."
verbose; "Print pack details (source stats, kept counts, bytes written) to stderr."

ARGS:
path : String; "Path to the source `.ixe` (e.g. from `ix compile`)."
name : String; "Displayed name of the bundle root constant (e.g. `Nat.add`)."
]

end
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions Ix/Cli/DiffCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
/-
`ix diff <old.ixe> <new.ixe>`: structured diff of two serialized Ixon
environments.

The diff itself is computed in Rust (`rs_diff_env_files` →
`ixon::diff`): both files are memory-mapped and lazily parsed
(constant windows stay zero-copy mmap slices; `ConstantMeta` is never
bulk-materialized) and compared on anonymous structure — names serve
as join/display keys, constants compare by content address with
per-field classification (type/value/lvls/…, `block.*` for projection
targets, `"encoding"` when only the representation moved). `--meta`
additionally compares named metadata (`ConstantMeta`/`original`) via
a streaming merge-join over both files' §5 named sections.

Every changed row carries a root-vs-rippled verdict: one edited
constant re-addresses its whole reverse-dependency cone, so most
changed rows are *rippled* (fully explained by dependency
re-addressing) and only the *roots* are intrinsic edits. The default
display lists roots and summarizes the rippled count; `--verbose`
lists rippled rows too, and in `--meta` mode rippled rows carrying
metadata edits stay visible.

Exit codes (GNU diff convention): 0 = no difference found in the
selected mode, 1 = differences found, 2 = error.
-/
module
public import Cli
public import Ix.Address
public import Ix.Common
public import Ix.Ixon

public section

namespace Ix.Cli.DiffCmd

private def pad (s : String) (w : Nat) : String :=
s.pushn ' ' (w - s.length)

private def shortAddr (verbose : Bool) (a : Address) : String :=
if verbose then toString a else ((toString a).take 12).toString ++ "…"

/-- Synthetic mutual-block names embed the block hash as their second
component (`Ix.<64-hex>.…`); a changed block churns one such pair
per block, so the default display groups them into a count. -/
private def isSyntheticMuts (s : String) : Bool :=
match s.splitOn "." with
| "Ix" :: h :: _ =>
h.length == 64 && h.all fun c => c.isDigit || ('a' ≤ c && c ≤ 'f')
| _ => false

private def printStats (path : String) (s : Ixon.EnvStats) : IO Unit :=
IO.println
s!"[diff] {path}: {s.consts} consts, {s.named} named, {s.blobs} blobs, {s.comms} comms"

/-- Print up to `cap` addresses (all when `verbose`), one per line. -/
private def printAddrList
(linePrefix : String) (addrs : Array Address) (verbose : Bool) :
IO Unit := do
let cap := if verbose then addrs.size else min addrs.size 10
for a in addrs[0:cap] do
IO.println s!"{linePrefix}{shortAddr verbose a}"
if addrs.size > cap then
IO.println s!"{linePrefix}… and {addrs.size - cap} more"

private def brackets (labels : Array String) : String :=
"[" ++ ", ".intercalate labels.toList ++ "]"

private def printNamedSection
(d : Ixon.EnvDiff) (wantMeta verbose : Bool) : IO Unit := do
let keep (s : String) : Bool := verbose || !isSyntheticMuts s
let added := d.namedAdded.filter (keep ·.1)
let removed := d.namedRemoved.filter (keep ·.1)
let synAdded := d.namedAdded.size - added.size
let synRemoved := d.namedRemoved.size - removed.size
let roots := d.namedChanged.filter (!·.rippled)
let rippleCount :=
if d.namedChanged.isEmpty then ""
else s!" ({roots.size} roots, {d.namedChanged.size - roots.size} rippled)"
let metaCount :=
if wantMeta then s!", {d.namedMetaOnly.size} metadata-only" else ""
IO.println
s!"named: {d.namedAdded.size} added, {d.namedRemoved.size} removed, {d.namedChanged.size} changed{rippleCount}{metaCount}"
if synAdded + synRemoved > 0 then
IO.println
s!" (synthetic mutual-block names: {synAdded} added, {synRemoved} removed — --verbose lists)"
-- Changed rows shown by default: the roots, plus (under --meta)
-- rippled rows carrying metadata edits — `namedMetaOnly` only covers
-- same-addr rows, so hiding those would hide real metadata changes.
let shown := d.namedChanged.filter fun c =>
verbose || !c.rippled || (wantMeta && !c.metaFields.isEmpty)
-- Column width over everything we are about to print.
let mut wMax := 0
for (n, _) in added do wMax := max wMax n.length
for (n, _) in removed do wMax := max wMax n.length
for c in shown do wMax := max wMax c.name.length
for (n, _) in d.namedMetaOnly do wMax := max wMax n.length
let w := min wMax 40
for (n, addr) in added do
IO.println s!" + {pad n w} {shortAddr verbose addr}"
for (n, addr) in removed do
IO.println s!" - {pad n w} {shortAddr verbose addr}"
for c in shown do
let kind :=
if c.oldKind == c.newKind then c.oldKind
else s!"{c.oldKind}→{c.newKind}"
let ripTag := if c.rippled then " (rippled)" else ""
IO.println
s!" ~ {pad c.name w} {pad kind 9} {shortAddr verbose c.oldAddr} → {shortAddr verbose c.newAddr} {brackets c.fields}{ripTag}"
if wantMeta && !c.metaFields.isEmpty then
IO.println s!" meta: {brackets c.metaFields}"
let hidden := d.namedChanged.size - shown.size
if hidden > 0 then
IO.println
s!" ({hidden} rippled rows hidden — address changes fully explained by dependency re-addressing; --verbose lists)"
for (n, labels) in d.namedMetaOnly do
IO.println s!" m {pad n w} {brackets labels}"
if shown.any (·.fields.contains "encoding") then
IO.println
" (encoding = representation changed; no semantic field difference detected)"

def runDiffCmd (p : Cli.Parsed) : IO UInt32 := do
let some oldArg := p.positionalArg? "old"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let some newArg := p.positionalArg? "new"
| p.printError "error: must specify <old.ixe> <new.ixe>"; return 2
let oldPath := oldArg.as! String
let newPath := newArg.as! String
let wantMeta := p.hasFlag "meta"
if wantMeta && p.hasFlag "anon" then
IO.eprintln "error: --anon and --meta are mutually exclusive"
return 2
let verbose := p.hasFlag "verbose"
-- Byte-equal fast path and the diff itself both run over mmapped
-- files — nothing is read into Lean ByteArrays.
let d ← try
if ← Ixon.rsIxeFilesEqual oldPath newPath then
IO.println "identical"
return (0 : UInt32)
Ixon.rsDiffEnvFiles oldPath newPath wantMeta
catch e =>
IO.eprintln s!"error: {e.toString}"
return (2 : UInt32)
printStats oldPath d.statsA
printStats newPath d.statsB
if d.isEmpty then
if wantMeta then
IO.println "files differ in bytes but no semantic difference found"
else
IO.println
"files differ in bytes but no anonymous-structure difference found (try --meta)"
return 0
if let some (oldMain, newMain) := d.mainChanged then
let fmt : Option Address → String
| none => "∅"
| some a => shortAddr verbose a
IO.println s!"main: {fmt oldMain} → {fmt newMain}"
unless d.assumptionsAdded.isEmpty && d.assumptionsRemoved.isEmpty do
IO.println
s!"assumptions: +{d.assumptionsAdded.size} −{d.assumptionsRemoved.size}"
printAddrList " + " d.assumptionsAdded verbose
printAddrList " - " d.assumptionsRemoved verbose
unless d.namedAdded.isEmpty && d.namedRemoved.isEmpty
&& d.namedChanged.isEmpty && d.namedMetaOnly.isEmpty do
printNamedSection d wantMeta verbose
unless d.commsAdded.isEmpty && d.commsRemoved.isEmpty
&& d.commsChanged.isEmpty do
IO.println
s!"comms: +{d.commsAdded.size} −{d.commsRemoved.size} ~{d.commsChanged.size}"
printAddrList " + " d.commsAdded verbose
printAddrList " - " d.commsRemoved verbose
printAddrList " ~ " d.commsChanged verbose
unless d.constsOnlyA.isEmpty && d.constsOnlyB.isEmpty do
let note :=
if verbose then "" else " (mutual blocks/projections; --verbose lists)"
IO.println
s!"consts: {d.constsOnlyA.size} only in {oldPath}, {d.constsOnlyB.size} only in {newPath}{note}"
if verbose then
printAddrList " - " d.constsOnlyA verbose
printAddrList " + " d.constsOnlyB verbose
unless d.blobsOnlyA.isEmpty && d.blobsOnlyB.isEmpty do
IO.println
s!"blobs: {d.blobsOnlyA.size} only in {oldPath}, {d.blobsOnlyB.size} only in {newPath}"
if verbose then
printAddrList " - " d.blobsOnlyA verbose
printAddrList " + " d.blobsOnlyB verbose
unless d.hintsChanged.isEmpty do
IO.println s!"hints changed: {d.hintsChanged.size}"
let cap := if verbose then d.hintsChanged.size else min d.hintsChanged.size 10
for (a, oldH, newH) in d.hintsChanged[0:cap] do
IO.println s!" {shortAddr verbose a} {oldH} → {newH}"
if d.hintsChanged.size > cap then
IO.println s!" … and {d.hintsChanged.size - cap} more"
IO.println s!"[diff] {oldPath} ≠ {newPath}"
return 1

end Ix.Cli.DiffCmd

open Ix.Cli.DiffCmd in
def diffCmd : Cli.Cmd := `[Cli|
diff VIA runDiffCmd;
"Print a structured diff of two serialized Ixon environments (`.ixe`). By default only anonymous structure is compared: constants by content address (joined through names, with per-field change classification), consts/blobs sets, comms, main/assumptions, and reducibility hints. Changed names are root-caused: rows fully explained by dependency re-addressing are counted as `rippled` and hidden by default, so the listing shows the intrinsic edits (roots). Exit codes: 0 = no difference, 1 = differences found, 2 = error."

FLAGS:
anon; "Compare only anonymous structure (the default; accepted for explicitness)."
«meta»; "Additionally compare named metadata (binder names, originals, kv-maps)."
verbose; "Print full addresses, uncapped lists, synthetic mutual-block names, and rippled changed rows."

ARGS:
old : String; "Path to the first (old) serialized env (`.ixe`)."
new : String; "Path to the second (new) serialized env (`.ixe`)."
]

end
76 changes: 76 additions & 0 deletions Ix/Cli/PackCmd.lean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
/-
`ix pack <env.ixe> <name>`: prune a serialized env to the self-contained
bundle pinning one named constant, and write it as a standalone `.ixe`.

A bundle is an `.ixe` whose `main` points at a distinguished constant;
because a constant's address is a merkle root over its whole dependency
DAG, `main`'s 32 bytes alone pin the value — the bundle is the
data-availability artifact that ships the bytes. `--assume` declares
trust-boundary cut-points: reached cut-points are recorded in the
bundle's `assumptions` instead of being carried (thin bundles).

The heavy lifting is `Env::prune_to_closure` (3-edge value closure of
`main`, display metadata carried to fixpoint) followed by
`Env::validate_closed` — the same check a receiver runs — so a written
bundle is closed by construction.

Different from `ix shard extract`: extract produces a general sub-env
for the kernel-check pipeline (no `main`, no `assumptions`, anon-work
block closure); pack produces a verified bundle with a root and an
explicit trust boundary.
-/
module
public import Cli
public import Ix.Ixon
public import Ix.Cli.ConstsFile

public section

namespace Ix.Cli.PackCmd

def runPackCmd (p : Cli.Parsed) : IO UInt32 := do
let some pathArg := p.positionalArg? "path"
| p.printError "error: must specify <path> to a source .ixe file"
return 1
let envPath := pathArg.as! String
let some nameArg := p.positionalArg? "name"
| p.printError "error: must specify <name> of the bundle root constant"
return 1
let mainName := nameArg.as! String
let assume ← Ix.Cli.ConstsFile.gather p "assume" "assume-file"
let outPath : String :=
match p.flag? "out" with
| some flag => flag.as! String
| none => s!"{mainName}.ixe"
let anon := p.hasFlag "anon"
let verbose := p.hasFlag "verbose"
try
Ixon.rsPackEnv envPath mainName assume outPath anon verbose
let mode := if anon then " [anon]" else ""
IO.println s!"[pack] wrote {outPath} (main {mainName}, \
{assume.size} assumption cut(s) declared){mode}"
return (0 : UInt32)
catch e =>
IO.eprintln s!"error: {e.toString}"
return (1 : UInt32)

end Ix.Cli.PackCmd

open Ix.Cli.PackCmd in
def packCmd : Cli.Cmd := `[Cli|
pack VIA runPackCmd;
"Prune a `.ixe` env to the self-contained bundle pinning one constant (sets `main`; validated closed)"

FLAGS:
anon; "Pack only anonymous structure — no names or metadata (§4/§5 empty; §3 hints still carried). The minimal artifact a receiver needs to typecheck/evaluate the pinned value."
assume : String; "Comma-separated cut-point constants — displayed names or 64-hex addresses. Reached cut-points are recorded in the bundle's `assumptions` instead of carried (thin bundle)."
"assume-file" : String; "Additionally read cut-points from a file (one per line; `#` comments and blank lines ignored). Unions with --assume."
out : String; "Output `.ixe` path. Defaults to `<name>.ixe` (e.g. `Nat.add.ixe`)."
verbose; "Print pack details (source stats, kept counts, bytes written) to stderr."

ARGS:
path : String; "Path to the source `.ixe` (e.g. from `ix compile`)."
name : String; "Displayed name of the bundle root constant (e.g. `Nat.add`)."
]

end
Loading