Skip to content

feat(formal): real-lift R1 — first real ⟦compile p⟧ = ⟦p⟧ (RealCompile.v)#640

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/lucid-cray-4a22dp
Jun 21, 2026
Merged

feat(formal): real-lift R1 — first real ⟦compile p⟧ = ⟦p⟧ (RealCompile.v)#640
hyperpolymath merged 1 commit into
mainfrom
claude/lucid-cray-4a22dp

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What

Climbs the REAL-LIFT ladder (formal/REAL-LIFT.adoc) from R0 → R1: the first mechanized ⟦compile p⟧ = ⟦p⟧ on the real objects — the actual lib/wasm.ml instruction IR and the real (resolved) lib/ast.ml expression core. This retires the toy K1/K1Let on real objects.

RealWasm.v (grown for R1)

Adds locals (LocalGet/LocalSet) and the comparison ops I32Eq/I32LtS, threading a mutable locals store through wexec. wexec is refactored through a per-instruction step1, so the sequencing lemmas wexec_app / wexec_seq (which the preservation proof composes with) are one line each. wexec_sound (R0) is retained for the pure (no_local) fragment.

RealCompile.v (new, R1)

  • rexpr — the resolved int/bool/let/binary core of lib/ast.ml (de Bruijn levels; name resolution is a separate obligation, P-7; bool ≔ 0/1, int ≔ Z, so one observable);
  • eval — the reference dynamic semantics (mirrors lib/interp.ml);
  • compile — lowers let to LocalSet d into a pre-sized locals array (slot = binding depth d; siblings reuse slots), mirroring lib/codegen.ml;
  • compile_correct — the theorem:
eval env e = Some v  →  agree env locals  →  |env| = d  →  d + depth e ≤ |locals| →
  ∃ locals', wexec (compile d e) locals st = Some (locals', v :: st)
           ∧ |locals'| = |locals| ∧ (∀ i < d, nth_error locals' i = nth_error locals i)

carrying an env↔locals agreement invariant with fresh-slot allocation and low-slot preservation through the induction (the genuine compiler-correctness simulation);

  • compile_program_correct — runs a closed program from the zero-initialised locals array.

Concrete end-to-end check (let x = 2+3 in x*4 ⇒ 20): r1_eval_demo (source) and r1_exec_demo (compile then wexec[20]).

Honest scope

R1 is the int/bool/let/binop fragment on de Bruijn-resolved source; LocalTee/i64, structured control, memory, floats, calls, and effects are later rungs (REAL-LIFT.adoc §4). R2 (structured control on a fuel-indexed wexec) is next, and is the rung that settles #601 concretely.

Verification

All axiom-free — every Print Assumptions reports Closed under the global context. formal/ now 17 files, 29 closure reports (full dep-order recompile, no Axioms:). Wired into _CoqProject / justfile / .hypatia-ignore; README.adoc, REAL-LIFT.adoc (R1 landed, R2 next), and PROOF-NEEDS.adoc (K-1 row, §1, §6 Wave 3) updated.

Follow-on to #638 (R0 + plan, merged). QTT-dynamic #637 ✅ → F-5 + R0 #638 ✅ → **R1 (this)**.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr


Generated by Claude Code

@hyperpolymath hyperpolymath marked this pull request as ready for review June 21, 2026 17:40
@github-actions

Copy link
Copy Markdown

🔍 Hypatia Security Scan

Findings: 41 issues detected

Severity Count
🔴 Critical 2
🟠 High 23
🟡 Medium 16

⚠️ Action Required: Critical security issues found!

View findings
[
  {
    "reason": "Action denoland/setup-deno@v2 needs attention",
    "type": "unpinned_action",
    "file": "publish-jsr.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in instant-sync.yml",
    "type": "secret_action_without_presence_gate",
    "file": "instant-sync.yml",
    "action": "peter-evans/repository-dispatch",
    "rule_module": "workflow_audit",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/packages/affinescript-cli/mod.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (2 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/packages/affine-vscode/mod.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-vite/src/affine-plugin-improved.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "expect() in hot path (32 occurrences, CWE-754)",
    "type": "expect_in_hot_path",
    "file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/wasm_gen.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "expect() in hot path (29 occurrences, CWE-754)",
    "type": "expect_in_hot_path",
    "file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/affine_gen.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (2 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/panic.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (1 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/alloc.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (3 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/ffi.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  }
]

Powered by Hypatia Neurosymbolic CI/CD Intelligence

…e.v)

Climbs the REAL-LIFT ladder (formal/REAL-LIFT.adoc) from R0 to R1: the first
mechanized codegen-preservation theorem on the REAL objects — the actual
lib/wasm.ml instruction IR and the real (resolved) lib/ast.ml expression core —
retiring the toy K1/K1Let on real objects.

RealWasm.v (grown): adds locals (LocalGet/LocalSet) and the comparison ops
I32Eq/I32LtS, threading a mutable locals store through wexec. wexec is refactored
through a per-instruction step1 so the sequencing lemmas wexec_app/wexec_seq
(which the preservation proof composes with) are one line each. wexec_sound is
retained for the pure (no_local) fragment.

RealCompile.v (new, R1):
- source rexpr: the resolved int/bool/let/binary core of lib/ast.ml (de Bruijn
  LEVELS — name resolution is P-7; bool = 0/1, int = Z);
- eval: the reference dynamic semantics (mirrors lib/interp.ml);
- compile: lowers let to LocalSet into a pre-sized locals array (slot = binding
  depth; siblings reuse slots), mirroring lib/codegen.ml;
- compile_correct: eval env e = Some v -> wexec (compile |env| e) locals st
  = Some (locals', v :: st), carrying an env<->locals agreement invariant with
  fresh-slot allocation and low-slot preservation through the induction;
- compile_program_correct: runs a closed program from the zero-initialised array.

All axiom-free (Print Assumptions: Closed under the global context). formal/ now
17 files, 29 closure reports. Wired into _CoqProject / justfile / .hypatia-ignore
/ README.adoc; REAL-LIFT.adoc (R1 landed, R2 next) + PROOF-NEEDS.adoc (K-1 row,
section 6 Wave 3) updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr
@hyperpolymath hyperpolymath force-pushed the claude/lucid-cray-4a22dp branch from 0f902e0 to bc3ec78 Compare June 21, 2026 17:51
@hyperpolymath hyperpolymath merged commit 5a42e6e into main Jun 21, 2026
13 checks passed
@hyperpolymath hyperpolymath deleted the claude/lucid-cray-4a22dp branch June 21, 2026 17:51
@github-actions

Copy link
Copy Markdown

🔍 Hypatia Security Scan

Findings: 41 issues detected

Severity Count
🔴 Critical 2
🟠 High 23
🟡 Medium 16

⚠️ Action Required: Critical security issues found!

View findings
[
  {
    "reason": "Action denoland/setup-deno@v2 needs attention",
    "type": "unpinned_action",
    "file": "publish-jsr.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in instant-sync.yml",
    "type": "secret_action_without_presence_gate",
    "file": "instant-sync.yml",
    "action": "peter-evans/repository-dispatch",
    "rule_module": "workflow_audit",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/packages/affinescript-cli/mod.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (2 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/packages/affine-vscode/mod.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-vite/src/affine-plugin-improved.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "expect() in hot path (32 occurrences, CWE-754)",
    "type": "expect_in_hot_path",
    "file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/wasm_gen.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "expect() in hot path (29 occurrences, CWE-754)",
    "type": "expect_in_hot_path",
    "file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/affine_gen.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (2 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/panic.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (1 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/alloc.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (3 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/ffi.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  }
]

Powered by Hypatia Neurosymbolic CI/CD Intelligence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant