Skip to content

codegen: name Go identifiers via formatIdentifiers - #14673

Closed
vito wants to merge 17 commits into
naming/4-module-namingfrom
naming/5a-go-codegen
Closed

vito wants to merge 17 commits into
naming/4-module-namingfrom
naming/5a-go-codegen

Conversation

@vito

@vito vito commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Part 5a/N of the stack splitting #14501 (identifier casing). Plan: #14501 (comment)

Refs #13668

Stacked on #14669.

What it does

Go codegen names Go identifiers with the engine's Query.formatIdentifiers instead of golint's initialisms and strcase. Schemas without that field keep the old converters, so older engines and pre-v1 module views generate byte-identical code. Wire names (selected fields, argument names, enum values, GraphQL type names) never change.

This PR has two parts. The first commit is shared cmd/codegen infrastructure, and the other SDK PRs (5b–5h) build on it.

Shared codegen infrastructure (941227d)

  • cmd/codegen/introspection/names.go:
    • Schema.HasFormatIdentifiers is the gate.
    • Schema.Names collects every type, field, argument, input field and enum value name, leaving out introspection names and names the engine can't parse (_).
    • FormatNames / Schema.LoadFormattedNames batch the names through formatIdentifiers with the schema's own __schemaVersion dictionary, and Schema.FormattedName looks them up.
    • NameFormat is a CASING:ACRONYMS pair.
    • Include/Exclude keep the loaded names.
  • codegen introspect --names-out names.json --names SNAKE:UPPERCASE,PASCAL:CAPITALIZED: writes the formatted names as a sidecar, for SDK codegen that runs without an engine. A schema without the API gets {}.
  • Engine connection: codegen now connects whenever the schema it generates from has formatIdentifiers.
  • engine-dev: a new IntrospectionNames(formats) function produces the sidecar. The committed engine-dev bindings of docs-dev, release and the php/python/rust client toolchains are updated in 504b460.
  • cmd/codegen/internal/testnames: formats names like the engine does, for generator tests that run without one.
  • TestIdentifier/TestCodegenFormatNames (deferred from core: add formatIdentifiers naming API #14667) replaces TestViews and TestFormatSchemaNames. It covers the gate on __schemaJSONFile and live introspection at current and v0.21.0, and formats every core name against engine/naming.

Go

  • Formats:
    • PASCAL:UPPERCASE for types, methods, option struct fields and enum value suffixes.
    • CAMEL:UPPERCASE for parameters.
    • Both are loaded in generateCode and GenerateModule, before anything formats a name.
  • Deprecated Go aliases, now for core too: core: name modules with engine/naming from v1.0.0-beta.21 #14669's module-only machinery (legacyMethodName, FieldLegacyWrapper, InterfaceClientLegacyWrapper, LegacyFieldOptionsName, legacy enum constants) now covers every identifier whose Go spelling changed:
    • A renamed method gets a deprecated wrapper.
    • A renamed type or options struct gets a deprecated alias.
    • A renamed enum value gets a deprecated constant.
  • Enum value constants use the engine's PASCAL form. The UnmarshalJSON cases keep the legacy deduplication, so no wire name loses its case.
  • moduleNamer gate: it now checks for Query.formatIdentifiers in the schema, the same gate the generators and runtimes use, instead of comparing the schema version against v1.0.0-0.
  • Regenerated sdk/go. The repo's own callers move to the new names, because staticcheck flags the deprecated ones.

Changes for Go users

No hard breaks. Every renamed identifier keeps its old name as a // Deprecated: alias. Code that uses the old names keeps compiling, but staticcheck/SA1019 will warn. The renames in the core client:

before (deprecated) now
GitCommit.Sha, ShortSha, ParentShas SHA, ShortSHA, ParentSHAs
GitBundleRef.Sha, GitPushResult.Sha SHA
GeneratedCode.VcsGeneratedPaths, VcsIgnoredPaths VCSGeneratedPaths, VCSIgnoredPaths
Workspace.Sdks SDKs
SshfsVolume, SshfsVolumeOpts SSHFSVolume, SSHFSVolumeOpts
NetworkProtocolTcp / Udp NetworkProtocolTCP / UDP
RegistryProtocolHttp / Https RegistryProtocolHTTP / HTTPS
ImageLayerCompressionEstarGz ImageLayerCompressionEStarGZ
ImageMediaTypesOcimediaTypes / Oci ImageMediaTypesOCIMediaTypes / OCI

Parameter names change too (callId → callID), which doesn't affect callers. Go modules get the same treatment at codegen time when their schema has formatIdentifiers (engine v1 views).

Not in it

  • PR 6 material: core schema renames (callID, pushURL, shortSHA, ...), and with them the old-schema-names table (cmd/codegen/introspection/renamed.go) and its uses in legacyFieldSchemaName/legacyArgSchemaName. Core legacy names here come only from Go formatting changes.
  • TypeScript and the other SDKs: these are PRs 5b–5h, built on the first commit.
  • In-repo modules' dagger.gen.go: not regenerated (decision 22). go-sdk/generate/stale was not run.
  • Public schema: unchanged.

Testing

  • go build ./..., go vet (main module, sdk/go, the touched toolchain modules)
  • go test ./cmd/codegen/...:
    • names, gate, formats and the names file
    • Go engine names for objects and enums (goldens)
    • legacy aliases for modules and core
    • the module alias surface at v1.0.0
    • the moduleNamer gate
  • Checks: golangci-lint/lint-all, go-client/generate/stale, go-client/test
  • Integration:
    • TestIdentifier
    • TestModuleNaming
    • TestModule/TestModuleEntrypointLegacyNameAliases
    • TestGo
    • TestModule/(TestModuleEnum*|TestSelfCalls*|TestUseLocalDependency*|TestModuleDeprecation*)
    • TestGit/(TestGitCommit|TestGitLog|TestGitBundlePreservesAnnotatedTag)
    • TestContainer/(TestMediaTypes|TestForceCompression)
    • TestVolume/TestSSHFS*

vito added 17 commits October 10, 2026 22:14
A list of plain values (Array, DynamicArrayOutput) gave each element a result
of its own when resolving the response: a deep copy of the list's call frame,
and for a cached list, a cache entry per element. For a call with a large list
argument that is quadratic: formatIdentifiers with the core schema's 961 names
spent ~250ms on per-element cache entries, and ~100ms copying frames when
uncached. Leaf elements need no result, so read them straight from the list.

Signed-off-by: Alex Suraci <[email protected]>
NameAliases builds the dagql.Aliases for an old spelling of a renamed core
type, field, argument or enum value, accepted only on the views with the new
naming rules (v1.0.0 and later). ModuleNameAliases is the same for a
module's declarations, accepted on every view: a module's names follow its
own engine version, not its caller's view. Every transition alias goes
through one of them, so ending the transition is deleting them and their
callers.

Nothing calls them yet.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
The in-engine Dang runtime typechecks its callers against its dependencies'
schema JSON, so a Dang caller using an old name (like go-sdk's
.generate(legacyJson: ...)) would fail to typecheck even though the engine
accepts the alias. __schemaJSONFile gets an internal includeAliases argument
that adds the field, argument and enum value aliases, deprecated, and
SchemaIntrospectionJSONFileForDang asks for it. Type aliases stay out: a
copy of a type would be a different type to Dang. Other SDKs keep the
alias-free JSON, since their generators would collide on the aliases.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
Expose engine/naming through Query.identifier, Query.formatIdentifiers and
Query.namingDictionary, with the Identifier, IdentifierWord, NamingTerm,
IdentifierWordKind, Casing and AcronymStyle types. The API is experimental
and only served at v1.0.0 views (IdentifierNamingVersion, v1.0.0-0),
prereleases included.

formatIdentifiers returns plain strings so SDK codegen can format thousands
of names in one round trip, takes the engine version whose dictionary to use
(codegen passes the __schemaVersion it generates for), and skips the cache:
formatting is far cheaper than publishing a result with a large list
argument.

Identifiers persist their words rather than re-parsing, so a cached value
keeps formatting the same way if the dictionary changes.

Signed-off-by: Alex Suraci <[email protected]>
Add the identifier casing API to the GraphQL schema snapshot and the API
reference pages.

Signed-off-by: Alex Suraci <[email protected]>
Pure additions: the Go, Python, TypeScript, Rust, Elixir and PHP core
bindings for Query.identifier, Query.formatIdentifiers,
Query.namingDictionary and their types.

Signed-off-by: Alex Suraci <[email protected]>
Types, fields, arguments, input object fields, struct-tag fields and enum
values can declare Aliases: old spellings that queries may still use after a
rename, optionally limited to some views. They exist only in the schema
queries are validated against (SchemaWithAliasesForView, also what gqlgen's
handler validates with). Schema and SchemaForView, and so introspection,
codegen and the schema JSON, never show them: SDK generators would collide
on them (legacyJson and legacyJSON both become LegacyJSON in a Go opts
struct).

Field, argument and type aliases are rewritten to the canonical name when
the query is parsed, so an aliased query makes the canonical calls: same IDs,
same cache entries. Type aliases match in fragment type conditions,
including node(id:) { ... on OldName }. Enum value and input object field
aliases are input only: the enum's or input object's decoder resolves them,
so literals, variables and plain strings all decode to the canonical value.
EnumValues.RenameView gives a value a new name in some views, for renaming
a core enum's values on v1 views while older views keep the old names.

Each use adds a dagger.io/dag.alias event to the current span. Aliases
colliding with a real name, or claimed by two names, are ignored, and they
count toward the schema digest. Nothing registers an alias yet.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
Modules that declare engine version v1.0.0-0 or later (every v1.0.0
prerelease, since the gate is a view and views are base-version granular),
and manifest v2 entrypoints, which are served at the engine's own version, now
get their schema names from engine/naming instead of strcase: HTTPClient stays
HTTPClient instead of Httpclient, e2eTest is no longer E_2_E_TEST, and so on.
Older modules keep the strcase rules byte for byte.

core.Namer carries the choice. The typedef constructors (function, withArg,
withObject, withField, withEnumMember, ...) record the caller's view and
normalize with NamerFromContext, so a module's runtime names by the version it
declares; the in-engine Dang runtime stamps that view on the selectors it makes
(dangshared.NamingSelectors). Constructors, namespacing, CLI paths, include
patterns and artifact paths follow the owning module's Namer, and lookups of
user-typed names try both spellings.

Every name the new rules changed keeps its legacy spelling as a hidden alias,
accepted on every view (ModuleNameAliases): constructors, types, functions,
fields, arguments and enum members (decoded by the enum, via
EnumMemberTypeDef.LegacyName). A module's names follow its own version, not its
caller's, so callers generated against the old names keep working.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
The CLI derives command, flag and type names from schema names. It now spells
them by the naming rules of the engine version it ships with (e2eTest is
--e2e-test, not --e-2-e-test): the typedefs it loads don't say which engine
version each module declares, and a client follows the version it connects
with.

What users type still resolves by the legacy rules too: legacy flag spellings
normalize to the current ones, legacy command spellings are cobra aliases and
are matched by the shell and sibling-entrypoint lookups (fn-2 for fn2), and
module constructors and type names match either spelling. Enum flags and
collection keys take a member in any case, or else the single member that
matches once '_' and '-' are ignored, so legacy member spellings (ARM_64 for
ARM64), which the engine only knows as hidden aliases, still work; the CLI
sends the canonical name.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
The Go SDK computes the schema names of a module's own types, fields and
arguments itself: in the introspection JSON it merges into the schema for
self-call bindings, and in the queries of interface implementations. They must
match the engine's or references break, so they now follow the same gate:
engine/naming for modules at v1.0.0-0 and up (the schema version is the
module's view), strcase before. References to core and dependency types resolve
like the engine's depTypeReference fallback does.

cmd/codegen can't import core, so moduleNamer (module_naming.go) mirrors
core.Namer.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
Go modules regenerate their bindings at every load, so a dependency module
renamed by the new naming rules (daggerCli is daggerCLI, DaggerCli is
DaggerCLI) would break their build on engine upgrade.

Keep the old identifiers as deprecated aliases: wrapper methods, type aliases,
option struct aliases, extra option struct fields and enum constants, also
re-exported from internal/dagger. The schema hides the engine's aliases, so a
module's old schema names are recovered by applying the legacy strcase namer
to the current ones. Core declarations' names didn't change, so the core output
is unchanged.

This is the module-only part of the Go alias machinery (naming.go,
FieldLegacyWrapper, LegacyFieldOptionsName, ...): the Go client codegen change
that formats names through the engine extends it to core names.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
ModuleNamingSuite covers a Go module at the current engine version (acronym
types, fields and arguments keep their casing; references to JSONValue,
LLMMessage and LLMTokenUsage resolve to the core types; legacy field, argument,
type and enum member spellings are still accepted, in queries and in dagger
call), the same module at v1.0.0 prereleases (new names) and before v1.0.0
(strcase names, byte for byte), a Python module naming its types like the Go
one, and the CLI flag for an E2E-style argument under both.

TestModuleEntrypointLegacyNameAliases covers a manifest v2 entrypoint, which is
served at the engine's version, answering to its legacy names. Existing
expectations follow the new names: comURL for a Python com_url argument, and
the dagger functions table padded to experimental-with-all-gpus.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
cmd/codegen's Go generator now imports engine/naming (moduleNamer), so
generating the Go SDK client failed to build codegen without it.

Refs #13668

Signed-off-by: Alex Suraci <[email protected]>
Add the shared codegen side of identifier casing: introspection.FormatNames
and Schema.LoadFormattedNames ask Query.formatIdentifiers to format every
schema name, with the naming dictionary of the schema's own version, and
keep the results on the schema for FormattedName. A schema without
Query.formatIdentifiers formats nothing, so generators keep their legacy
converters and older schemas generate the same code.

- codegen connects to the engine whenever the schema it generates from
  has Query.formatIdentifiers.
- `codegen introspect --names-out names.json --names SNAKE:UPPERCASE,...`
  writes the formatted names as a sidecar for SDK codegen that runs
  without an engine, and engine-dev gains IntrospectionNames to produce it.
- cmd/codegen/internal/testnames formats names like the engine, for
  generator tests without one.
- TestIdentifier/TestCodegenFormatNames covers the gate and the
  formatting against a live engine.

Signed-off-by: Alex Suraci <[email protected]>
Go codegen now loads the schema's names formatted by the engine
(PASCAL:UPPERCASE for types, methods, option fields and enum values,
CAMEL:UPPERCASE for parameters) and uses them for every Go identifier.
Schemas without Query.formatIdentifiers keep golint's initialisms and
strcase exactly as before, so older engines and module views generate
byte-identical code. Wire names never change.

The module-only alias machinery from module naming now covers every
identifier the engine's formatting renamed, core included: a renamed
method keeps a deprecated wrapper, a renamed type or options struct a
deprecated alias, and a renamed enum value a deprecated constant
(Sha -> SHA, NetworkProtocolTcp -> NetworkProtocolTCP).

moduleNamer now gates on Query.formatIdentifiers being in the schema,
like the generators and module runtimes, instead of comparing the
schema version against v1.0.0-0 itself.

Signed-off-by: Alex Suraci <[email protected]>
Regenerate the Go client from a schema with Query.formatIdentifiers, so
its identifiers follow engine/naming: Sha is SHA, ParentShas ParentSHAs,
SshfsVolume SSHFSVolume, Workspace.Sdks SDKs, NetworkProtocolTcp
NetworkProtocolTCP, ImageMediaTypesOcimediaTypes
ImageMediaTypesOCIMediaTypes, and so on. Every old name stays as a
deprecated alias, so existing code keeps compiling.

Move the repo's own callers to the new names, since staticcheck flags
the deprecated ones.

Signed-off-by: Alex Suraci <[email protected]>
Add IntrospectionNames to the committed engine-dev bindings of the
modules that depend on it (docs-dev, release, and the php, python and
rust client toolchains), as their codegen would, so the SDK PRs that
use it don't each have to touch them.

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Closing: the in-repo SDKs are now legacy. The module-codegen naming work here (Go codegen via formatIdentifiers, module_naming.go, the shared names.go / --names-out infra) will be ported to github.com/dagger/go-sdk (identifier-casing branch) once the engine side lands. The branch stays as reference, and as the base of the still-open Rust (#14675) and .NET (#14676) PRs.

@vito vito closed this Oct 22, 2026
vito added a commit to dagger/go-sdk that referenced this pull request Oct 22, 2026
When the schema being generated has Query.formatIdentifiers (engine API views
from v1.0.0-beta.21), Go identifiers follow the engine's naming rules for the
schema's version: PASCAL:UPPERCASE for types, methods, option fields and enum
values, CAMEL:UPPERCASE for parameters (ShortSha -> ShortSHA,
NetworkProtocolTcp -> NetworkProtocolTCP, SshfsVolume -> SSHFSVolume). A
schema without the field keeps golint's initialisms and strcase byte for byte,
whatever version it claims. Wire names never change.

The names are formatted with the vendored rules rather than by asking the
engine: the generators run without an engine connection. Ported from
dagger/dagger#14673 (c7582fd) without its deprecated aliases for renamed
identifiers. Names only change when a module or client declares beta.21 or
later, so that is an opt-in, not an engine upgrade.

Signed-off-by: Alex Suraci <[email protected]>
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