Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations generate a name collision - fixed #539

Merged
merged 1 commit into from
Aug 7, 2023

Conversation

davidhubbard
Copy link
Collaborator

This is a partial fix of #46

zombiezen commented on Aug 22, 2016:

One of the notable examples is in persistent.capnp that the annotation and
the type collide.

Also see capnproto/capnproto#323

This commit changes the generated code for all annotations that start with a lowercase letter. Since the generated code in Go must start with an uppercase letter to be valid Go, this change appends an "_" to the name, regardless of whether there is a name collision already. (The thinking is that a name collision can happen in the future, and the renaming must be strictly an injective function, meaning that Go identifiers are always chosen the same regardless of other names. This way the codegen will not cause painful refactors in other code due to a name change later.)

The capnp files in this repo under std all have $Go.name() annotations due to this bug. This removes one of them (std/capnp/persistent.capnp) and replaces it with a unit test that compiles the generated code. Actually doing a "go build" is one step father than previous unit tests.

The thinking is to not add too many calls to "go build," since there is a lot of overhead and slow unit tests are discouraging. This commit appears to add about 250ms to the time it takes to run a "go test" in the capnpc-go subdir.

@davidhubbard
Copy link
Collaborator Author

davidhubbard commented Aug 7, 2023

I've cleaned this up now - ready for review!

@davidhubbard davidhubbard added this to the 3.0 milestone Aug 7, 2023
@davidhubbard
Copy link
Collaborator Author

level0_test.go:2270: log level error: rpc: incoming disembargo: send receiver loopback: send message: rpc: build message: target for receiver loopback does not point to the right connection (args: map[]) senderpromise_test.go:404: Received unexpected error: test.capnp:PingPong.echoNum: call on null client

The current CI status already had that error. This PR doesn't address it, but at least it wasn't caused here. See previous CI builds

Copy link
Collaborator

@lthibault lthibault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a first pass to pick out things that jump out. Digging in more deeply now.

Looks great so far! 👍

capnpc-go/capnpc-go_test.go Show resolved Hide resolved
lthibault
lthibault previously approved these changes Aug 7, 2023
Copy link
Collaborator

@lthibault lthibault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is easily one of the best PRs I've ever seen! Thanks for your contribution -- approved! 🎉

This is a partial fix of capnproto#46

> zombiezen commented on Aug 22, 2016:
>
> One of the notable examples is in persistent.capnp that the annotation and
> the type collide.

Also see capnproto/capnproto#323

This commit changes the generated code for all annotations that start with
a lowercase letter. Since the generated code in Go must start with an
uppercase letter to be valid Go, this change appends an "_" to the name,
regardless of whether there is a name collision already. (The thinking is
that a name collision can happen in the future, and the renaming must be
strictly an injective function, meaning that Go identifiers are always
chosen the same regardless of other names. This way the codegen will not
cause painful refactors in other code due to a name change later.)

The capnp files in this repo under `std` all have $Go.name() annotations
due to this bug. This removes one of them (std/capnp/persistent.capnp) and
replaces it with a unit test that compiles the generated code. Actually
doing a "go build" is one step father than previous unit tests.

The thinking is to not add too many calls to "go build," since there is a lot
of overhead and slow unit tests are discouraging. This commit appears to add
about 250ms to the time it takes to run a "go test" in the capnpc-go subdir.

This also tweaks templates/interfaceClient to fix a problem if an interface is
empty. The {{range .Methods -}} block in interfaceClient has a side effect of
marking the "context" package for import, and an empty interface skips that.
Since Resolve() also depends on the "context" package, this adds a call to
{{$.G.Imports.Context}}.Context to ensure it also marks "context" as used.
@davidhubbard davidhubbard merged commit 163c79d into capnproto:main Aug 7, 2023
0 of 4 checks passed
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.

2 participants