From ddf65fc2deb996dd504b3f355e5891749776f0f4 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 20 Aug 2026 19:39:27 +0000 Subject: [PATCH] Stop SchemaBinary leaking into encoding barrel consumers `EMPTY_READER_VIEW` was built from `EMPTY_READER_BUFFER.buffer`. A member access in argument position is not effect-free to a bundler, so the `@__PURE__` annotation the build adds could not be honoured and the pair survived tree shaking in every consumer that imports `effect/unstable/encoding` without ever touching this module. Both placeholders now read one named `ArrayBuffer`, which keeps `EMPTY_READER_VIEW.buffer === EMPTY_READER_BUFFER.buffer` exactly as before. Add a tracked bundle fixture so the module's size is compared on every PR by the existing Bundle job. Co-Authored-By: Claude Opus 5 --- .../effect/src/unstable/encoding/SchemaBinary.ts | 16 +++++++++++----- packages/tools/bundle/fixtures/schema-binary.ts | 10 ++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 packages/tools/bundle/fixtures/schema-binary.ts diff --git a/packages/effect/src/unstable/encoding/SchemaBinary.ts b/packages/effect/src/unstable/encoding/SchemaBinary.ts index 4c7a3d1cd1d..7f3099f7b15 100644 --- a/packages/effect/src/unstable/encoding/SchemaBinary.ts +++ b/packages/effect/src/unstable/encoding/SchemaBinary.ts @@ -542,8 +542,14 @@ class IndexSignatureCache { } } -const EMPTY_READER_BUFFER = new Uint8Array(0) -const EMPTY_READER_VIEW = new DataView(EMPTY_READER_BUFFER.buffer) +// Both placeholders read the same named `ArrayBuffer` rather than reaching +// through `EMPTY_READER_BUFFER.buffer`. A member access in argument position +// defeats the `@__PURE__` annotation the build adds, which pinned this pair +// into the bundle of every consumer that imports the encoding barrel without +// ever touching this module. +const EMPTY_READER_ARRAY_BUFFER = new ArrayBuffer(0) +const EMPTY_READER_BUFFER = new Uint8Array(EMPTY_READER_ARRAY_BUFFER) +const EMPTY_READER_VIEW = new DataView(EMPTY_READER_ARRAY_BUFFER) const EMPTY_PARSE_OPTIONS: SchemaAST.ParseOptions = {} class Reader { @@ -2384,9 +2390,9 @@ function decodeExtraPair(layout: StructLayout, r: Reader, out: Record