feat(hir): supply native parsers for static Zod schemas - #9040
Draft
proggeramlug wants to merge 3 commits into
Draft
feat(hir): supply native parsers for static Zod schemas#9040proggeramlug wants to merge 3 commits into
proggeramlug wants to merge 3 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
proggeramlug
force-pushed
the
feat/zod-compile-aot
branch
from
August 29, 2026 16:28
1b305bf to
f13b50d
Compare
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.
Summary
AOT-compiles a conservative static subset of Zod
z.compile()while keeping Zod?not Perry?as the owner of schema semantics.Perry recognizes a closed
z.object({...}), emits only a native parser, and passes that parser to the proposed ZodcompileFromParser()API. Zod's own TypeScript remains responsible for cloning, async/backward/skip-check bypasses, recursion guards, public parse methods, validation, and authoritative runtime fallback.This remains a draft because it depends on the upstream Zod integration API proposed in colinhacks/zod#6498.
Architecture
There is no Perry reimplementation of Zod's compiled wrapper contract. Unsupported schemas and Zod versions without
compileFromParser()retain the ordinaryz.compile(schema, options)call.Changes
z.object({...})declarations imported fromzod/zod/v4.int/ literalmin/ literalmaxchecks to native Perry HIR.INVALIDsentinel from the native parser and install it through Zod'scompileFromParser().__proto__, unsupported schemas, and dynamic options rather than partially specializing them.compilePackagesenter a TypeScript source tree even when the package's built exports target is absent. This makes the temporary source-only Zod pin reproducible.ee27e77ad86238199cfa0c262cfa2c7dfc125e49and opt Zod intoperry.compilePackages.Current supported subset
import * as z from 'zod' or 'zod/v4'constschema bindingsz.object()with static, unique, non-computed fieldsz.string(),z.number(), andz.boolean()z.number().int(),.min(<number literal>), and.max(<number literal>)z.compile(schema)and static{ strict: <boolean> }Everything else remains on Zod's normal runtime path.
Upstream dependency / landing decision
The Zod-side API implementation is available at:
Before this Perry PR leaves draft, we should agree that:
compileFromParser(schema, parser, { validator? })plus an exported failure sentinel.Test plan
npm ci --ignore-scripts --dry-runcargo test -p perry-hir --lib(360 passed, 1 pre-existing ignored before rebase)cargo test -p perry-hir zod_aot --libafter rebasing onto currentmain(5 passed)cargo test -p perry --bin perry compile_package_resolves_source_without_built_exports_targetcargo build --profile perry-dev -p perryasync-runtime,web-fetch(nodyn-eval)__originalRunandbag.fallbackRunidentities prove installation is Zod-ownedzshy) passesVerified output
The assertions cover schema cloning, replacement of
_zod.run, Zod ownership of the wrapper and fallback, native valid parsing without fallback, unknown-key stripping, invalid fallback, and the final Zod issue.Checklist
CHANGELOG.mdeditCONTRIBUTING.mdand agree to the Code of Conduct