Repository navigation
feat: count and compare texts by code point - #99
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Slice 11b of #83, decision 12:
lengthand<onTextcount and compare code points, as the solvers do, in proofs, the interpreter and the generated TypeScript.The change
lengthon a text and<,<=,>,>=between texts are rewritten into two nodes,TextLengthandTextOrder, asExpr::Isis. Ordering enums is still an error.str.len,str.<andstr.<=(a > bis(str.< b a)).chars().count()..lengthand<work on UTF-16 units, which disagree with code points above U+FFFF. The generated code callstextLength$andtextLess$, emitted only in modules that use them.text-ordered.accordexpectederror; decision 12 makes that program legal, so it now expects proofs. Docs:syntax.md,typescript.md, and row 6 ofnative-code-constraints.md(now enforced).Review focus
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.accordpins it, at about 10 s per conformance run. The other cases use contracts that need no law.length(text)is ani64, and callers assume a callee'si64result 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:
mainthe new cases don't reach their expected outcomes, sincelengthand ordering on texts are errors there.cargo fmt --all --checkpasses;cargo clippy --all-targets -- -D warningsis clean.cargo test --no-fail-fast: every suite passes, onmainand on this branch.words.tsmatches the hand-written expected module byte for byte.textLess$(a < b) and a UTF-16textLength$(BigInt(value.length)) each fail the differential test, the latter withwidth("😀"): 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'
lengthand 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