ReviewOS

home-lang/home

fix(ts): preserve imported homomorphic union callback members

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

Parent

  • #548 TypeScript correctness
  • #416 TypeScript performance

Problem

After #672, the pinned Zod 4.5.2 graph remains at 374 diagnostics / 369 unique identities. Ten locale TS7006 reports occur because contextual callback typing transported through imported distributive homomorphic utilities does not retain the readable union surface.

The faithful reduction has three modules, matching Zod's imported utility graph. Its MultipleMatch arm omits options; the final Record<string, unknown> intersection makes that property readable as unknown. After the Array.isArray(issue.options) guard, TypeScript deliberately treats the mapped callback value as any.

// utilities.ts
export type Primitive = string | number | symbol | bigint | boolean | null | undefined;
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type InexactPartial<T> = { [P in keyof T]?: T[P] | undefined };
export type MakePartial<T, K extends keyof T> = Omit<T, K> & InexactPartial<Pick<T, K>>;
export type Identity<T> = T;
export type Flatten<T> = Identity<{ [K in keyof T]: T[K] }>;

// owner.ts
import type * as util from "./utilities.js";
interface IssueBase { readonly code?: string; readonly path: PropertyKey[]; readonly message: string; }
interface NoMatch extends IssueBase { readonly code: "invalid_union"; readonly options?: util.Primitive[]; readonly inclusive?: true; }
interface MultipleMatch extends IssueBase { readonly code: "invalid_union"; readonly inclusive: false; readonly matches: number[]; }
interface Custom extends IssueBase { readonly code: "custom"; }
type Issue = NoMatch | MultipleMatch | Custom;
type RawIssue<T extends IssueBase> = T extends any
  ? util.Flatten<util.MakePartial<T, "message" | "path"> & { readonly input: unknown } & Record<string, unknown>>
  : never;
export type ErrorMap<T extends IssueBase = Issue> = (issue: RawIssue<T>) => string | undefined;

// consumer.ts
import type { ErrorMap } from "./owner.js";
import type { Primitive } from "./utilities.js";
export const error: () => ErrorMap = () => (issue) => {
  if (issue.code === "invalid_union" && issue.options && Array.isArray(issue.options) && issue.options.length > 0) {
    return issue.options.map((value) => {
      const exact: Primitive = value;
      const wrong: never = value;
      void exact; void wrong;
      return `${value}`;
    }).join(" | ");
  }
  return undefined;
};

TypeScript 6.0.3 and the native preview each report exactly the intentional TS2322 (any to never), with no TS7006, TS2339, or TS2344.

Requirements

  • Preserve exact readable, optional, and open-index structure across imported distributive homomorphic mapped aliases and contextual callback transport.
  • Keep normal discriminant, truthiness, and Array.isArray flow semantics.
  • No source/library/member-name special cases, source-text inference, blanket diagnostic suppression, depth caps, or broad any exports.
  • Add focused Program/schema/checker coverage and the exact three-module invalid-control oracle.
  • Require exact TS6/native/Home diagnostic parity, full checker and Program suites, ReleaseFast, format/diff checks, and the repository Pickier baseline.
  • Run pinned Zod 4.5.2 twice against the exact #672 parent; reject any added diagnostic identity or unstable run.
  • Publish detailed evidence and a linked README table, including negative results if the corpus does not improve.
8 days ago

Progress update:

  • Replaced the earlier two-module reduction with the faithful three-module Zod shape. The earlier options?: never arm was not fair: real Zod omits that member and recovers it as unknown through Record<string, unknown>.
  • TypeScript 6.0.3, native TypeScript, and the current Home candidate now agree on the oracle: exactly one intentional TS2322 (any to never), and no TS7006/TS2339/TS2344.
  • Added structural transport for homomorphic Pick/Exclude/partial/intersection pipelines, optional-key coverage, open string indices, nested keyof constraint proofs, imported union narrowing, member Array.isArray flow, and source-owned contextual diagnostic authority.
  • Full suites passed after the latest source change: Program 203/203 and checker 4,364/4,364.
  • Rejected the first ReleaseFast corpus probe after an intermittent SIGSEGV. The crash report exposed union/intersection member slices borrowed across generic resolution, which can relocate the interner member pool. All four affected narrowing loops now duplicate those slices before resolving members. The full suites pass with that ownership fix; ReleaseFast rebuild and repeated Zod stability checks are in progress.

No benchmark result will be accepted until two unchanged, sequential ReleaseFast runs complete with identical diagnostic identities and no additions versus #672.

8 days ago

Verification update:

  • The faithful three-module oracle now matches TypeScript 6.0.3 and native TypeScript exactly: one intentional consumer.ts:7:13 TS2322 (any to never), with no TS7006, TS2339, or TS2344.
  • Full Program and checker test targets pass; the checker target remains 4,364/4,364.
  • ReleaseSafe Zod 4.5.2 audit against exact parent 307892be9: 374 -> 350 diagnostics and 369 -> 345 location/code identities. Removed 24 existing identities (11 TS7006, 9 TS2339, 4 TS2345), with zero added identities.
  • Two sequential ReleaseSafe Zod runs are byte-identical: empty stdout and stderr SHA-256 62f115f3549509b7a392e0173a3a285b85b1691d81fc672bed435db4d566a2eb. Timings were 68.84s and 71.47s real.
  • ReleaseFast builds successfully. zig fmt --check and git diff --check pass. Pickier is unchanged at the repository baseline (22,427 findings: 11,834 errors and 10,593 warnings).

The broad operational intersection candidate was rejected after it changed nine unrelated diagnostic identities. The retained implementation confines exact union/intersection traversal to semantic constraint proofs and keeps ordinary inferred types stable.

8 days ago

Completed and pushed directly to main in two conventional commits:

  • a730be062 — fix(ts): preserve imported homomorphic union callback context (#673)
  • 4d5d3d5a9 — docs(ts): publish homomorphic union callback audit (#673)

Accepted evidence: exact three-engine 1× TS2322 oracle parity; Zod 4.5.2 374 -> 350 diagnostics and 369 -> 345 location/code identities (24 removed, 0 added); two byte-identical ReleaseSafe runs; full Program/checker suites; ReleaseFast; formatting and diff gates. README and detailed performance docs now publish the result.

Sign in to comment on this issue.