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

Generated code is not reproducible when multiple plugins are specified #474

Closed
ashi009 opened this issue Dec 14, 2017 · 7 comments
Closed

Comments

@ashi009
Copy link

ashi009 commented Dec 14, 2017

So far this is not a problem, as there is only one plugin built in to protoc-gen-go. However when more than one plugin is registered the generator may behave unexpectedly.

This is caused by two issues:

  1. RegisterPlugin is called from init() and the execution sequence is not guaranteed (though it's possible to manually control the import sequence and hope go doesn't change it's behavior on handling import packages).
  2. Registered plugins are filtered against the list of plugin to use from user input at runtime. Meaning, the order of plugins to use doesn't affect the final output -- it will always be unpredictable. What makes things worse is that, unknown plugin will be ignored silently.

I think the second place is the best place to fix this issue.

@dsnet
Copy link
Member

dsnet commented Dec 14, 2017

The Go language spec specifies that package initialization occurs in declaration order. Given that, I don't really see an issue.

@dsnet dsnet added this to the Unplanned milestone Dec 14, 2017
@ashi009
Copy link
Author

ashi009 commented Dec 14, 2017 via email

@dsnet
Copy link
Member

dsnet commented Dec 14, 2017

The generator plugin API is something that could use an overhaul. We probably don't have time to think about it today, but will keep this issue in mind for the future.

@paranoiacblack
Copy link
Contributor

@ashi009 Can you provide any motivating examples where this problem shows up? It seems like it needs to be up to each plugin to directly specify which stage of plugin initialization it belongs to. If that were the case, we could lazily register plugins. There's probably no way the Go tool or the compiler will be able to deduce this, although package initialization order is really close.

@dsnet
Copy link
Member

dsnet commented Mar 8, 2018

At the present time, we want to hold to a harder stance that 3rd party plugins added via generator.RegisterPlugin are not well supported. It is very difficult making changes to protoc-gen-go without breaking any arbitrary registered plugin. The best path forward would be to just fork generator for your own purposes.

@dsnet dsnet closed this as completed Mar 8, 2018
@dsnet
Copy link
Member

dsnet commented Mar 8, 2018

Filed #547 as an umbrella for better plugin support.

@ashi009
Copy link
Author

ashi009 commented Mar 8, 2018 via email

@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants