Skip to content

Research: bounded superoptimization of pure OwnIR transfer helpers (enumeration / e-graphs / SMT) #459

Open

Description

@PhysShell

Classification

Hypothesis

For one demonstrably expensive, pure helper, a narrowly defined expression grammar plus semantic deduplication can reveal an equivalent cheaper implementation that manual refactoring or the compiler misses. This is not a proposal to rewrite the ownership analysis or its diagnostic semantics.

The blog enumerates expressions, deduplicates by vectors of results on ~20 tests and manually identifies subexpression reuse. Test-vector equality is a search heuristic, not proof. A four-operation expression also need not mean a faster machine-code implementation.

Kill-first protocol

  1. Establish need: profile existing workload and identify at most 1–2 actual hot pure functions (e.g., a state-transition/bitset helper only if one really exists). Pin code SHA, inputs, benchmark harness and semantics. KILL immediately if there is no meaningful hot spot or a standard compiler optimization already solves it.
  2. Fix semantics: specify allowed inputs, integer widths, overflow/shift behavior, undefined/invalid states, order/side effects, and target runtime. Exclude allocations, exceptions, aliases, lifetime/Dispose effects, interprocedural and WPF behavior from synthesis.
  3. Small search: restricted operators/constants; enumerate trees or use e-graph rewriting; retain shared-subexpression DAGs in cost accounting; deduplicate by test-output vectors; generate edge cases and counterexamples.
  4. Independent validation: exhaustive evaluation on a tractable bounded domain or SMT proof under explicit assumptions, plus compiler/build tests and differential/metamorphic regression. If equivalence is unproved, label UNVERIFIED and do not propose production replacement. Alive2 only if the candidate has genuinely equivalent LLVM IR semantics; no automatic claim of .NET/Rust proof.
  5. Measure: compare current implementation, optimized compiler baseline and generated candidate on representative workloads. Record correctness verdict, counterexamples, instruction count where meaningful, latency, throughput, allocation, memory, portability and maintainability cost.

Deliverables / decision gate

  • Reproducible self-contained spike with frozen inputs, exact versions/SHAs, candidate grammar and results.
  • Candidate + counterexample/proof receipt + before/after benchmark, or a documented negative result.
  • GO only for a verified rewrite with reproducible useful improvement and acceptable complexity; CHANGE for a reusable verifier/test generator only; KILL for no hot spot, insufficient proof, or negligible benefit.
  • No production integration, broad synthesis framework, or auto-fix roll-out as part of this issue.

A separate, architecture-level code-pattern recommender is documented in Pattern-Aware Refactoring; that is not Own.NET's remit.

Activity

  1. PhysShell commented on Nov 15, 2026

    @PhysShell
    OwnerAuthor

    Additional prior art: OpenEvolve (Asankhaya Sharma)

    Source: algorithmicsuperintelligence/openevolve, an LLM-guided evolutionary program-search framework with external evaluators and population-based search.

    Please treat this as an optional search baseline inside #459, not a new optimization project. The existing issue's pure, explicitly specified OwnIR helper / independent semantic-equivalence gate stays authoritative.

    Suggested comparison only after #459 identifies a real measured hotspot and a trusted oracle:

    1. A: current implementation + compiler optimization; B: bounded enumerative/e-graph/SMT search already specified in Research: bounded superoptimization of pure OwnIR transfer helpers (enumeration / e-graphs / SMT) #459; C: a narrow OpenEvolve-style LLM mutation loop.
    2. Equalize evaluation/time/token budgets and held-out independent tests; record seeds, generated variants, invalid-candidate rate and full cost. Best-of-N with no evolutionary feedback is a useful control.
    3. Candidate 'passes test suite' is only empirical evidence, never proof of equivalent transfer/ownership semantics. Counterexample/independent equivalence check and mutation negatives remain mandatory.
    4. Hard stop on unstable outputs, unproved rewrites, no gain beyond B, or maintainability/cost regression. No integration or production changes from this comment.

    Useful high-level donor: proposal/search/evaluator separation and archived candidate provenance, not automatic code replacement.

  2. PhysShell commented on Nov 20, 2026

    @PhysShell
    OwnerAuthor

    Emmy donor: multi-observable rewrite equivalence and deterministic CSE (20.11.2026)

    Research page · Emmy CHANGELOG · upstream.

    EMMY-02 / REWRITE-SEMANTIC-FIDELITY / DEFER, in this existing bounded superoptimization issue. Emmy is not a proposed OwnIR library or ownership analyzer. Its AD bug history documents how simplification of a dual/tape value as a plain number can preserve an apparent scalar while deleting derivative structure; changelog #143 also discusses deterministic common-subexpression elimination independent of hash iteration order.

    Portable test methodology: prove or refute equivalence against a vector of observables, not just returned scalar/boolean: ownership obligations, effects, alias/path facts, source provenance, unknown/non-modeled state and stable ID/hash, in addition to runtime value. Negative controls: rewrite removes a symbolic wrapper; folds across revision-bound inputs; changes source ordering and canonical output; merges expressions that appear numerically equal but carry distinct facts. Compare against the existing independently authored OwnIR oracle with tiny pure transfer helpers; require counterexample and exact source/IR SHA. Avoid new generic CAS/e-graph framework, GPL code import, and CI gates until incremental value demonstrated.

  3. PhysShell commented on Nov 23, 2026

    @PhysShell
    OwnerAuthor

    2026-11-23 — Tree Calculus / typing rules as programs: verified-rewrite prior art

    Research Page · original Coq/Rocq proofs · 2026 Typing Rules Become Programs · working implementations/benchmarks.

    Tree Calculus represents programs as trees inspectable by programs of the same calculus. The new Rocq 9.3 research reports patch_commutes_with_evaluation, optimise_preserves_evaluation, optimise_typed, and typing/inference programs with explicit assumptions. Potential lesson: certify a small pure AST/IR rewrite against independently reviewed semantics, rather than equating test-vector match with equivalence.

    Bounded/optional in #459: if one real, profiled pure OwnIR helper needs a rewrite, compare current typed AST + PBT/SMT/existing verifier against the reference proof discipline; one wrong-rewrite mutant must fail. Measure proof cost, semantic correspondence to Rust, runtime gains, and maintenance. No Tree Calculus runtime/DSL or new formal stack by default. RESEARCH / P3 / KILL-FIRST / NOT ADOPTED. Original repo has an MIT root LICENSE but historic LGPL headers; check rights before code reuse.

  4. PhysShell commented on Nov 23, 2026

    @PhysShell
    OwnerAuthor

    2026-11-23 — Johannes Bader: LambAda/Triage calculus as a rewrite semantics donor

    Bader research Page · LambAda · Tree Calculus · typing rules as programs.

    LambAda compiles a human-readable syntax into tree/triage calculus, with a compiler written in the same calculus. Interesting not as a dependency but as an example of representing/programmatically transforming programs and simplifying stream/map compositions. The 2026 Rocq material describes evaluation-preserving rewrites; author explicitly says LambAda does not guarantee correctness/stability. For #459, compare an existing pure OwnIR/AST optimization against ordinary typed Rust tree rewrite + differential/metamorphic/SMT baseline before considering formalism. Demand a negative rewrite mutant, explicit source-model correspondence and actual measurable benefit. NO production integration.

  5. PhysShell commented on Nov 23, 2026

    @PhysShell
    OwnerAuthor

    2026-11-23 — John Tromp AIT: closed-term enumeration / encoding cost as methodology donor

    Research Page · language sandbox issue #60 · Tromp/AIT · ClosedRanking.hs · Sizes.hs.

    AIT includes rank/unrank generation of small closed λ-terms and bit-size comparisons (unary/Elias/Huffman) plus an independent evaluator ecosystem. Reusable idea: for one profiled pure OwnIR transfer helper, use bounded, de-duplicated expression generation and first-divergence tests; compare actual code runtime and proof, not smallest BLC representation as a performance proxy. Need a verified semantics mapping and negative mutants; do not port an experimental Haskell→BLC GHC plugin. Tree/Triage calculus evaluator files tree.lam and triage.lam have different rules. #459 already owns enumeration/optimization; no new Own.NET task. Research P3, no production integration.

  6. PhysShell commented on Nov 26, 2026

    @PhysShell
    OwnerAuthor

    Prior art / quchen/articles — 2026-11-26

    RESEARCH / REUSE-FIRST / KILL-FIRST / NOT ADOPTED / NO IMPLEMENTATION AUTHORIZED. Collection, inspected revision 14dc3eb.

    Rules for typeclass laws is an explicitly unsubmitted proposal, not an implemented GHC facility. It suggests making algebraic law assumptions explicit and using them for rewriting. Algebraic blindness and Tag, don't type are additional design references.

    Transfer hypothesis: add to the existing bounded superoptimization study an inventory of laws for pure, already specified OwnIR helpers: associativity/idempotence only where applicable, explicit preconditions, counterexamples for invalid laws, independently checked equivalence over the supported domain. For abstract-state operations include unknown/top/bottom and resource identity; never assume syntactic similarity means semantic equivalence. Property tests are counterexample search, not universal proof. Measure valid rewrites, rejected unsound candidates and runtime/maintenance impact against the existing baseline. Kill if existing checks cover the case or no net benefit. Related #445 and #450. No production optimizer, solver change or analyzer rewrite.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions