ReviewOS

home-lang/home

fix(ts): preserve callable metadata during union subtype reduction

#511
Closed chris opened this 8 days ago ·
8 days ago

Follow-up to #507; tracker #416 and a prerequisite for preserving callable semantics across source owners (#480, #487).

With the shared strict/noEmit/noLib/skipLibCheck config, Home accepts this invalid narrowing while TS 6.0.3 and native TS 7.0.2 each report TS2322:

export {};
declare let value: unknown;
declare function guard(x: unknown): x is number;
declare function plain(x: unknown): boolean;
const selected = [guard, plain];
if (selected[0](value)) { const bad: number = value; }

The strict callable subtype path used by array-element and conditional-union reduction compares erased parameter/return payloads but does not consult predicate or explicit receiver metadata. A plain boolean function must not subsume a predicate promise, and incompatible receiver types must remain distinct. Audit both declaration and branch orders, bare callables and object wrappers, and retain positive controls for genuine compatible predicates. Use source-level regressions plus relation-level tests; do not waive failures or modify timed corpora.

Baseline binary: bench/vs_tsgo/results/signature-identity.6jiDkG/home-final (SHA256 d7ecf960b76ef1f61b3e9acf4ebb97cad70fc3d087db20c5a5cdce03d82e6ffc). Both graph benchmark rows remain ineligible; this issue is not their readmission.

8 days ago

Reproduced and pushed the permanent audit in 79d9ce2 (Refs #511, #416). TS 6.0.3 and native TS 7.0.2 each pass all 256 cases. Current Home passes 120/256: mixed plain/predicate 60/64, different targets 12/64, same target 16/64, explicit receivers 32/64. This includes false positives as well as unsound acceptance; no failure is waived. Both new checker regression tests fail on the pre-fix source and pass after adding semantic metadata to subtype reduction. The larger matrix additionally exposes missing predicate composition and receiver checking for resolved union signatures; those are being fixed before claiming completion. Untimed raw evidence: bench/vs_tsgo/results/callable-unions.2pCgVc/before.log and unit-before.log.

8 days ago

Candidate verification: all 768 compiler/case checks pass (256/256 each for Home, TS 6.0.3, native TS 7.0.2), compared with Home 120/256 before. The v2 checker suite passes 4,259/4,259. Additional final-source tests cover three-way unions, predicate-kind/argument-position incompatibility, and any-return functions not acquiring a predicate promise; those focused tests pass. Driver 186/186, program 105/105, CLI 69/69, harness 37/37 pass. Final release/checker/conformance verification is still running. No timing claims or graph readmission yet.

8 days ago

Final verification caught an existing five-way union arity regression after the two-branch limitation was removed. Both pinned CLIs confirm exactly two TS2554 diagnostics for the unchanged checker fixture. The synthesis path was incorrectly replacing the matched common signature with the longest constituent, discarding its required/bounded arity. It now retains the matched parameter contract; the original focused regression passes unchanged. Full checker/conformance and a fresh release are rerunning; this issue remains open until final verification completes.

8 days ago

The expanded final check also caught over-aggressive deduplication of the resulting overload set: partial matching belongs to finding cross-branch candidates, not deciding whether output overloads are identical. Result deduplication now retains distinct parameter counts, minimum arities, rest markers, parameter identities and receiver types. All 208 union-focused tests pass, including the unchanged positive arity controls and f6 regression; the previous conformance run passed 1,417/1,417. A final full-source checker/conformance/release verification is running. The 256-case CLI matrix and additional three-/five-way fixture checks remain required.

8 days ago

Completed and pushed as Chris Breuer, without coauthors: audit 79d9ce2, fix 7d16f7a, documentation 150655867. The final release passes all 256 union cases (Home before: 120/256; TS 6.0.3 and native TS 7.0.2: 256/256 throughout), plus 12 additional compiler/fixture checks. Checker 4,261/4,261; conformance 1,417/1,417; driver 186/186; program 105/105; CLI 69/69; harness 37/37. Predicate/receiver composition, strict reduction, three-way unions and retained call arities are covered. Existing regression fixtures were not weakened. Raw evidence: bench/vs_tsgo/results/callable-unions.2pCgVc, final -v5.log files, binary SHA256 462eaf0f83137f05205ac50705c5b4878c0e24f18a7b69fcb1804dc1a03a30dc. README table and full report: https://github.com/home-lang/home/blob/main/docs/docs/TS_PERFORMANCE.md#callable-union-predicates-and-receivers-untimed . No new timing claim; #480/#487 remain open.

Sign in to comment on this issue.