Use depset instead of mutable lists #633
Merged
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.
Because of the implementation of
rust_test
we have to providesrcs
,deps
, andproc_macro_deps
inCrateInfo
so the test can fetch those and pass them together with its own sources and dependencies torustc
.Currently a Rust library provides 2 providers: (1)
CrateInfo
describing the target, and (2)DepInfo
describing its dependencies. The first thing that downstream libraries do is they get transitive depset fromDepInfo
, and putCrateInfo
as direct.This could be improved by putting
CrateInfo
intoDepInfo
already in the target that provides it - there would be only one depset created, not one per downstream dependency. The problem is though that forrust_test
we cannot put theCrateInfo
into the depset because Starlark sees it as mutable, and the cause is the use of a concatenated list. How come it worked before? Well, before the list came from a provider from a different target, so it was frozen. Now we are creating the provider, and our lists are not frozen.I tried to lament this a bit and IMHO using depsets (which are frozen upon construction) is the best immediate step. I have a followup PR that modifies
DepInfo
so linking with complicated C++ dependency graphs works correctly, and that's where I encountered this problem (and that's where I extracted this PR from).