deep-gen

command
v6.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Command deep-gen generates reflection-free Patch, Diff, Equal and Clone methods for the types named by -type.

Field types are classified into four groups, which decide the code emitted for them:

  • Structs declared in the generated package (and pointers to them) have the generated methods, so field code calls Equal/Clone/applyOperation on them directly and patches can address sub-paths inside them.
  • Builtin comparable types, and named types over one, are compared with == and copied by assignment.
  • Anything else the generator can name — types from other packages such as time.Time, generic instantiations, arrays, interfaces — is opaque: it is named in type assertions but compared with deep.Equal, which dispatches to the type's own Equal method when it has one.
  • Types the generator cannot name (channels, funcs, qualifiers that resolve to no import) get no case at all, so applyOperation reports the operation as unhandled and the caller falls back to the reflection engine.

Embedded fields are addressed by their type name, the same way the language (and the reflection engine) names them.

The generator also inspects the package's type graph for two facts: cycles, and reference classes reachable by more than one route (two *Meta fields, a *time.Time next to a map[string]*time.Time, an interface next to any pointer). Types where either holds are "shared": their Clone threads a deep.CloneMemo so a value reached twice is copied once and cycles are rebuilt, their Equal threads a deep.VisitSet so comparison terminates, and their Diff threads a deep.DiffMemo so a pair is diffed once and every later route becomes one alias operation. Types where neither holds generate exactly the code they always did.

Generated code calls Equal, Clone and applyOperation on every struct declared in the package that a requested type references — directly, embedded, or as a collection element. Those structs must therefore also have generated code: list them in -type, or generate them in a separate run over the same package.

Imports are derived from the generated code itself, so a field type that refers to another package pulls that package in, and no import is emitted for code that ended up not being generated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL