-
Notifications
You must be signed in to change notification settings - Fork 27
Paralellize and cache the creation of FileDescriptorProto #694
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
200b720
Add the FDS and FDP queries.
ckoutsidi-b f0ec7d6
Fix the linting errors and update the copyright year
ckoutsidi-b 10c91d8
Undo the year change
ckoutsidi-b de654fe
Makes the FDS and FDP queries harder to misuse.
ckoutsidi-b b7e4d8f
Rename FDP.go and FDS.go into lowercase
ckoutsidi-b edfe6e2
Do the requested changes
ckoutsidi-b fff036d
Finish the changed highlighted in the reviews. Fix exclude
ckoutsidi-b 127269d
satisfy the linter
ckoutsidi-b 50f30f0
Implement the latest feedback
ckoutsidi-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2020-2025 Buf Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package queries | ||
|
|
||
| import ( | ||
| "google.golang.org/protobuf/types/descriptorpb" | ||
|
|
||
| "github.com/bufbuild/protocompile/experimental/fdp" | ||
| "github.com/bufbuild/protocompile/experimental/incremental" | ||
| "github.com/bufbuild/protocompile/experimental/ir" | ||
| ) | ||
|
|
||
| // FDP is an [incremental.Query] that converts the lowered IR files [*ir.File] | ||
| // to [*descriptorpb.FileDescriptorProto] | ||
| // | ||
| // FDP queries with different File and Options are considered distinct. | ||
| // The File field must not be edited between different FDP queries! | ||
| type FDP struct { | ||
| *ir.File // Must be comparable. | ||
| fdp.Options | ||
| } | ||
|
|
||
| var _ incremental.Query[*descriptorpb.FileDescriptorProto] = FDP{} | ||
|
|
||
| // Key implements [incremental.Query]. | ||
| func (l FDP) Key() any { | ||
| return l | ||
| } | ||
|
|
||
| // Execute implements [incremental.Query]. | ||
| func (l FDP) Execute(t *incremental.Task) (*descriptorpb.FileDescriptorProto, error) { | ||
| t.Report().Options.Stage += stageFDP | ||
|
|
||
| return fdp.DescriptorProto(l.File, &l.Options) | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright 2020-2025 Buf Technologies, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package queries | ||
|
|
||
| import ( | ||
| "slices" | ||
|
|
||
| "google.golang.org/protobuf/types/descriptorpb" | ||
|
|
||
| "github.com/bufbuild/protocompile/experimental/fdp" | ||
| "github.com/bufbuild/protocompile/experimental/incremental" | ||
| "github.com/bufbuild/protocompile/experimental/ir" | ||
| "github.com/bufbuild/protocompile/experimental/source" | ||
| "github.com/bufbuild/protocompile/internal/ext/slicesx" | ||
| ) | ||
|
|
||
| // FDS is an [incremental.Query] that produces a [*descriptorpb.FileDescriptorSet]. | ||
| // It takes the IR files [ir.File] produced via [Link], topologically | ||
| // sorts the resulting IR files, and converts each to a [*descriptorpb.FileDescriptorProto] | ||
| // via [FDP]. It then bundles them all together into a [*descriptorpb.FileDescriptorSet]. | ||
| // | ||
| // FDS queries with different Openers, options, and workspaces are considered distinct. | ||
| type FDS struct { | ||
| source.Opener // Must be comparable. | ||
| *ir.Session | ||
| source.Workspace // Must be comparable | ||
| fdp.Options | ||
| } | ||
|
|
||
| var _ incremental.Query[*descriptorpb.FileDescriptorSet] = FDS{} | ||
|
|
||
| // Key implements [incremental.Query]. | ||
| func (l FDS) Key() any { | ||
| return l | ||
| } | ||
|
|
||
| // Execute implements [incremental.Query]. | ||
| func (l FDS) Execute(t *incremental.Task) (*descriptorpb.FileDescriptorSet, error) { | ||
| t.Report().Options.Stage += stageFDS | ||
|
|
||
| linkQuery := Link{ | ||
| Opener: l.Opener, | ||
| Session: l.Session, | ||
| Workspace: l.Workspace, | ||
| } | ||
|
|
||
| linkResult, err := incremental.Resolve(t, linkQuery) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| irs := linkResult[0].Value | ||
| irs = slices.DeleteFunc(irs, func(f *ir.File) bool { return f == nil }) | ||
|
|
||
| fdpQueries := slicesx.Transform( | ||
| slices.Collect(ir.TopoSort(irs)), | ||
| func(f *ir.File) incremental.Query[*descriptorpb.FileDescriptorProto] { | ||
| return FDP{ | ||
| File: f, | ||
| Options: l.Options, | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| fdpResults, err := incremental.Resolve(t, fdpQueries...) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| fdps, err := fdpResults.Slice() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| fdps = slices.DeleteFunc( | ||
| fdps, | ||
| func(fdp *descriptorpb.FileDescriptorProto) bool { return fdp == nil }, | ||
| ) | ||
|
|
||
| return &descriptorpb.FileDescriptorSet{File: fdps}, nil | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,4 +24,6 @@ const ( | |
| stageAST | ||
| stageIR | ||
| stageLink | ||
| stageFDP | ||
| stageFDS | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.