Skip to content

codec: stop grafting by name; codecs are plain namespaces - #276

Merged
vito merged 9 commits into
mainfrom
codec-namespaces
Nov 9, 2026
Merged

vito merged 9 commits into
mainfrom
codec-namespaces

Conversation

@vito

@vito vito commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Removes the name-based grafting that put the codecs' encode/decode (and @JSON.field/@JSON.ignore, …) onto any scalar named JSON, YAML or TOML, and turns the three codecs into plain namespaces like Random. This is the first step in taking format knowledge out of Dang's core: after this PR, member resolution, the Prelude and assignability no longer know a codec by name or by identity.

What changes

  • No more grafting. BuiltinScalarModule / attachBuiltinSchemes / attachBuiltinMethods / isBuiltinScalarMember are gone, with their calls in schema import, scalar declarations and the runtime. Since stdlib: base64 String methods and JSON/YAML/TOML codec namespaces #131 Dang owns JSON/YAML/TOML in the Prelude and imports never shadow builtins, so for a schema's scalar JSON the graft only ever added Dagger.JSON.encode; for a user's scalar JSON it kept the codec working behind a shadowing declaration.
  • Codecs are namespaces. JSON, YAML and TOML are ObjectKind static modules installed like Random. The type named JSON (the untyped JSON value from codec: make JSON an untyped JSON value #257) is a separate type, JSONType, that only shares the name; the value and type namespaces resolve independently. It carries the @JSON directives because directive scopes resolve in the type namespace.
  • With no ScalarKind static modules left, builtin statics never sit on a meta-type, so these go away without any replacement check:
    • the static-first skip in Select.Infer,
    • the meta-type branch of registerBuiltinTypes,
    • isDegradableScalar's static-module exclusion.
  • Namespaces are not special-cased. JSON!, YAML! and TOML! behave exactly as Random! does on main: they name the namespace's own type, with the generic errors that follow (see below). Builtin namespaces are conceptually automatically provided imports.
  • Shadowing hints. A missed member or scoped directive on a type that shadows a Prelude name says the declaration shadows the builtin (error path only, keyed on Prelude bindings). The hint tells a Prelude type's statics from a Prelude namespace's members. Meta-types now print their qualifier (Test.JSON).
  • Stale claims removed. Every comment, test and doc (skill + lit) that said same-named scalars merge with, shadow, or are grafted onto the codecs.

isJSONScalar is untouched (still main's by-name check); it goes away with the JSON value type in a later PR.

  • Rebased onto main's analysis package. analysis.builtinMember looked members up on any scalar of a codec's name through BuiltinScalarModule; it now uses the host type itself. While the type JSON (the value type) and the value JSON (the namespace) are separate, analysis.Members("JSON") also lists the namespace's members, so JSON.encode still documents in hover, completion and the REPL. codec: Decoded replaces the JSON value type #281 drops that once JSON is only the namespace.
  • New error tests import_qualified_codec and import_dang_qualified_codec: neither a schema import's namespace nor a native module's reaches the codec namespaces (Test.YAML, Lib.YAML), consistent with import: keep Dang's names out of schema imports #275 and import: keep the prelude out of module imports #279.

User-facing breakages (released behavior)

Before After
Test.JSON.encode([7]) (a schema's scalar JSON) field "encode" not found in Test.JSON; Test.JSON is a different type from the builtin JSON, which has it → use JSON.encode
scalar JSON then JSON.encode(…) / @JSON.field in the same module field "encode" not found in JSON; the JSON declared here shadows the builtin JSON, which has it; rename the declaration to use the builtin (same hint for directive @JSON.field not declared)
let y: YAML! = "a: 1" cannot use String! as YAML!, the same generic error as Random! → use String!
YAML.decode(s) :: TOML! (failed at runtime) still fails at runtime, now with constructor for TOML not found, as for any namespace

No in-repo code (including mod/) relied on any of these.

Maintainer decisions

  • D8: this PR contains the grafting removal, the stale-claim cleanup, and the codecs as ObjectKind namespaces with JSONType split off; main's isJSONScalar stays as it is.
  • D4: the per-format directives stay (@JSON.field, @YAML.ignore, …); a general validation hook comes in a later PR.
  • Q-41 B: builtin namespaces are conceptually automatically provided imports, with no downstream special-casing. So there is no namespace-specific error or check. Installing them as implicit imports comes in a separate PR.

Testing

dang fmt, golden updates reviewed, and every check (**) passes. New error tests:

  • user_scalar_json_shadows_codec
  • schema_scalar_json_has_no_codec

vito added 5 commits November 9, 2026 05:02
Drop BuiltinScalarModule / attachBuiltinSchemes / attachBuiltinMethods /
isBuiltinScalarMember. They put encode/decode (and the @Format.field /
@FORMAT.ignore directives) on any scalar named JSON, YAML or TOML. Since
68adbdd Dang owns those names in the Prelude and imports never shadow
builtins, so for a schema's `scalar JSON` the graft only added
`Dagger.JSON.encode`; for a user's `scalar JSON` it kept the codec
working behind a shadowing declaration.

Static-first member resolution skips builtin static hosts instead of
asking whether a member name is grafted; a later commit removes that
skip too.

Comments, tests, the skill and lit docs no longer claim that same-named
scalars merge with, shadow, or are grafted onto the codecs.

Signed-off-by: Alex Suraci <[email protected]>
YAML and TOML become ObjectKind static modules installed like Random,
rather than ScalarKind types. They never had values of their own: `let
y: YAML! = "..."` held an unvalidated string that could not even degrade
to String. encode, decode and the @YAML/@TomL directives work unchanged;
only the meaningless `YAML!`/`TOML!` value types go away.

Signed-off-by: Alex Suraci <[email protected]>
When a member or scoped directive is missing from a type that shares
its name with a Prelude type that has it, say so: a user's `scalar
JSON` shadows the builtin JSON (and its encode/decode and @JSON
directives), and a schema's `Test.JSON` is a different type from it.
Meta-types now print with their type's qualifier, so the error names
`Test.JSON` rather than a bare JSON. The check runs only on the error
path and is keyed on Prelude names, not on any format.

Signed-off-by: Alex Suraci <[email protected]>
JSON becomes a plain ObjectKind namespace like YAML, TOML and Random:
the value `JSON` is the module holding encode/decode, and the type
`JSON` is JSONType, the untyped JSON value, a separate type that only
shares the name. The two resolve independently through the Prelude's
value and type namespaces. JSONType carries the @JSON directives, since
directive scopes resolve in the type namespace.

With no ScalarKind static modules left, builtin statics never sit on a
meta-type, so the static-first skip in member resolution, the meta-type
branch of registerBuiltinTypes and isDegradableScalar's static-module
exclusion all go away. No check by name or identity replaces them.
isJSONScalar is unchanged.

Passing the namespace where a JSON value is expected now says the value
is a module, not a value of the type JSON.

Signed-off-by: Alex Suraci <[email protected]>
The codecs are no longer ScalarKind modules: reword the comments and
tests that still said so, and drop the docs linker's meta-type branch,
which only served a builtin scalar's name.

Signed-off-by: Alex Suraci <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Deploying dang with  Cloudflare Pages  Cloudflare Pages

Latest commit: 88fe83a
Status: ✅  Deploy successful!
Preview URL: https://ed62df68.dang-3kk.pages.dev
Branch Preview URL: https://codec-namespaces.dang-3kk.pages.dev

View logs

@vito
vito added this pull request to stack #282 November 9, 2026 15:15
The shadowing hint checked a Prelude type's statics and a Prelude
namespace's members with one predicate, so `Error.message` under a user
`interface Error` claimed the builtin Error had it. It now takes one
predicate for each.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the codec-namespaces branch from 9ac62e8 to 1e84c63 Compare November 9, 2026 15:38
@vito vito changed the title codec: stop grafting by name; codecs as namespaces codec: stop grafting by name; codecs are plain namespaces Nov 9, 2026
vito added 3 commits November 9, 2026 21:42
The skill's codec section described a schema's `scalar JSON` by the
encode/decode it lacks, which only makes sense next to the grafting this
branch removes. Say what it is instead: an ordinary schema scalar.

Signed-off-by: Alex Suraci <[email protected]>
The analysis package (from main) looked up a builtin codec's members on
any scalar of its name through BuiltinScalarModule, which this branch
removes. Codecs are plain namespaces now, so look members up on the
host itself. A type name that is also bound to another namespace as a
value (here `JSON`, whose type is the JSON value type while the value is
the codec namespace) lists that namespace's members as its statics, so
`JSON.encode` still documents.

Signed-off-by: Alex Suraci <[email protected]>
Codec namespaces are Prelude modules now, like Random; pin that neither
a schema import's namespace nor a native module's reaches them.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the codec-namespaces branch 2 times, most recently from 2c876b0 to 88fe83a Compare November 9, 2026 22:45
@vito
vito merged commit 7fdc20b into main Nov 9, 2026
9 checks passed
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