Skip to content

feat: count and compare texts by code point - #99

Merged
Sequela02 merged 2 commits into
mainfrom
feat/stage-11-text-code-points
Nov 19, 2026
Merged

Sequela02 merged 2 commits into
mainfrom
feat/stage-11-text-code-points

Conversation

@Sequela02

Copy link
Copy Markdown
Contributor

Slice 11b of #83, decision 12: length and < on Text count and compare code points, as the solvers do, in proofs, the interpreter and the generated TypeScript.

The change

  • Checker: length on a text and <, <=, >, >= between texts are rewritten into two nodes, TextLength and TextOrder, as Expr::Is is. Ordering enums is still an error.
  • Proofs: str.len, str.< and str.<= (a > b is (str.< b a)).
  • Interpreter: compares Rust strings, whose UTF-8 order is code-point order; length is chars().count().
  • TypeScript: JavaScript's .length and < work on UTF-16 units, which disagree with code points above U+FFFF. The generated code calls textLength$ and textLess$, emitted only in modules that use them.
  • Differential test: the default text samples gain U+FF5A, which comes before U+1D11E by code point and after it by UTF-16 unit.
  • text-ordered.accord expected error; decision 12 makes that program legal, so it now expects proofs. Docs: syntax.md, typescript.md, and row 6 of native-code-constraints.md (now enforced).

Review focus

  • cvc5 1.4.2 proves no order law of str.< (for example, that one of two texts comes first); it runs to the 10 s limit, so such an obligation is undecided, as the stage 11 measurement noted. text-ordered-law.accord pins it, at about 10 s per conformance run. The other cases use contracts that need no law.
  • A text's length has no stated bound. length(text) is an i64, and callers assume a callee's i64 result fits, while lists have a stated element limit. Not addressed here; left for a decision.

Verification

On Windows, with the pinned Z3 5.3.3 and cvc5 1.4.2:

  • Cases committed first; on main the new cases don't reach their expected outcomes, since length and ordering on texts are errors there.
  • cargo fmt --all --check passes; cargo clippy --all-targets -- -D warnings is clean.
  • cargo test --no-fail-fast: every suite passes, on main and on this branch.
  • The generated words.ts matches the hand-written expected module byte for byte.
  • Planted faults in a separate copy: a UTF-16 textLess$ (a < b) and a UTF-16 textLength$ (BigInt(value.length)) each fail the differential test, the latter with width("😀"): want 1, got 2.

Not established: Linux and macOS (CI, with full-ci).

Risk note

Two-way door: new accepted programs, nothing previously accepted changes meaning. Blast radius: texts' length and ordering in proofs, interpreter and TypeScript; other cases keep their outcomes. Evidence: the cases and checks above.

Refs #83

Atrium: 01a1e493-5b83-771b-bdf7-c8715cf599bd

Decision 12 makes `length` and `<` on `Text` count and compare code
points, as the solvers' `str.len` and `str.<` do, so a program that
orders texts is no longer an error. The cases pin it before the
compiler does: a contract that holds and one that breaks for each,
enum ordering still refused, and a pair across U+FFFF ("z" before
"😀"), where UTF-16 order disagrees. A TypeScript case pins the
generated module. text-ordered-law pins that cvc5 proves no order
law of `str.<`, so such an obligation is undecided.

Refs #83
`length` on a text and `<`, `<=`, `>`, `>=` between texts now check,
prove and run. The checker writes them as their own nodes, so each
backend can't confuse them with list length or integer order: proofs
use `str.len`, `str.<` and `str.<=`, and the interpreter compares
Rust strings, whose UTF-8 order is code-point order.

JavaScript's `.length` and `<` count and compare UTF-16 units, which
disagree with the solvers above U+FFFF. Generated TypeScript calls
its own `textLength$` and `textLess$` instead, emitted only in the
modules that use them, and the differential samples gain U+FF5A,
which UTF-16 orders after U+1D11E, so a unit-based helper fails it.

Refs #83
@Sequela02 Sequela02 added the full-ci Run Windows and macOS CI once before merging label Nov 19, 2026
@Sequela02
Sequela02 merged commit d30bb38 into main Nov 19, 2026
5 checks passed
@Sequela02
Sequela02 deleted the feat/stage-11-text-code-points branch November 19, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run Windows and macOS CI once before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant