Skip to content

Emit static Effect schema declarations#1

Closed
patroza wants to merge 1 commit into
mainfrom
codex/schema-dts-facade
Closed

Emit static Effect schema declarations#1
patroza wants to merge 1 commit into
mainfrom
codex/schema-dts-facade

Conversation

@patroza

@patroza patroza commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

Adds declaration-emitter support for Effect schema model facades so .d.ts emit can materialize the same static shape we currently generate in scanner source:

  • materializes namespace X { interface Encoded ... } from S.StructNestedEncoded<typeof X>
  • synthesizes interface X, namespace X.Make, X.DecodingServices, and X.EncodingServices
  • rewrites emitted schema bases to S.OpaqueFacade<X, X.Encoded, X.Make, X.DecodingServices, X.EncodingServices, {}>
  • preserves class static members by intersecting the facade with fields, mapFields, copy, to, and from
  • emits an intermediate __X_base / __X wrapper for model classes with own members, matching native source codegen shape

This intentionally lives in declaration emit and checker/node-builder plumbing only, so it can be carried as a patch onto Effect's TypeScript compiler fork later.

Validation

  • npm run build:compiler
  • scanner comparison with the forked compiler:
    • no-static main + compatibility patch: Aggregate Instantiations: 13,917,040
    • static-native branch + forked compiler: Aggregate Instantiations: 13,840,894
    • no-static main + stock compiler: Aggregate Instantiations: 17,871,742

The d.ts-emitter path recovered roughly 98% of the static-native source-codegen instantiation benefit in the scanner comparison.

Notes / Gotchas

  • Existing native __X_base helper classes are not reinterpreted. Rewriting those to namespace service aliases can make old generated type Make = X.Make aliases self-reference and collapse constructor input to never.
  • Textual d.ts parity is close but not byte-for-byte: ordering, import qualification, and boolean vs false | true can still differ.
  • This targets the effect-app/TypeScript fork only; do not retarget to the official Microsoft repository.

@patroza patroza force-pushed the codex/schema-dts-facade branch from a3df1f4 to 3bafe2c Compare June 21, 2026 18:33
@patroza

patroza commented Jun 21, 2026

Copy link
Copy Markdown
Member Author

Update: the emitter now also handles direct bare schema models like class X extends S.Opaque<X>()(...) {} when no namespace X existed before.

For those classes it now synthesizes:

  • top-level interface X from the schema Type
  • namespace X
  • X.Encoded
  • X.Make
  • X.DecodingServices
  • X.EncodingServices
  • S.OpaqueFacade<X, X.Encoded, X.Make, X.DecodingServices, X.EncodingServices, {}> base rewrite

It also tightens recognition to schema aliases S.Opaque / Schema.Opaque, so Context.Opaque service tags are not swept into this path.

Validation:

  • npm run build:compiler
  • tiny declaration fixture for bare S.Opaque<DirectBare>()(...) emitted the full OpaqueFacade + interface + namespace shape ✅

@patroza patroza force-pushed the codex/schema-dts-facade branch from 3bafe2c to b6e686e Compare June 21, 2026 18:41
@patroza

patroza commented Jun 21, 2026

Copy link
Copy Markdown
Member Author

Updated again after measuring direct bare S.Opaque<X>()(...) support.

Latest scanner comparison with this compiler:

  • main/no-static + stock TypeScript: 17,871,742
  • main/no-static + forked emitter before bare Opaque: 13,917,040
  • main/no-static + forked emitter with bare Opaque: 12,128,418
  • static-native branch + forked emitter with bare Opaque: 11,724,286

Bare Opaque support adds another 1,788,622 instantiation reduction on no-static main vs the previous emitter pass. Current no-static compiler emit is 404,132 above static-native, so it recovers about 93% of the current stock-to-static-native benefit.

Also fixed synthesized interface/namespace export-ness so non-exported local schema classes merge correctly inside their source module.

@patroza patroza force-pushed the codex/schema-dts-facade branch from b6e686e to 630474a Compare June 21, 2026 19:18
@patroza patroza closed this Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant