Skip to content
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

[PubgrubTests] Handle duplicate product keys in DependencyGraphBuilder.serve #3564

Conversation

WowbaggersLiquidLunch
Copy link
Contributor

@WowbaggersLiquidLunch WowbaggersLiquidLunch commented Jun 19, 2021

This PR fixes 2 places where DependencyGraphBuilder.serve mishandles dependencies with duplicate keys (products).

  1. One of the callers of the function passes in a dictionary literal with duplicate keys. Although the logic in this function suggests that duplicate keys are allowed, TSCBasic.OrderedDictionary preserves only the final of all duplicate keys' values in a dictionary literal. In addition, with Adopt Swift Collections' OrderedSet and OrderedDictionary #3533, Swift Collections' OrderedDictionary traps on duplicate keys. KeyValuePairs seems like the right replacement that allows duplicate keys.

  2. Because of the duplicate keys, when dependencies are iterated, the same product can appear more than once, each time with possibly different filteredDependencies. In each iteration, the filteredDependencies associated with the product is mapped to packageDependencies, which is then assigned to the value in a different dictionary keyed by the same product, overriding any existing value from a possible previous assignment. Changing the assignment to an appending operation preserves all previous values.

@tomerd
Copy link
Contributor

tomerd commented Jun 21, 2021

@swift-ci please smoke test

@tomerd tomerd self-assigned this Jun 21, 2021
…ependencyGraphBuilder.serve`

[One of the callers](https://github.com/apple/swift-package-manager/blob/20eba126ffa32088abb46d642bd0481dbae212ef/Tests/PackageGraphTests/PubgrubTests.swift#L472-L475) of the function passes in a dictionary literal with duplicate keys. Although the logic in this function suggests that duplicate keys are allowed, `TSCBasic.OrderedDictionary` preserves only [the final](https://github.com/apple/swift-tools-support-core/blob/21a79185b2ea8f89b9253ed8cdf2338bf564c499/Sources/TSCBasic/OrderedDictionary.swift#L97-L99) of all duplicate keys' values in a dictionary literal. In addition, with swiftlang#3533, Swift Collections' `OrderedDictionary` [traps](https://github.com/apple/swift-collections/blob/c0549b6284aadd5fd13156316f43fcb43c7fca77/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary%2BInitializers.swift#L88-L91) on duplicate keys. `KeyValuePairs` seems like the right replacement that allows duplicate keys.
@WowbaggersLiquidLunch WowbaggersLiquidLunch force-pushed the use-KeyValuePairs-for-duplicate-keys branch from cc736a7 to 4802fc4 Compare June 21, 2021 23:44
@WowbaggersLiquidLunch WowbaggersLiquidLunch changed the title [PubgrubTests] Replace OrderedDictionary with KeyValuePairs in DependencyGraphBuilder.serve [PubgrubTests] Handle duplicate product keys in DependencyGraphBuilder.serve Jun 21, 2021
…dictionary keyed by `product`

`dependencies` passed to `DependencyGraphBuilder.serve` can have duplicate product keys, so when `dependencies` are iterated, the same `product` can appear more than once, each time with possibly different `filteredDependencies`. Assigning `packageDependencies` mapped from a `product`'s `filteredDependencies` to the value in a different dictionary keyed by the same `product` overrides any existing value from a previous assignment. Appending `packageDependencies` instead preserves all previous values.
@WowbaggersLiquidLunch WowbaggersLiquidLunch force-pushed the use-KeyValuePairs-for-duplicate-keys branch from 4802fc4 to dfd4217 Compare June 21, 2021 23:58
@tomerd
Copy link
Contributor

tomerd commented Jun 22, 2021

@swift-ci please smoke test

@tomerd tomerd merged commit 065536e into swiftlang:main Jun 22, 2021
@tomerd
Copy link
Contributor

tomerd commented Jun 22, 2021

thanks @WowbaggersLiquidLunch

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.

2 participants