-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Cherry-pick Assure trait-guarded dependencies are not included in resolution; precompute enabled traits before resolution (#8852) #8948
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
Conversation
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
…compute enabled traits before resolution (swiftlang#8852) Trait-guarded dependencies were still being considered during dependency resolution, when they should be excluded if they aren't being used in any other scenario. Additionally, enabled traits should be pre-computed before entering the resolution stage in order to avoid possible race conditions when navigating through the dependency graph nodes. Since we have the `--experimental-prune-unused-dependencies` feature behind an experimental flag, we'll now consider an alternate path that will prune trait-guarded package dependencies from the dependency graph **_if and only if_** said dependency is not used in any other unguarded context. A dictionary wrapper titled `EnabledTraitsMap` is used to store the enabled traits per package for the package graph and is stored as a property within the `Workspace`, with some additional behaviour to return a `["default"]` set of traits if the package has not yet been stored in the dictionary, rather than returning `nil`. Following this behaviour, when passing a set of traits to methods that require them (e.g. for dependency computation, enabled trait computation, etc.) we now require that it is not Optional, since the checks done on a `nil` set of traits were redundant. SwiftCommandState now also stores a `TraitConfiguration`, since we'll want access to this across multiple `SwiftCommand`s, and it is essentially a part of the state anyhow. `TraitOptions` is now included in the `GlobalOptions` for `SwiftCommand`s to supplement this, so that when a `SwiftCommandState` is created we will have access to the user-passed enabled traits. These options, as entitled, are available globally across all the swift package commands, so previous properties that declared `TraitOptions` in these commands has been removed in favour of using it straight from the `GlobalOptions`. Trait-guarded dependencies are excluded from dependency resolution, and since traits are pre-computed there should no longer be an issue with race conditions for traits in resolution as well.
@swift-ci please test |
@swift-ci please test |
@swift-ci please test windows |
@swift-ci please test |
@swift-ci please test windows |
1 similar comment
@swift-ci please test windows |
dschaefer2
approved these changes
Jul 18, 2025
@swift-ci please test windows |
1 similar comment
@swift-ci please test windows |
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.
Cherry pick of #8852
Trait-guarded dependencies were still being considered during dependency
resolution, when they should be excluded if they aren't being used in
any other scenario. Additionally, enabled traits should be pre-computed
before entering the resolution stage in order to avoid possible race
conditions when navigating through the dependency graph nodes.
Modifications:
Since we have the
--experimental-prune-unused-dependencies
featurebehind an experimental flag, we'll now consider an alternate path that
will prune trait-guarded package dependencies from the dependency graph
if and only if said dependency is not used in any other unguarded
context.
A dictionary wrapper titled
EnabledTraitsMap
is used to store theenabled traits per package for the package graph and is stored as a
property within the
Workspace
, with some additional behaviour toreturn a
["default"]
set of traits if the package has not yet beenstored in the dictionary, rather than returning
nil
.Following this behaviour, when passing a set of traits to methods that
require them (e.g. for dependency computation, enabled trait
computation, etc.) we now require that it is not Optional, since the
checks done on a
nil
set of traits were redundant.SwiftCommandState now also stores a
TraitConfiguration
, since we'llwant access to this across multiple
SwiftCommand
s, and it isessentially a part of the state anyhow.
TraitOptions
is now includedin the
GlobalOptions
forSwiftCommand
s to supplement this, so thatwhen a
SwiftCommandState
is created we will have access to theuser-passed enabled traits. These options, as entitled, are available
globally across all the swift package commands, so previous properties
that declared
TraitOptions
in these commands has been removed infavour of using it straight from the
GlobalOptions
.Result:
Trait-guarded dependencies are excluded from dependency resolution, and
since traits are pre-computed there should no longer be an issue with
race conditions for traits in resolution as well.