Translator.fromExports: the ESM wasm-import delivery path (runtime half) - #60
Merged
Conversation
…delivery path) Item 4 of the #16 delivery design note, runtime half. Deno's native wasm- module imports are stable, permission-free, and cached like any module — the ideal translator delivery on Deno — but they hand back an instantiated NAMESPACE, which Translator could not consume (create takes bytes or a Module and instantiates internally). fromExports(ns, {buildHash?}) wraps the namespace: no compile, no copy. The private constructor now takes the exports record; the missing-export validation is unchanged and refuses namespaces by name. Sharing is safe by construction — ESM yields one instance per realm and translate() is synchronous end-to-end, so calls cannot interleave — documented on the method. buildHash cannot be recovered from an instance: null by default (the artifact cache already handles that, cache/core.ts:120-127) or supplied by a caller that knows the asset's hash (a published package shipping a sidecar digest). Pins (translator_from_exports_test.ts): a dynamically wasm-imported shim translates BYTE-IDENTICALLY to the bytes-constructed path (envelope equality); repeated translations on the shared instance are stable; a short namespace is refused naming the missing export; the buildHash contract. Gates: test-runtime (full), check.
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.
PR 3 of 4 from the #16 delivery design note (reordered before the package PR, which builds on it).
Deno's native wasm-module imports are the ideal translator delivery there — stable (unlike raw byte imports), permission-free (unlike
readFile), module-cache-delivered — but they yield an instantiated namespace.Translator.fromExports(ns, {buildHash?})wraps it: no compile, no copy.Key pin: a dynamically wasm-imported shim translates byte-identically (envelope equality) to the
create(bytes)path. Sharing safety documented (one ESM instance per realm;translateis synchronous end-to-end so calls cannot interleave).buildHashstays honest: unrecoverable from an instance → null (cache already refuses politely) or caller-supplied.Gates: test-runtime 347/0, check. Next:
@deltic/translator+defaultTranslator()consuming this on the Deno path.