-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Conversation
I've cleaned this up now - ready for review! |
ae543b4
to
8d8c734
Compare
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 |
There was a problem hiding this 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! 👍
There was a problem hiding this 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.
This is a partial fix of #46
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.