-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix pre-computation of traits when loading dependency manifests #9057
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
bripeticca
merged 14 commits into
swiftlang:main
from
bripeticca:bug/showdepswithtraits
Sep 10, 2025
Merged
Fix pre-computation of traits when loading dependency manifests #9057
bripeticca
merged 14 commits into
swiftlang:main
from
bripeticca:bug/showdepswithtraits
Sep 10, 2025
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
The culprit here is the fact that we were essentially doing an AND boolean check across all the traits in the target dependency condition, when we should be doing an OR boolean check. If at least one trait is enabled in the list of traits in the target dependency condition, then the target dependecy should be considered enabled as well.
* Added a wrapper struct that contains a list of traits that could be passed as an argument + the expected output for said combination for TraitTests * Added extra test cases to traits-related Manifest tests, accounting for target dependencies that are enabled by many traits
* When applicable, the subscript for EnabledTraitsMap will now automatically form a union of the existing explicitly enabled traits for a package if the package identity exists as a key in the stored dictionary (meaning, if the package has already been assigned explicitly enabled traits rather than relying on "default" traits) * Clean up code surrounding the use of the traits map, namely the redundant checks on whether a package is defaulting to default traits vs. explicitly enabled traits * Add some TODOs in comments to address in next commit
Contributor
Author
|
@swift-ci please test |
Contributor
Author
|
@swift-ci please test |
Since the wrapper EnabledTraitsMap allows us to determine whether a package is using default traits by returning ["default"] in place of nil when a package has not yet been added to the stored dict, omit explicitly adding "default" to the dictionary itself. This will allow us to check whether we've explicitly modified the trait configuration for a given package, since it will override the default set of traits.
Contributor
Author
|
@swift-ci please test |
Contributor
Author
|
@swift-ci please test windows |
Contributor
Author
|
@swift-ci please test |
Contributor
Author
|
@swift-ci please test windows |
Contributor
Author
|
@swift-ci please test |
Contributor
Author
|
@swift-ci please test windows |
Contributor
Author
|
@swift-ci please test self hosted windows |
Update an area of code that used legacy methods to compute enabled traits of a dependency prior to the introduction of the EnabledTraitsMap.
Contributor
Author
|
@swift-ci please test |
Contributor
Author
|
@swift-ci please test windows |
Contributor
Author
|
@swift-ci please test self hosted windows |
2 similar comments
Contributor
Author
|
@swift-ci please test self hosted windows |
Contributor
Author
|
@swift-ci please test self hosted windows |
dschaefer2
approved these changes
Sep 10, 2025
bripeticca
added a commit
to bripeticca/swift-package-manager
that referenced
this pull request
Sep 15, 2025
…tlang#9057) This fix addresses some issues that arose with trait-based dependency resolution on Linux and, found through development, a related issue found involving the `swift package show-dependencies` command. It fixes an error that was thrown as a discrepancy in state when executing `swift package show-dependencies` if traits were guarding a dependency and was omitted from the package graph. Additionally, this will assure that the `EnabledTraitsMap` guards against explicitly adding "default" traits to the stored dictionary, since this wrapper is a mechanism to determine whether traits have been explicitly set (and therefore have overridden "default" or have flattened the list of default traits).
bripeticca
added a commit
to bripeticca/swift-package-manager
that referenced
this pull request
Sep 16, 2025
…tlang#9057) This fix addresses some issues that arose with trait-based dependency resolution on Linux and, found through development, a related issue found involving the `swift package show-dependencies` command. It fixes an error that was thrown as a discrepancy in state when executing `swift package show-dependencies` if traits were guarding a dependency and was omitted from the package graph. Additionally, this will assure that the `EnabledTraitsMap` guards against explicitly adding "default" traits to the stored dictionary, since this wrapper is a mechanism to determine whether traits have been explicitly set (and therefore have overridden "default" or have flattened the list of default traits).
bripeticca
added a commit
that referenced
this pull request
Sep 18, 2025
…ncy manifests (#9136) - **Explanation**: Fixes some errors in trait computation that hadn't considered when default traits `["default"]` were being appended to the `EnabledTraitsMap`, which should only consider a list of flattened traits + *explicitly enabled traits* by a user/parent package. The inclusion of `default` in this dictionary was resulting in an inaccurate computation of which traits were enabled, since pre-computation serves to flatten the list of transitively enabled traits for future reference. There were also cases where we were re-computing transitively enabled traits in areas where we had already filled out the `enabledTraitsMap`, so we now default to simply fetching the entry from the dictionary instead of computing the traits all over again. - **Scope**: Fixes trait-related computation in dependency resolution - **Issues**: - **Original PRs**: #9057 - **Risk**: Low risk - **Testing**: Added new fixtures + regression tests to address the behaviour that was previously incorrect. - **Reviewers**: @dschaefer2
bripeticca
added a commit
that referenced
this pull request
Sep 19, 2025
…tion when loading dependency manifests (#9141) - **Explanation**: Addresses multiple traits issues: - Changes the check for trait-guarded target dependencies to determine whether the package dependency from which it derives is used in the parent package; prior to this change, the check was asserting that *all* traits in the `when` condition of a target dependency were enabled for the dependency to be considered unguarded, but now the check confirms that *at least one* trait in the condition is enabled. - Fixes some errors in trait computation that hadn't considered when default traits ["default"] were being appended to the EnabledTraitsMap, which should only consider a list of flattened traits + explicitly enabled traits by a user/parent package. The inclusion of default in this dictionary was resulting in an inaccurate computation of which traits were enabled, since pre-computation serves to flatten the list of transitively enabled traits for future reference. There were also cases where we were re-computing transitively enabled traits in areas where we had already filled out the enabledTraitsMap, so we now default to simply fetching the entry from the dictionary instead of computing the traits all over again. - **Scope**: Package resolution stage; particularly affects pre-computation of transitively enabled traits when determining which target dependencies are/aren't guarded by traits. Also allows for multiple traits to be considered in a target dependency's `when` condition, any of which being enabled would then include said target dependency. - **Issues**: - **Original PRs**: #9015 #9057 - **Risk**: Low risk; fixes trait-related issues. - **Testing**: Fixtures added for end-to-end testing of the issue; regression tests added to multiple suites - **Reviewers**: @FranzBusch @jakepetroules @dschaefer2
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.
This fix addresses some issues that arose with trait-based dependency resolution on Linux and, found through development, a related issue found involving the
swift package show-dependenciescommand. It fixes an error that was thrown as a discrepancy in state when executingswift package show-dependenciesif traits were guarding a dependency and was omitted from the package graph.Additionally, this will assure that the
EnabledTraitsMapguards against explicitly adding "default" traits to the stored dictionary, since this wrapper is a mechanism to determine whether traits have been explicitly set (and therefore have overridden "default" or have flattened the list of default traits).