Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
f5214bc
Adopt Unicode correctness-oracle testing guide
lukewilliamboswell Nov 25, 2026
ade226f
Add bounded opt-in Thai dictionary line breaking
lukewilliamboswell Nov 25, 2026
dbf3c36
Record Thai tailoring growth evidence
lukewilliamboswell Nov 25, 2026
fe5f5bc
Upgrade the Unicode data and algorithm pins to 18.0
lukewilliamboswell Nov 25, 2026
190a233
Surface Thai index and segmentation invariant failures
lukewilliamboswell Nov 25, 2026
e883b69
Refresh measured Thai growth after invariant review
lukewilliamboswell Nov 25, 2026
6a63fb4
Derive the line benchmark revision from the manifest
lukewilliamboswell Nov 25, 2026
a46578d
Integrate Unicode 18 source and conformance pins
lukewilliamboswell Nov 25, 2026
9964362
Integrate enduring Unicode testing methodology
lukewilliamboswell Nov 25, 2026
8ef1085
Integrate opt-in Thai dictionary line breaking
lukewilliamboswell Nov 25, 2026
d6d5acd
Migrate Unicode fuzz coverage to roc-fuzz suites
lukewilliamboswell Nov 25, 2026
6edacba
Audit public Unicode safety and bound segmentation collectors
lukewilliamboswell Nov 25, 2026
4a5b4c9
Integrate the public Unicode API safety contract
lukewilliamboswell Nov 25, 2026
7513542
Guard fuzz supervisor deadlines and assert model goals
lukewilliamboswell Nov 25, 2026
55d6aeb
Integrate compiler-instrumented Unicode fuzz suites
lukewilliamboswell Nov 25, 2026
35b33dd
Implement Unicode default sentence segmentation
lukewilliamboswell Nov 25, 2026
69d7d2e
Add explicit Unicode locale identifier and Case profile selectors
lukewilliamboswell Nov 25, 2026
352498a
Exercise sentence collectors, fuzz coverage, and SB8 model
lukewilliamboswell Nov 25, 2026
ae631f3
Exercise bounded collection contracts in fuzz suites
lukewilliamboswell Nov 25, 2026
8226ff8
Bound locale parsing and audit its public contracts
lukewilliamboswell Nov 25, 2026
87e72be
Build the pinned Unicode Code9 oracle on macOS
lukewilliamboswell Nov 25, 2026
3695171
Keep audit scope tied to the public nominal type
lukewilliamboswell Nov 25, 2026
26a8ff1
Integrate explicit locale identifiers and casing profiles
lukewilliamboswell Nov 25, 2026
4490a34
Integrate fuzz exploration of bounded collector limits
lukewilliamboswell Nov 25, 2026
96d8fb1
Integrate the pinned bidi oracle macOS build
lukewilliamboswell Nov 25, 2026
6f8547e
Integrate Unicode 18 sentence segmentation
lukewilliamboswell Nov 25, 2026
376d8ad
Describe sentence owned materialization accurately
lukewilliamboswell Nov 25, 2026
80515d1
Implement the four Unicode normalization forms and canonical matching
lukewilliamboswell Nov 25, 2026
e30e2ab
Integrate Unicode normalization and canonical caseless matching
lukewilliamboswell Nov 25, 2026
fbedb19
Expose Unicode identifier and exact numeric scalar properties
lukewilliamboswell Nov 25, 2026
9a704fa
Gate the new scalar properties with public contract checks
lukewilliamboswell Nov 25, 2026
8846b89
Return exact decimal digits in one scalar lookup
lukewilliamboswell Nov 25, 2026
1234469
Integrate Unicode identifier properties and exact numeric values
lukewilliamboswell Nov 25, 2026
4ed73d9
Implement bounded UCA and CLDR collation operations
lukewilliamboswell Nov 25, 2026
0ac4794
Check CLDR profiles against pinned ICU comparison fixtures
lukewilliamboswell Nov 25, 2026
0dfba47
Fuzz normalization forms, concatenation, and resource bounds
lukewilliamboswell Nov 25, 2026
0b88adb
Integrate normalization fuzz properties
lukewilliamboswell Nov 25, 2026
7143738
Pin and generate Unicode 18 and CLDR 49 collation data
lukewilliamboswell Nov 25, 2026
4e7304c
Integrate reviewed sentence materializer documentation
lukewilliamboswell Nov 25, 2026
28f7465
Integrate bounded UCA and CLDR collation
lukewilliamboswell Nov 25, 2026
414da77
Use ICU4X Neo as a Unicode 18 grapheme benchmark reference
lukewilliamboswell Nov 25, 2026
9506883
Integrate the Unicode 18 ICU4X grapheme reference
lukewilliamboswell Nov 25, 2026
01582fb
Check every Unicode scalar in both Roc safety backends
lukewilliamboswell Nov 25, 2026
565f50f
Run the collation safety root once per backend
lukewilliamboswell Nov 25, 2026
81a5222
Integrate exhaustive scalar round trips in both safety backends
lukewilliamboswell Nov 25, 2026
1d7650f
Test the active CLDR collation release axis
lukewilliamboswell Nov 25, 2026
e72abb5
Integrate the CLDR manifest regression correction
lukewilliamboswell Nov 25, 2026
eab9af4
Use shared allocation ratchets on Linux and macOS
lukewilliamboswell Nov 25, 2026
fa2750b
Use shared allocation ratchets in the integration branch
lukewilliamboswell Nov 25, 2026
ce6269a
Keep upstream Unicode inputs local and exercise seeded correctness or…
lukewilliamboswell Nov 26, 2026
c998590
Keep bulk conformance data local and gate changes with fuzz oracles
lukewilliamboswell Nov 26, 2026
6360250
Give the local Unicode data regression suite time to finish
lukewilliamboswell Nov 26, 2026
5cfcf07
Allow the optional data regression suite to finish
lukewilliamboswell Nov 26, 2026
2013fe0
Use defaulted configuration records for Unicode APIs
lukewilliamboswell Nov 26, 2026
543dff8
Integrate defaulted Unicode configuration records
lukewilliamboswell Nov 26, 2026
d70c7d9
Name the collation digit ordering policy
lukewilliamboswell Nov 26, 2026
548cab3
Integrate named collation digit ordering
lukewilliamboswell Nov 26, 2026
7614f51
Run fuzz campaigns locally
lukewilliamboswell Nov 26, 2026
f187ef2
Keep fuzz campaigns local
lukewilliamboswell Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Official Unicode inputs are hashed byte-for-byte by their manifest. Preserve
# upstream LF line endings even when Git is configured to use CRLF on Windows.
/vendor/unicode/** text eol=lf
/vendor/unicode/**/*.zip -text
/vendor/cldr/** text eol=lf

# Roc formatting is byte-sensitive, so keep source line endings identical on
# every development and CI host.
Expand Down
24 changes: 15 additions & 9 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,23 @@ jobs:
version: nightly
nightly-tag: ${{ env.ROC_NIGHTLY_TAG }}

- name: Run deterministic fuzz suite expectations
run: ROC=roc python3 scripts/fuzz.py models

- name: Run bounded fuzz smoke
run: ROC=roc python3 scripts/fuzz.py smoke

- name: Upload fuzz failure evidence
if: failure()
uses: actions/upload-artifact@v4
with:
name: fuzz-smoke-evidence
path: |
.roc-unicode-tmp/fuzz/reports/
.roc-fuzz/
include-hidden-files: true
if-no-files-found: ignore

test:
name: ./scripts/all_tests.sh (${{ matrix.os }})
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -78,7 +92,7 @@ jobs:

- run: roc version

- name: Run all tests
- name: Run checkout-only examples, API checks, and allocation ratchets
run: ROC=roc ./scripts/all_tests.sh

# Also save the cache when the job fails, so tests that passed are cached.
Expand All @@ -87,11 +101,3 @@ jobs:
with:
path: ${{ steps.roc.outputs.cache-path }}
key: ${{ steps.roc.outputs.cache-key }}

- name: Upload minimized Bidi regressions
if: failure()
uses: actions/upload-artifact@v4
with:
name: bidi-regressions-${{ matrix.os }}
path: .roc-unicode-tmp/failures
if-no-files-found: ignore
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ examples/get-visual-width
examples/nr-of-code-points
examples/split-graphemes

# Pinned upstream data for local conformance and table generation
/vendor/unicode/[0-9]*/
/vendor/cldr/[0-9]*/

# Ignore generated output
generated-docs
tests/platform/.zig-cache/
Expand Down
16 changes: 16 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ work. Historical measurements should identify the pin through the repository
commit that produced them; generated, untracked reports may record the actual
compiler version they observed.

## Testing policy

Prefer roc-fuzz targets that check explicit correctness invariants and use a
small set of named seeds. Keep focused expectations for concrete regressions
or semantics that a general oracle cannot distinguish. Pin upstream Unicode
and CLDR inputs by URL and checksum in the manifest and fetch them locally
for Unicode updates and exhaustive conformance. Keep newly fetched inputs and
corpora out of Git. Commit the generated Roc modules needed by package users.

## Integration workflow

Develop independent substrates and features in isolated branches and
Expand All @@ -50,3 +59,10 @@ No feature or substrate branch may be merged into the integration branch until
a different agent or reviewer has performed an adversarial review against
`design.md`. Resolve material findings on the feature branch and record the
review outcome before integration. Authors do not approve their own changes.

## Testing methodology

Follow [docs/testing.md](docs/testing.md) when designing or reviewing test
evidence. Identify the production contract, the independent expected result,
and the limits of the evidence. Record the result of a targeted mutation when
adding or materially changing an oracle.
196 changes: 164 additions & 32 deletions README.md

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

These benchmarks are intentionally opt-in developer tools. They are not part of
the test suite or CI because their external toolchains and machine-dependent
timings are unsuitable as merge gates.
timings are unsuitable as merge gates. Fetch the pinned upstream data with
`python3 scripts/unicode_data.py fetch` before running the grapheme, line-break,
and script validation benchmarks.

- [`grapheme`](grapheme/README.md) compares allocation-free Unicode 17 extended
- [`grapheme`](grapheme/README.md) compares allocation-free extended
grapheme segmentation in Roc, Rust, and Go.
- [`indexed-valid-str`](indexed-valid-str/README.md) checks and measures the
private complete-string pull cursor used by lazy scalar traversal.
- [`line-break`](line-break/README.md) measures allocation-free Unicode 17
- [`line-break`](line-break/README.md) measures allocation-free Unicode 18
default line-break opportunities against an official conformance signature.
- [`properties`](properties/README.md) compares independent narrow property
views with the fused composite row on ASCII, BMP, supplementary, and mixed
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/bidi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ sizes. Retained state and work should grow linearly with paragraph size.

## Optional external differential

Normal CI uses the vendored Unicode 17 BidiTest and BidiCharacterTest data.
Run `python3 scripts/unicode_data.py fetch` before the full local Bidi
conformance suite or the reference differential.
`scripts/bidi_reference_differential.py` is an explicit local verification tool.
It downloads Unicode's official Code9 C reference source for Unicode 17.0.0,
It downloads Unicode's official Code9 C reference source for Unicode 18.0.0,
verifies every source file against recorded SHA-256 digests, compiles an
isolated query wrapper, and compares deterministic seeded scalar cases against
the Roc test app. It verifies the Roc compiler against `.roc-version`; a failed
download, checksum, compile, or mismatch fails the command. The source is not
vendored, so the repository's canonical UCD data remains its local source of
truth.
download, checksum, compile, or mismatch fails the command. The reference
uses the same checksum-verified character and bracket data as the package.

On a differential failure, the command writes a minimized tab-separated row
under `.roc-unicode-tmp/failures`. Re-run it by placing that row after a
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bidi/main.roc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ run! = |input| {
var $checksum = 0.U64
var $at = 0.U64
while $at < repeats {
analysis = Bidi.analyze_paragraph(source, Auto, Bidi.default_limits) ?? return "FAIL\tanalysis"
analysis = Bidi.analyze_paragraph(source, { limits: Bidi.default_limits }) ?? return "FAIL\tanalysis"
paragraph = TextRange.scalar_range(Bidi.paragraph_range(analysis))
whole_line = Bidi.reorder_line(analysis, paragraph) ?? return "FAIL\twhole line"
start = ScalarRange.start(paragraph)
Expand Down
26 changes: 15 additions & 11 deletions benchmarks/grapheme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

This local benchmark compares allocation-free extended-grapheme-cluster
counting over identical UTF-8 bytes. It uses a representative set of optimized
Unicode 17 implementations with iterator or next-boundary APIs, so the timed
implementations with iterator or next-boundary APIs, so the timed
loop does not need to materialize every boundary:

- Roc: `Grapheme.Cursor.push`/`finish`, using this package's Unicode 17 tables.
- Rust/ICU4X: `icu_segmenter` 2.2.0, Unicode 17, from the Unicode Consortium.
- Roc: `Grapheme.Cursor.push`/`finish`, using this package's Unicode 18 tables.
- Rust/ICU4X: `icu_segmenter` 2.4.0, with the Neo constructor and Unicode 18
compiled data from the Unicode Consortium. [ICU4X 2.4.0](https://github.com/unicode-org/icu4x/releases/tag/icu%402.4.0)
- Go: `clipperhouse/uax29` 2.7.0, Unicode 17, with a specialized forward
iterator.
- C: `libgrapheme` 3.0.0, Unicode 17, with its UTF-8 next-break API.
Expand Down Expand Up @@ -34,8 +35,10 @@ default when `taskset` is available.
- A C compiler supporting `-flto`, and POSIX `make`
- Network access on the first build

Rust and Go library versions are locked in `Cargo.lock` and `go.sum`. Override
tool locations with command-line options or set `ROC` for the Roc compiler.
Rust and Go library versions are locked in `Cargo.lock` and `go.sum`.
ICU4X 2.4 exposes the Neo constructor through its `unstable` feature, which
the benchmark enables on the pinned release. Override tool locations with
command-line options or set `ROC` for the Roc compiler.
The runner downloads the pinned `libgrapheme` 3.0.0 source archive into the
ignored build directory and verifies its SHA-256 before building it.

Expand Down Expand Up @@ -81,9 +84,10 @@ the segmentation core rather than allocation and reference-count behavior from
materializing lists of ranges or strings. Input reading, process startup, and
printing one checksum are included but amortized over repeated scans.

Before timing, every implementation emits a compact signature of all boundary
positions. The signatures must agree on every corpus, and the official corpus
must match the boundaries encoded in Unicode 17's `GraphemeBreakTest.txt`.
This catches misplaced boundaries even when the total cluster count happens to
match. The runner aborts rather than reporting incomparable timings when those
checks fail.
Before timing, every implementation emits a compact signature of its boundary
positions. Implementations with the same Unicode version must agree on each
corpus. For `--case unicode_conformance`, implementations matching the
package's Unicode version must also match the official conformance signature.
The report records each implementation's Unicode version and signature.
Differences across Unicode versions are diagnostic because benchmarks can
perform different numbers of boundary transitions on the same bytes.
95 changes: 61 additions & 34 deletions benchmarks/grapheme/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

ROOT = Path(__file__).resolve().parents[2]
BENCH = Path(__file__).resolve().parent
sys.path.insert(0, str(ROOT))
from scripts import unicode_data

MANIFEST = unicode_data.load_manifest()
UNICODE_VERSION = unicode_data.release_version(MANIFEST, "unicode")
BUILD = ROOT / ".roc-unicode-tmp" / "benchmarks" / "grapheme"
DEFAULT_OUTPUT = BUILD / "results.json"
DEFAULT_TARGET_BYTES = 1024 * 1024
Expand All @@ -34,12 +39,20 @@
f"libgrapheme-{LIBGRAPHEME_VERSION}.tar.gz"
)
LIBGRAPHEME_SHA256 = "32585af73dda62fbcc0fed14f199aa1bc988ad01dad0bfbd06cf175d9cf3d68c"
CONFORMANCE_CASE = "unicode_conformance"
IMPLEMENTATION_UNICODE_VERSIONS = {
"roc": UNICODE_VERSION,
"rust_icu4x": "18.0.0",
"rust_unicode_segmentation": "17.0.0",
"go_clipperhouse": "17.0.0",
"c_libgrapheme": "17.0.0",
}
CASE_NAMES = (
"ascii",
"latin_combining",
"multilingual",
"emoji_sequences",
"unicode17_conformance",
CONFORMANCE_CASE,
)


Expand Down Expand Up @@ -88,21 +101,14 @@ def boundary_signature(ends: Sequence[int]) -> tuple[int, int, int]:


def conformance_corpus() -> tuple[bytes, tuple[int, int, int]]:
path = ROOT / "vendor/unicode/17.0.0/GraphemeBreakTest.txt"
corpus = bytearray()
ends: list[int] = []
for raw_line in path.read_text(encoding="utf-8").splitlines():
body = raw_line.split("#", 1)[0].strip()
if not body:
continue
tokens = body.split()
for case in unicode_data.parse_grapheme_tests(MANIFEST):
# A control separator guarantees a boundary between adjacent test cases.
corpus.extend(b"\0")
ends.append(len(corpus))
for index in range(1, len(tokens), 2):
corpus.extend(chr(int(tokens[index], 16)).encode("utf-8"))
if tokens[index + 1] == "÷":
ends.append(len(corpus))
start = len(corpus)
ends.extend(start + offset for offset in case.break_offsets)
corpus.extend("".join(chr(point) for point in case.code_points).encode("utf-8"))
return bytes(corpus), boundary_signature(ends)


Expand All @@ -127,9 +133,9 @@ def corpora(
"1️⃣ 👋🏿 ❤️‍🔥 🧑‍🚀 ",
target_bytes,
),
"unicode17_conformance": conformance,
CONFORMANCE_CASE: conformance,
}
return cases, {"unicode17_conformance": expected}
return cases, {CONFORMANCE_CASE: expected}


def file_sha256(path: Path) -> str:
Expand Down Expand Up @@ -330,6 +336,33 @@ def calibrate(
return repeats, checksum


def verify_signatures(
case_name: str,
signatures: dict[str, tuple[int, int, int]],
conformance_signature: tuple[int, int, int] | None,
) -> None:
by_version: dict[str, dict[str, tuple[int, int, int]]] = {}
for implementation, signature in signatures.items():
version = IMPLEMENTATION_UNICODE_VERSIONS[implementation]
by_version.setdefault(version, {})[implementation] = signature
if (
conformance_signature is not None
and version == UNICODE_VERSION
and signature != conformance_signature
):
raise BenchmarkFailure(
f"{case_name}: {implementation} Unicode {version} expected boundary "
f"signature {conformance_signature}, got {signature}"
)
for version, group in by_version.items():
if len(set(group.values())) > 1:
raise BenchmarkFailure(
f"{case_name}: Unicode {version} boundary signatures differ: {group}"
)
if len(set(signatures.values())) > 1:
print(f" Unicode versions yield different boundary signatures: {by_version}")


def benchmark(
binaries: dict[str, Path],
cases: dict[str, bytes],
Expand All @@ -344,12 +377,16 @@ def benchmark(
for case_name, corpus in cases.items():
print(f"\n[{case_name}] {len(corpus):,} bytes", flush=True)
case_results: dict[str, dict] = {}
one_pass_counts: dict[str, int] = {}
signatures: dict[str, tuple[int, int, int]] = {}
signatures = {
language: verify_boundaries(binary, corpus, cpu)
for language, binary in binaries.items()
}
verify_signatures(case_name, signatures, expected.get(case_name))

for language, binary in binaries.items():
signatures[language] = verify_boundaries(binary, corpus, cpu)
repeats, checksum = calibrate(binary, corpus, cpu, target_seconds)
one_pass_counts[language] = checksum
if checksum != signatures[language][0]:
raise BenchmarkFailure(f"{case_name}: {language} count and signature disagree")
checked_invoke(binary, corpus, repeats, cpu, checksum)
samples = []
for _ in range(samples_count):
Expand All @@ -359,6 +396,7 @@ def benchmark(
mad = statistics.median(abs(value - median) for value in samples)
case_results[language] = {
"clusters": checksum,
"boundary_signature": signatures[language],
"repeats": repeats,
"mb_per_second_median": median,
"mb_per_second_mad": mad,
Expand All @@ -370,19 +408,6 @@ def benchmark(
flush=True,
)

if len(set(one_pass_counts.values())) != 1:
raise BenchmarkFailure(
f"{case_name}: implementations disagree on cluster counts: {one_pass_counts}"
)
if len(set(signatures.values())) != 1:
raise BenchmarkFailure(
f"{case_name}: implementations disagree on boundary positions: {signatures}"
)
if case_name in expected and next(iter(signatures.values())) != expected[case_name]:
raise BenchmarkFailure(
f"{case_name}: Unicode 17 expected boundary signature "
f"{expected[case_name]}, got {signatures}"
)
results[case_name] = {"bytes": len(corpus), "implementations": case_results}
return results

Expand Down Expand Up @@ -499,6 +524,7 @@ def main() -> None:
raise BenchmarkFailure(
f"benchmark requires {pinned_roc}, got {actual_roc!r}"
)
all_cases, all_expected = corpora(args.corpus_bytes)
binaries = (
{
"roc": BUILD / "roc",
Expand All @@ -515,7 +541,6 @@ def main() -> None:
if missing:
raise BenchmarkFailure(f"benchmark binaries are missing: {missing}")

all_cases, all_expected = corpora(args.corpus_bytes)
selected_names = args.cases or list(CASE_NAMES)
cases = {name: all_cases[name] for name in selected_names}
expected = {name: all_expected[name] for name in selected_names if name in all_expected}
Expand All @@ -541,11 +566,13 @@ def main() -> None:
"cc": capture([args.cc, "--version"]),
},
"libraries": {
"roc_unicode": UNICODE_VERSION,
"unicode_segmentation": "1.13.3 (Unicode 17)",
"icu_segmenter": "2.2.0 (Unicode 17)",
"icu_segmenter": "2.4.0 (Unicode 18, Neo)",
"clipperhouse_uax29": "2.7.0 (Unicode 17)",
"libgrapheme": "3.0.0 (Unicode 17)",
},
"unicode_versions": IMPLEMENTATION_UNICODE_VERSIONS,
"configuration": {
"samples": args.samples,
"target_seconds": args.target_seconds,
Expand Down Expand Up @@ -574,6 +601,6 @@ def main() -> None:
if __name__ == "__main__":
try:
main()
except (BenchmarkFailure, OSError, subprocess.CalledProcessError) as error:
except (BenchmarkFailure, OSError, subprocess.CalledProcessError, unicode_data.DataError) as error:
print(f"ERROR: {error}", file=sys.stderr)
raise SystemExit(1) from error
Loading
Loading