Skip to content

Commit

Permalink
pkg/gen: generate (almost) all pkg.go files in one call
Browse files Browse the repository at this point in the history
This change centralizes the pkg code generation to a single call
to `go run pkg/gen` instead of having an individual invocation of `go run gen.go`
inside each package. The `go:generate` line is moved into `pkg/gen.go`.

This significantly speeds up code generation (from ~15s to ~3s when I last tested it).

We also avoid the cyclic dependency of the code generator on the code that's been
generated by avoiding the use of `cue/load` which depends in turn on the standard
library which is generated by `pkg/gen`.

This is an intermediate step towards refactoring the pkg code generation to
allow easy specification of arbitrary function signatures.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I118d678809e33da3349b598967967bda91613cfd
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/538503
Reviewed-by: Marcel van Lohuizen <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
rogpeppe committed Jun 27, 2022
1 parent b30eb99 commit 23dc354
Show file tree
Hide file tree
Showing 33 changed files with 210 additions and 223 deletions.
4 changes: 2 additions & 2 deletions cue/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func compileInstances(r *Runtime, data []*instanceData) (instances []*Instance,
return r.build(builds)
}

// Unmarshal creates an Instance from bytes generated by the MarshalBinary
// method of an instance.
// Unmarshal returns a slice of instances from bytes generated by
// Runtime.Marshal.
func (r *Runtime) Unmarshal(b []byte) ([]*Instance, error) {
if len(b) == 0 {
return nil, errors.Newf(token.NoPos, "unmarshal failed: empty buffer")
Expand Down
5 changes: 1 addition & 4 deletions pkg/crypto/ed25519/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/crypto/hmac/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/crypto/md5/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/crypto/sha1/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/crypto/sha256/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/crypto/sha512/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/encoding/base64/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/encoding/csv/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/encoding/hex/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/encoding/json/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions pkg/encoding/yaml/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package pkg

//go:generate go run ./gen
Loading

0 comments on commit 23dc354

Please sign in to comment.