Make bufimagebuild.Builder take a Module instead of a ModuleFileSet#2212
Merged
Make bufimagebuild.Builder take a Module instead of a ModuleFileSet#2212
Conversation
Member
Author
|
Note this PR could be considered somewhat controversial, so we should discuss tomorrow. I can see arguments both ways on it. |
Member
Author
|
Some notes for discussion:
The storagemem stuff could/should be split out into a separate PR if we pursue this. |
Member
Author
|
Other comment: the inheritance throughout the types in |
mfridman
approved these changes
Jun 20, 2023
Member
Author
|
Talked offline: we're merging this for now as it's a net win, and will continue to make improvements as we go. Next up is a better module testing framework, and eliminating |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A very common operation we want to do throughout our codebases is go from a
Moduleto anImage. However, you can't - the question would be, why not?The answer is that we have an intermediate state, a
ModuleFileSet, that "flattens" aModulefrom what amounts to a set of .proto files and a lock file, to a set of combined .proto files that represent both the module's .proto files and the dependencies' .proto files. This is what we pass to i.e.protocompile. Currently, to compile aModule, you first need to make aModuleFileSet, and then pass theModuleFileSetto thebufimagebuild.Builder.This can make some kind of sense in the abstract, but in practice, 99.9% of our usage of
bufimagebuild.Imageis someone creating aModuleFileSetBuilderright before, creating aModuleFileSet, and then creating anImage. This is wasteful and confusing to those who don't fully understand the (convoluted) type system inbufmodule- you should be able to go right from aModuleto anImage.On top of this, confusingly,
ModuleFileSetinherits fromModule, which causes a host of issues. There are places in the code where one might be expecting aModule, but are instead passed aModuleFileSet, which stealthily modifies the behavior ofGetModuleFilesuch that files from both the sources and dependencies will be returned. You could, in fact, also create aModuleFileSetfrom aModuleFileSet, recursive behavior that our code does not actually handle (and will result in a bug from duplicate files).It's been a longstanding TODO in the codebase to eliminate
ModuleFileSetaltogether, and instead just useModules, perhaps with a function onModuleAllFiles()that returns what amounts to aModuleFileBucket, a type that will be completely distinct fromModule.This PR does the first step of this: it changes
bufimagebuild.Builderto take aModuleinstead of aModuleFileSet, and then just inlines the (very) simple operation thatModuleFileSetdoes. To do this,bufimagebuild.Buildernow takes aModuleReaderdirectly. In practice, in our codebase, this eliminates a lot of extra code to use aModuleFileSet, and makes it easier for future developers to understand how to do fromModulestoImages.One thing that is a little more complicated with this is some unit testing we do around modules and their dependencies - often, you want to pass a manually-built
ModuleFileSetto thebufimagebuild.Builder. To help with this, new functions have been added tobufmoduletestingwith examples to provide functionality to build test lock files and testModuleReaders.One pain point is
buf export, which actually needs both the equivalent ofModuleFileSets, and the ability to build anImage, but this is minor and can be dealt with whenModuleFileSetsare actually eliminated. However, for now during this migration,bufimagebuild.Builderhandles the case if aModuleis actually aModuleFileSet, and does not call theModuleFileSetBuilderin this case.A PR in core will be done in conjunction with this PR to handle the new behavior.
This PR also reverts the addition of
NewReadWriteBucketWithOptionsinstoragemem, which isn't consistent with the rest of our codebase.