interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / semhash / README.md

133 lines · 7809 bytes Raw Blame History Source

seed/semhash: meaning hash and semantic diff for Omega units (M1)

semhash.om is a seeded-Omega tool. It gives every function of a .om unit a hash of what the function means, not how it is spelled. Renaming locals or parameters, adding or removing notes, blank lines or spacing, and reordering functions do not change a function's hash. The tool errs toward CHANGED: when it cannot prove that a spelling is meaning-free, it keeps the spelling verbatim, so the change shows up as CHANGED rather than SAME.

The design is close to Unison's content-addressed definitions. A call is hashed as the callee's hash (Merkle), so a change in a leaf reaches every transitive caller, and a function-name-only rename keeps its hash.

Build

semhash.om has no om2 line. It is compiled after the plain-function form of om/sha256/sha256-om2.om:

mkdir -p build
{ sed 's/^export fn /fn /' om/sha256/sha256-om2.om; cat seed/semhash/semhash.om; } > build/semhash.full.om \
  && $OMC < build/semhash.full.om > build/semhash && chmod +x build/semhash

$OMC is the pinned seed compiler. check.sh pins sha256 26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991. A missing or different compiler makes it print SEMHASH NOT_RUN and exit 3.

Modes

commandoutputexit
semhash < u.om or semhash hash < u.omFN name hex line=N[ verbatim][ cycle] per function, then UNIT hex fns=n0
semhash canon < u.omthe unit with locals renamed by first occurrence (v0 v1 ..., or the first of w y z q whose letter-digit names are unused), with notes and blank lines dropped and tokens joined by one space0
semhash diff a.om b.omSAME, CHANGED or REMOVED name, RENAMED a->b, ADDED name, then EXPORTS CHANGED and ENTRY CHANGED a->b if they apply, then DIFF SAME or DIFF CHANGED n=K0 same, 1 changed
semhash keywordsthe keyword table (word code) the tool classifies with0
semhash dups < recordsrecords are hash-mode FN lines with a unit path in front (PATH FN name hex line=N...). Every SKIP ... line is echoed. Then, for each set of two or more records with the same 64-digit hash, DUP hex n=K followed by PATH name line=N... per member, in input order; last DUPS groups=G fns=F records=R skipped=S0

The other exit codes are:

Duplicate-function report (#827 M1)

sh seed/semhash/dups.sh SEMHASH [-i INDEX] [DIR...] hashes every .om unit under the given directories (default om seed, from the repository root, in LC_ALL=C path order), puts each unit's path in front of its FN lines and pipes them to SEMHASH dups. A unit that semhash refuses becomes SKIP path rc=N reason. With -i INDEX the records themselves, which form the function-level meaning-hash index (one PATH FN name hex line=N... line per function), are also written to INDEX. Equal hashes mean equal meaning as far as this tool can prove it (see the next two sections), so a group is a set of functions that one shared definition could replace. The grouping is in semhash.om; the script only lists files and runs the tool.

At omega-mv d3d1b1bc the report over om/ and seed/ is dups/report-d3d1b1bc.txt: DUPS groups=449 fns=1542 records=6959 skipped=17. The 17 skipped units are the deliberately malformed compiler fixtures (CR bytes, unterminated blocks) and dups/refused.om. The largest group is 66 copies of fn main to int / ret 0. Many groups are test fixtures that repeat a helper on purpose; others, such as inb, obflush, ob1 and hexval in om/aarch64, om/codec, om/evidence, om/gpumath and om/tls, are library code that could share one unit.

What a function hash covers

Not normalised (renaming these reports CHANGED)

The following are not normalised:

Changing the profile line changes every function hash. A change to a declaration that no function uses does not show as CHANGED for any function, but it does change the unit hash. Function order matters only through the ENTRY and EXPORTS lines and the unit hash.

Check

Run sh seed/semhash/check.sh from anywhere. It makes these checks:

  1. Keyword parity: the tool's table must equal the two word:code lists of seed/omc/genkw.awk plus the fn kw2 table of seed/omc/omc.om, decoded in sh.
  2. Oracle: for every unit omc accepts, omc(canon(x)) must be byte-identical to omc(x).
    • The units are rung4, contracts, omc tests, om2, host tests, the json compositions, blake3, sha256, leakscan, the tool itself and the cases.
    • For a unit omc refuses, the canon form must stay refused.
    • om2 fmt units are skipped, because their output is the formatted source text.
  3. Cases: cases/*.om are diffed against cases/base.om, and stdout and the exit code are compared with cases/*.exp.
    • inv_* cases must be all SAME.
    • neg_* cases are the negative controls, which must report CHANGED.
    • ren_fn must report RENAMED.
  4. Unit hashes: they must be equal for alpha renaming and for notes and spacing, and differ for reordering.
  5. Refusals and usage: the CR input, reserved-byte input and unknown-mode cases are checked.
  6. Mutant: a copy of the tool with while dropped from its table must fail both keyword parity and the oracle (mutant killed).
  7. Dups: dups.sh over dups/ (a.om, b.om, refused.om) must print dups/dups.exp exactly: a.om sq and b.om sq2 (a renamed parameter) group, inc and inc2 (a different constant) do not, and refused.om is a SKIP. Control: the same records with one hash digit changed past the first 16 must give groups=0, so grouping compares the whole hash, not the key.

cases in the PASS line counts the oracle-identical units, the non-control cases and the dups check. controls counts the neg_* cases, the three refusal and usage checks, the killed mutant and the dups control.