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

Adopt Swift Collections' OrderedSet and OrderedDictionary #3533

Conversation

WowbaggersLiquidLunch
Copy link
Contributor

@WowbaggersLiquidLunch WowbaggersLiquidLunch commented Jun 7, 2021

They're better optimised and tested than TSCBasic's.

This PR needs to be tested together with swiftlang/swift-tools-support-core#222 and swiftlang/swift#37431.

@compnerd
Copy link
Member

compnerd commented Jun 7, 2021

This needs updating in the CMake build before it can be merged. The nightlies build needs to be updated for this as well.

@WowbaggersLiquidLunch
Copy link
Contributor Author

This needs updating in the CMake build before it can be merged. The nightlies build needs to be updated for this as well.

Sorry I don't really understand what this means. Is there something I should do in order for the CMake and nightly builds to be updated?

@finagolfin
Copy link
Contributor

I don't know what nightlies refers to, but the CMake build is used to bootstrap SPM on the CI. Take a look at when swift-crypto was added, #3202, for an example of the kinds of changes that are needed to add a Swift package dependency.

@WowbaggersLiquidLunch WowbaggersLiquidLunch marked this pull request as draft June 7, 2021 16:54
@WowbaggersLiquidLunch
Copy link
Contributor Author

WowbaggersLiquidLunch commented Jun 7, 2021

Converted to draft while I work on CMakeLists and the bootstrap script.

Package.swift Outdated Show resolved Hide resolved
@WowbaggersLiquidLunch WowbaggersLiquidLunch force-pushed the adopt-swift-collections branch 2 times, most recently from a48848b to 374bf40 Compare June 9, 2021 17:23
@WowbaggersLiquidLunch WowbaggersLiquidLunch marked this pull request as ready for review June 9, 2021 17:47
@WowbaggersLiquidLunch
Copy link
Contributor Author

WowbaggersLiquidLunch commented Jun 9, 2021

I finished adding swift-collections to CMakeLists and bootstrap, but wasn't able to test them locally.

Also, this PR is still blocked by swiftlang/swift-tools-support-core#222, because I haven't figured out how to add swift-collections to its CMake build.

Package.swift Outdated Show resolved Hide resolved
build_with_cmake(args, cmake_flags, args.swift_crypto_source_dir, args.swift_crypto_build_dir)
build_with_cmake(args, cmake_flags, args.tsc_source_dir, args.tsc_build_dir)

def build_yams(args):
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a lot of duplication here — I realize that there was already some, but this is adding another case of it. Would it make sense to consolidate some of this into a function? I did that with the code to install a dylib and its associated module, and it might make sense to follow that model and pass parameters as needed. The output directory could potentially be a return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. It makes sense to consolidate them into a function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened #3582 to consolidate the functions, instead of doing it in this PR, in order to avoid merge conflicts before this PR is ready.

@WowbaggersLiquidLunch
Copy link
Contributor Author

WowbaggersLiquidLunch commented Jun 14, 2021

I converted this PR into a draft again earlier today, because I found a problem where PubgrubTests passes to DependencyGraphBuilder.serve an ordered dictionary with duplicate keys, which Swift Collection's OrderedDictionary traps.

@tomerd tomerd self-assigned this Jun 14, 2021
@tomerd tomerd added the WIP Work in progress label Jun 15, 2021
@WowbaggersLiquidLunch WowbaggersLiquidLunch changed the title Adopt Swift Collection's OrderedSet and OrderedDictionary Adopt Swift Collections' OrderedSet and OrderedDictionary Jun 19, 2021
@WowbaggersLiquidLunch
Copy link
Contributor Author

The problem of duplicate keys isn't really related to Swift Collections' OrderedDictionary, so I opened a separate PR #3564 for it.

Also updated version numbers used for swift-argument-parser and swift-crypto in the documentation.
WowbaggersLiquidLunch added a commit to WowbaggersLiquidLunch/swift-package-manager that referenced this pull request 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.
tomerd pushed a commit that referenced this pull request Jun 22, 2021
…er.serve` (#3564)

* [PubgrubTests] Replace `OrderedDictionary` with `KeyValuePairs` in `DependencyGraphBuilder.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 #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.

* [PubgrubTests] append, not assign, `packageDependencies` to value in 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.
@finagolfin
Copy link
Contributor

This will need to be rebased, as I just made some changes to the same portion of the bootstrap script.

@WowbaggersLiquidLunch
Copy link
Contributor Author

WowbaggersLiquidLunch commented Jul 1, 2021

This will need to be rebased, as I just made some changes to the same portion of the bootstrap script.

Thanks for the notice. I'm actually going to open a new PR (update: #3582) first that consolidate all the build_ functions as @abertelrud suggested.

@WowbaggersLiquidLunch
Copy link
Contributor Author

Closing this in favour of #3590

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants