Skip to content

Actually skip not needed dependencies during dependency resolution #3166

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 3 commits into from
Jan 11, 2021

Conversation

neonichu
Copy link
Contributor

@neonichu neonichu commented Jan 7, 2021

This is a follow-up to #3162. While that brought back the code for dependenciesRequired(for:), the guard based on productFilter actually made it so that it was practically never executed. Instead, the guard should be based on whether the package in question is a root package.

Additionally, this made the order of the returned dependencies unstable, due to use of Set. Since dependenciesRequired(for: keepUnused:) is now only used if ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION is set, I removed some dead code from there as well.

@neonichu
Copy link
Contributor Author

neonichu commented Jan 7, 2021

@swift-ci please smoke test

@neonichu
Copy link
Contributor Author

neonichu commented Jan 7, 2021

We actually always create PackageDependencyDescription with a .everything product filter initially (see here). With enabled target-based dependency resolution, we would later apply a specific filter here, but that code is never executed now.


let dependenciesByURL = Dictionary(dependencies.map({ ($0.url, $0) }), uniquingKeysWith: { $1 })
let requiredDependencies = requiredDependencyURLs.compactMap({ dependenciesByURL[$0] })
return requiredDependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks as though the dependencies will still be returned in arbitrary order. Should they be sorted by URL as they're converted from Set to Array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I wonder how this used to work? I actually went back to the old implementation here (just swapping name for URL).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, I think we can just return self.dependencies (which is already sorted as desired) filtered by requiredDependencyURLs.

@neonichu neonichu force-pushed the semi-target-based-dependencies-2 branch from 58d25eb to b2f40e2 Compare January 7, 2021 23:33
@neonichu
Copy link
Contributor Author

neonichu commented Jan 7, 2021

@swift-ci please smoke test

@tomerd
Copy link
Contributor

tomerd commented Jan 8, 2021

could we add a test for this?

@MaxDesiatov
Copy link
Contributor

Is there any chance this could be cherry-picked for release/5.4?

@neonichu
Copy link
Contributor Author

neonichu commented Jan 8, 2021

@MaxDesiatov yep, the intent is for this to be in 5.4 since this really should have been part of #3162

@neonichu
Copy link
Contributor Author

neonichu commented Jan 8, 2021

@tomerd I think we probably already have a test for this, but it is disabled/skipped as part of ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION. I'll dig up the right test(s) to re-enable.

@neonichu
Copy link
Contributor Author

neonichu commented Jan 9, 2021

@swift-ci please smoke test

@neonichu
Copy link
Contributor Author

neonichu commented Jan 9, 2021

I re-enabled the one test that is relevant for this, but it might make sense to resurrect a few more tests in a follow-up PR. When I initially introduced ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION I thought of it as a very temporary stop gap, so I didn't go through the effort of making some existing tests work in either mode, but we might want to reconsider that.

@neonichu
Copy link
Contributor Author

neonichu commented Jan 9, 2021

@tomerd looks like one of the new tests is potentially flaky? 🤔

/home/buildnode/jenkins/workspace/swift-package-manager-self-hosted-Linux-smoke-test/branch-main/swiftpm/Tests/WorkspaceTests/WorkspaceTests.swift:5108: error: WorkspaceTests.testDuplicateNestedTransitiveIdentityWithoutNames : XCTAssertTrue failed - unexpected failure matching 'product 'BarProduct' not found in package 'BarPackage'. it is required by package 'FooUtilityPackage' target 'FooUtilityTarget'.' against pattern equal("cyclic dependency declaration found: Root -> FooUtilityPackage -> BarPackage -> FooUtilityPackage")

@tomerd
Copy link
Contributor

tomerd commented Jan 9, 2021

@tomerd looks like one of the new tests is potentially flaky?

that would be very interesting! it would mean the resolution is not deterministic :|

@swift-ci please smoke test

@tomerd
Copy link
Contributor

tomerd commented Jan 9, 2021

@swift-ci please smoke test

@tomerd
Copy link
Contributor

tomerd commented Jan 9, 2021

@tomerd looks like one of the new tests is potentially flaky?

that would be very interesting! it would mean the resolution is not deterministic :|

@neonichu actually I think the change in this PR simply changes the resolution semantics leading to a different failure when names are not specified. this way it behaves in this PR is consistent with how it behaves in 5.3 so we may just need to amend the test

This is a follow-up to swiftlang#3162. While that brought back the code for `dependenciesRequired(for:)`, the guard based on `productFilter` actually made it so that it was practically never executed. Instead, the guard should be based on whether the package in question is a root package.

Additionally, this made the order of the returned dependencies unstable, due to use of `Set`. Since `dependenciesRequired(for: keepUnused:)` is now only used if `ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION` is set, I removed some dead code from there as well.
@neonichu neonichu force-pushed the semi-target-based-dependencies-2 branch from a01d30c to 9d0601a Compare January 11, 2021 19:50
@neonichu
Copy link
Contributor Author

@swift-ci please smoke test

@neonichu neonichu merged commit da4d643 into swiftlang:main Jan 11, 2021
@neonichu neonichu deleted the semi-target-based-dependencies-2 branch January 11, 2021 21:41
neonichu added a commit to neonichu/swift-package-manager that referenced this pull request Jan 11, 2021
…wiftlang#3166)

Actually skip not needed dependencies during dependency resolution

This is a follow-up to swiftlang#3162. While that brought back the code for `dependenciesRequired(for:)`, the guard based on `productFilter` actually made it so that it was practically never executed. Instead, the guard should be based on whether the package in question is a root package.

Additionally, this made the order of the returned dependencies unstable, due to use of `Set`. Since `dependenciesRequired(for: keepUnused:)` is now only used if `ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION` is set, I removed some dead code from there as well.

(cherry picked from commit da4d643)
neonichu added a commit that referenced this pull request Jan 14, 2021
…3166) (#3185)

Actually skip not needed dependencies during dependency resolution

This is a follow-up to #3162. While that brought back the code for `dependenciesRequired(for:)`, the guard based on `productFilter` actually made it so that it was practically never executed. Instead, the guard should be based on whether the package in question is a root package.

Additionally, this made the order of the returned dependencies unstable, due to use of `Set`. Since `dependenciesRequired(for: keepUnused:)` is now only used if `ENABLE_TARGET_BASED_DEPENDENCY_RESOLUTION` is set, I removed some dead code from there as well.

(cherry picked from commit da4d643)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants