Repository navigation
codec: stop grafting by name; codecs are plain namespaces - #276
Merged
Merged
Conversation
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]>
Deploying dang with
|
| Latest commit: |
88fe83a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ed62df68.dang-3kk.pages.dev |
| Branch Preview URL: | https://codec-namespaces.dang-3kk.pages.dev |
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
force-pushed
the
codec-namespaces
branch
from
November 9, 2026 15:38
9ac62e8 to
1e84c63
Compare
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
force-pushed
the
codec-namespaces
branch
2 times, most recently
from
November 9, 2026 22:45
2c876b0 to
88fe83a
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.
Removes the name-based grafting that put the codecs'
encode/decode(and@JSON.field/@JSON.ignore, …) onto any scalar namedJSON,YAMLorTOML, and turns the three codecs into plain namespaces likeRandom. 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
BuiltinScalarModule/attachBuiltinSchemes/attachBuiltinMethods/isBuiltinScalarMemberare gone, with their calls in schema import,scalardeclarations and the runtime. Since stdlib: base64 String methods and JSON/YAML/TOML codec namespaces #131 Dang ownsJSON/YAML/TOMLin the Prelude and imports never shadow builtins, so for a schema'sscalar JSONthe graft only ever addedDagger.JSON.encode; for a user'sscalar JSONit kept the codec working behind a shadowing declaration.JSON,YAMLandTOMLare ObjectKind static modules installed likeRandom. The type namedJSON(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@JSONdirectives because directive scopes resolve in the type namespace.Select.Infer,registerBuiltinTypes,isDegradableScalar's static-module exclusion.JSON!,YAML!andTOML!behave exactly asRandom!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.Test.JSON).isJSONScalaris untouched (still main's by-name check); it goes away with the JSON value type in a later PR.analysis.builtinMemberlooked members up on any scalar of a codec's name throughBuiltinScalarModule; it now uses the host type itself. While the typeJSON(the value type) and the valueJSON(the namespace) are separate,analysis.Members("JSON")also lists the namespace's members, soJSON.encodestill documents in hover, completion and the REPL. codec: Decoded replaces the JSON value type #281 drops that onceJSONis only the namespace.import_qualified_codecandimport_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)
Test.JSON.encode([7])(a schema'sscalar JSON)field "encode" not found in Test.JSON; Test.JSON is a different type from the builtin JSON, which has it→ useJSON.encodescalar JSONthenJSON.encode(…)/@JSON.fieldin the same modulefield "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 fordirective @JSON.field not declared)let y: YAML! = "a: 1"cannot use String! as YAML!, the same generic error asRandom!→ useString!YAML.decode(s) :: TOML!(failed at runtime)constructor for TOML not found, as for any namespaceNo in-repo code (including
mod/) relied on any of these.Maintainer decisions
JSONTypesplit off; main'sisJSONScalarstays as it is.@JSON.field,@YAML.ignore, …); a general validation hook comes in a later PR.Testing
dang fmt, golden updates reviewed, and every check (**) passes. New error tests:user_scalar_json_shadows_codecschema_scalar_json_has_no_codec