Repository navigation
Conversation
Up to Dang 2.3 the builtin JSON, YAML and TOML were scalars, so 2.1 code spells a scalar type bare: every Dagger Go SDK entrypoint has `fnArgs: JSON!` and `(result :: JSON!)`, and the engine's ModuleEntrypoint contract, which it writes as Dang source beside them, does too. 2.4 made them namespaces, which no value has as its type, so those entrypoints stopped compiling even when pinned to `dang = "2.1"`. Before 2.4, a type an import brings in unqualified now takes the place of a builtin import's namespace of the same name in type position, so with Dagger's `scalar JSON` imported a bare `JSON` type is `Dagger.JSON`. The value keeps naming the builtin namespace, so `JSON.encode` works in every version, and an explicit import of the same name still replaces the builtin. The rule is about import precedence, for every builtin import, and names none of them. No spelling tells the two apart, so the parser records the rule on the FileBlock and the import installer reads it from the context, for every file of RunFile, RunDir, DeclareDir, LoadDir sessions and analysis. The REPL's import scopes follow its version through BuildScopesFromImportsForVersion. Signed-off-by: Alex Suraci <[email protected]>
Moving source to Dang 2.4 changes what a bare type named like a builtin import means wherever an import brings in a type of that name unqualified: `receiverValue: JSON` named Dagger's scalar and comes to name the builtin JSON namespace. No spelling differs, so parsing as one version and formatting as the other can't see it. PlanMigrations now takes MigrateOptions.ImportedTypes, which reports what a project's imports bring in (BuiltinImportTypes computes it from import configs, introspecting or compiling them as needed), and qualifies those types by their import's name in type positions and type patterns: `receiverValue: Dagger.JSON`. It is only asked for projects that spell such a type bare. Types the module declares, or that an import of the same name replaces, are left alone, and a type two imports bring in is refused. `dang migrate` resolves the imports as running the project would, which for a Dagger import means starting a session. Signed-off-by: Alex Suraci <[email protected]>
A directive's scope names a namespace, as `JSON.encode` does, but it was resolved as a type. Before Dang 2.4 a type an import brings in can take a builtin import's name in type position, so with Dagger's `scalar JSON` imported `@JSON.field` looked for the directive on Dagger.JSON and failed. A scope that names an import's namespace now resolves as that name's value does. Also documents the exception in the dang-internals skill, and that pre-2.4 source spelling a builtin scalar bare with no import of that type is not kept working. Signed-off-by: Alex Suraci <[email protected]>
Resolving a project's imports can start a Dagger session, and a type two imports bring in only matters where a file spells it bare. The migration now resolves imports, and refuses an ambiguous type, only for a file that spells a type named like a builtin import bare, which a codec directive's scope (`@JSON.field`) is not. A file preview resolves them as lazily. `dang migrate` also detects Dagger from a Dagger module, as the LSP does, since that is where Dang entrypoints get Dagger's `scalar JSON` from. Signed-off-by: Alex Suraci <[email protected]>
Review follow-ups for the 2.4 import-type migration: - A bare type that needed qualifying but is still bare in the result, as in a #nofmt region, which is echoed as written, now fails the migration with its line, rather than coming to name the builtin. - Imports resolve per directory, so a Dagger module in a subdirectory of a project gets Dagger's types; a preview resolves from the file's directory alike. - A file whose bare types its module declares resolves nothing. The user-facing skill references mention the pre-2.4 rule and that `dang migrate` qualifies such types. Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
da9ef11
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://05e88fdf.dang-3kk.pages.dev |
| Branch Preview URL: | https://gate-builtin-import-types.dang-3kk.pages.dev |
Owner
Author
|
Closed in favor of #295 |
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.
Speculative: how hard is it to keep 2.1-pinned Dagger entrypoints compiling on Dang 2.4?
The problem
Every Dang entrypoint the Dagger Go SDK generates (
dang = "2.1", Dagger auto-imported) spells Dagger's JSON scalar bare:The engine's
ModuleEntrypointcontract (core/sdk/dang/v2/entrypoint.go) is also Dang source with bareJSON, written beside it and run at the same pinned version. On v2.4.0 this fails withtype hint mismatch: expression has type String!, but hint expects JSON!.What v2.3.0 actually did, measured at v2.3.0 and at 00dc380 (the pseudo-version dagger vendors): bare
JSONwas neverDagger.JSON. It was Dang's own Prelude scalarJSON, a separate type.pub f(x: JSON!): Dagger.JSON! { x }fails there with "declared Dagger.JSON!, inferred JSON!". The entrypoints worked because(s :: JSON!)from aString!works for any scalar, and the engine only checks that the result's scalar is namedJSON. 2.4 broke them by turning the builtin JSON/YAML/TOML from scalars into namespaces (8b182d2, 16e1985, 5cba6f8). Import precedence did not change.The gate
For source before 2.4 (
Version.importTypesOverBuiltinImports), a type an import brings in unqualified takes the place of a builtin import's namespace of the same name, in type position only. So with Dagger imported, a bareJSONtype isDagger.JSON. The contract andcallresolve it the same way. Values are unchanged:JSON.encodeis the builtin in every version. An explicit import named like a builtin ([imports.YAML]+import YAML) still replaces it in every version. From 2.4, behaviour is v2.4.0's.It is a generic import-precedence rule:
installUnqualifiedImportTypesFromModule): an existing binding that is the builtin import of that name (isBuiltinImportNamespace, an identity check againstStaticModules()that treats every builtin import the same) no longer blocks the import's type.The parser can't see imports, so it can't desugar this. It records the rule on
FileBlock.ImportTypesOverBuiltinImports(taggeddang:"version"; migration AST comparison skips it).FileBlock.Infer,prepareFileScopes/runDirectoryPhases(per file, nested-block imports included) andLoadDirsessions put the rule on the context. The installer reads it there. Pathless source (the REPL) falls back toVersionFromContext, and the REPL builds its import scopes through the newBuildScopesFromImportsForVersion. This covers RunFile, RunDir, DeclareDir, LoadDir sessions, analysis/LSP and the REPL. Each file follows its own version, imported Dang modules included.Directive scopes (
@JSON.field) now resolve as the namespace value does (directiveNamespaceScope), not through the type. Otherwise the gate would have broken codec directives in 2.1 Dagger modules.dang migrateto 2.4This is done, and it turned out to be the larger half.
PlanMigrationstakesMigrateOptions.ImportedTypes(configPath, dir), which reports what a directory's imports bring in.BuiltinImportTypescomputes it from import configs, introspecting schemas or compiling Dang modules. The migration then qualifies bare types in type positions and type patterns by their import's name:receiverValue: JSON→receiverValue: Dagger.JSON.dagger.json.#nofmtregion).MigrateSource(no imports) is unchanged.MigrateSourceWithImportsis the import-aware variant. There is a2.1-to-2.4/builtin_import_types.dangfixture, with a schema import, that runs before and after.Difficulty, honestly
dang.peg.go(+2219/−2218 for one line in the grammar action), tests, and the migration.dang migrateis no longer purely offline for projects that spell such a type bare.Random.Charset) resolve through the import's type. No known schema does this.What is not restored
2.1 source that uses a bare builtin scalar type with no import bringing in a type of that name (e.g. a script's
(s :: JSON!)) still fails as on v2.4.0. Restoring it would need the builtin JSON/YAML/TOML scalars back as types of their own, an identity-specific builtin the maintainer's principles rule out. How common: of ~171.dangfiles in dagger/dagger, 18 spell bareJSONas a type. All are generated entrypoints or engine entrypoint testdata, run with Dagger imported, so the gate covers them. None use bare JSON/YAML/TOML/Random/UUID as a type without such an import.Tests
pkg/dang/builtin_import_types_test.go:callend to end at runtime:JSON.encodeof a record holdingreceiverValue: JSON,(request :: JSON!)from a String, and a result the engine'sentrypointJSONResultaccepts. Covered in RunDir, RunFile, DeclareDir (signature), a LoadDir session, theContextWithVersion-pinned unpinned dir the engine uses, and 2.0/2.1.pkg/dang/migrate_import_types_test.go: the rewrite, auto-imports, declared/explicit names left alone, ambiguity,#nofmt, per-directory resolution, andBuiltinImportTypesfor schemas and Dang modules.TestImportTypesOverBuiltinImportsBefore2_4.go testforpkg/dang,pkg/dang/analysis,pkg/lsp,cmd/dangandtests(TestDang, incl. migrations), thego generatestale checks forpkg/dangandtreesitter(grammar.json unchanged), andfmt/stale.Release note
Dang source written for a version before 2.4 (e.g.
dang = "2.1") that spells a type bare, where an import brings in a type of that name and the name is also a builtin import (JSON, YAML, TOML, Random, UUID), compiles again: in type position, the bare name names the import's type. With Dagger imported, a bareJSONtype isDagger.JSON, so the Dang entrypoints the Dagger Go SDK generates work on Dang 2.4.JSON.encode/JSON.decodeand@JSON.fieldstill name the builtin. From Dang 2.4, the bare name is the builtin in type position too.dang migrate --to 2.4rewrites such types qualified (Dagger.JSON). It resolves the project's imports to find them, which can start a Dagger session. Pre-2.4 source that spelled the old builtinJSON/YAML/TOMLscalar types with no import of that name is not restored and must be migrated by hand (e.g. toString!orDecoded).