You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It makes output deterministic. Currently, changing the order of input files, or even adding a new import to one file can result in changes to other files.
It's a big step towards being able to generate files one at a time, or multiple packages at a time, as protoc does for other languages. Numerous people have requested this, the ability to generate file-at-a-time was only recently broken, and it's otherwise easy to fix.
It cleans up the generated code when multiple plugin-plugins use the same packages.
I am happy to write this code if there's general support, and I don't believe the changes would be intrusive.
Current operation
Currently, plugins call RegisterUniquePackageName once per imported name. This happens globally (ie. once per run).
This would generate an import statement in the output, as well as returning a prefix string to use when referring to objects from that package.
If importPath is the same package as the FileDescriptor, no import is generated, and an empty prefix is returned.
If importPath has already been imported in the file, no import is generated, and the previous prefix is returned.
If desiredName has already been used by a different import in this file, or reserved by RegisterUniquePackageName, a unique import alias is generated for the import. The prefix returned is the alias followed by . The alias is added to the blacklist used by RegisterUniquePackageName.
This change would allow incremental movement from RegisterUniquePackageName towards WriteImport, and both could coexist.
Support for plugins in general needs to be discussed. If we decide to provide first-class support for plugins, there will probably be an entire redesign.
Goal
per-file import uniquification
Why?
I am happy to write this code if there's general support, and I don't believe the changes would be intrusive.
Current operation
Currently, plugins call
RegisterUniquePackageName
once per imported name. This happens globally (ie. once per run).Proposed addition
Add a method
WriteImport(f *FileDescriptor, desiredName string, importPath string) (prefix string)
This would generate an
import
statement in the output, as well as returning a prefix string to use when referring to objects from that package.importPath
is the same package as the FileDescriptor, no import is generated, and an empty prefix is returned.importPath
has already been imported in the file, no import is generated, and the previous prefix is returned.desiredName
has already been used by a different import in this file, or reserved byRegisterUniquePackageName
, a unique import alias is generated for the import. The prefix returned is the alias followed by.
The alias is added to the blacklist used byRegisterUniquePackageName
.This change would allow incremental movement from
RegisterUniquePackageName
towardsWriteImport
, and both could coexist.@dsymonds @jhump @tamird @awalterschulze
The text was updated successfully, but these errors were encountered: