apple / swift-collections

Commonly used data structures for Swift
Apache License 2.0
3.55k stars 270 forks source link

Version 1.1.0 fails to compile #359

Closed jbelkins closed 2 months ago

jbelkins commented 3 months ago

When building swift-collections on macOS 12 / Xcode 14.0.1 / destination 'platform=OS X', the package fails to compile. The same macOS version and Xcode version compile successfully for the iOS & tvOS platforms, as well as for every other combination of host OS / Xcode version / target OS I have tried.

Relevant logs from the compile failure:

❌  /Users/runner/Library/Developer/Xcode/DerivedData/smithy-swift-eqehdcxsyalqqmgtkhjdigcyxfcr/SourcePackages/checkouts/swift-collections/Sources/RopeModule/Rope/Basics/Rope+Builder.swift:18:29: cannot specialize protocol type 'Sequence'

  public init(_ items: some Sequence<Element>) {
                            ^

❌  /Users/runner/Library/Developer/Xcode/DerivedData/smithy-swift-eqehdcxsyalqqmgtkhjdigcyxfcr/SourcePackages/checkouts/swift-collections/Sources/RopeModule/Rope/Basics/Rope+Builder.swift:230:64: cannot specialize protocol type 'Sequence'

    public mutating func insertBeforeTip(_ items: __owned some Sequence<Element>) {
                                                               ^

❌  /Users/runner/Library/Developer/Xcode/DerivedData/smithy-swift-eqehdcxsyalqqmgtkhjdigcyxfcr/SourcePackages/checkouts/swift-collections/Sources/RopeModule/Rope/Basics/Rope+Builder.swift:24:17: for-in loop requires 'some Sequence<Element>' to conform to 'Sequence'

    for item in items {
                ^~~~~

❌  /Users/runner/Library/Developer/Xcode/DerivedData/smithy-swift-eqehdcxsyalqqmgtkhjdigcyxfcr/SourcePackages/checkouts/swift-collections/Sources/RopeModule/Rope/Basics/Rope+Builder.swift:234:21: for-in loop requires 'some Sequence<Element>' to conform to 'Sequence'

        for item in items {
                    ^~~~~

❌  /Users/runner/Library/Developer/Xcode/DerivedData/smithy-swift-eqehdcxsyalqqmgtkhjdigcyxfcr/SourcePackages/checkouts/swift-collections/Sources/RopeModule/Rope/Operations/Rope+RemoveSubrange.swift:[32](https://github.com/smithy-lang/smithy-swift/actions/runs/7832430857/job/21371108130?pr=660#step:11:33):[36](https://github.com/smithy-lang/smithy-swift/actions/runs/7832430857/job/21371108130?pr=660#step:11:37): cannot specialize protocol type 'Sequence'

    with newElements: __owned some Sequence<Element>
                                   ^

A link to an example failed compile on Github CI: https://github.com/smithy-lang/smithy-swift/actions/runs/7832430857/job/21371108130?pr=660

Information

Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50) Target: x86_64-apple-macosx12.0



### Checklist

- [x] If possible, I've reproduced the issue using the `main` branch of this package.
- [x] I've searched for [existing GitHub issues](https://github.com/apple/swift-collections/issues).

### Steps to Reproduce
Compile swift-collections on the macOS, Xcode, and destination described above.

### Expected behavior
Compile should succeed.

### Actual behavior
Compile fails with the error messages above.
vanvoorden commented 3 months ago
Xcode 14.0.1
Build version 14A400

Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
Target: x86_64-apple-macosx12.0

https://github.com/apple/swift-collections?tab=readme-ov-file#project-status

It looks like the swift-collections 1.1.x package requires Swift 5.7.2 and Xcode 14.2.

jbelkins commented 3 months ago

It looks like the swift-collections 1.1.x package requires Swift 5.7.2 and Xcode 14.2.

Surprising that a breaking change like dropping toolchain version(s) would be made in a minor version bump. In any case, if this was intentional and my use of an unsupported Swift version was the cause of the failure, the maintainers may close this issue.

lorentey commented 3 months ago

Testing every minor release ever shipped for a major Swift release (such as 5.7) would be prohibitively expensive, so we only ran prerelease tests on the latest point releases (in this case, 5.7.2 on Apple platforms and 5.7.3 on Linux). Point releases contain critical bug fixes, so my general expectation is that upgrading to them would be much easier (i.e., a much easier sell) than upgrading to a new major Swift release.

However, I did not expect that primary associated types only became usable in 5.7.1+ -- that is an unpleasant surprise. This is quite a pickle, especially as the SwiftPM manifest header does not allow packages to require specific point releases.

I'm tempted to ask you to upgrade to 5.7.2 if possible. If this problem turns out to affect many clients, then plan B would be to immediately bump the requirement to 5.8 in a new tag and to roll back the 1.1.0 tag.

(We could technically also roll back the introduction of the some Sequence<Foo> syntax, but it's not a trivial change, and given the option, I overwhelmingly prefer to move forward, not back.)

vanvoorden commented 3 months ago

the SwiftPM manifest header does not allow packages to require specific point releases

https://developer.apple.com/documentation/PackageDescription/Package#overview

@lorentey Hmm… this documentation has an example of requiring a point release (swift-tools-version:3.0.2)… is that not going to help us here?

lorentey commented 3 months ago

Unfortunately, that doesn't seem to work. 😞

vanvoorden commented 3 months ago

https://github.com/apple/swift-package-manager/blob/main/Sources/Commands/PackageTools/ToolsVersionCommand.swift#L72-L80

https://github.com/apple/swift-package-manager/blob/main/Sources/PackageModel/ToolsVersion.swift#L78-L81

https://github.com/apple/swift-package-manager/blob/main/Sources/Workspace/InitPackage.swift#L422-L425

https://github.com/apple/swift-package-manager/blob/main/Tests/WorkspaceTests/ToolsVersionSpecificationRewriterTests.swift#L167-L171

@lorentey Hmm… are we running into one of these code paths that is zeroing the patch version?

lorentey commented 3 months ago

Perhaps! The quick smoke test I ran was this:

$ head -1 Package.swift
// swift-tools-version:5.9.2
$ xcrun swift --version
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
$ xcrun swift build
error: 'swift-collections': package 'swift-collections' is using Swift tools version 5.9.2 but the installed version is 5.9.0
error: ExitCode(rawValue: 1)
[0/1] Planning build
error: 'swift-collections': package 'swift-collections' is using Swift tools version 5.9.2 but the installed version is 5.9.0

Looking closer, this may be because what SwiftPM believes to be its version number does not match the toolchain's version:

$ xcrun swift package --version
Swift Package Manager - Swift 5.9.0

In Swift 5.7.2, SwiftPM reports itself as "5.7.1" (🤨), so perhaps setting the package manifest to that would have been a workable option. (The 1.1.0 tag is out, so if we want this adjusted, then that would need to be done in a new tag, with 1.1.0 removed altogether. At this moment, I don't know if doing that would be worth the disruption of a disappearing tag.)

repoluhun commented 2 months ago

I'm facing this same issue on monterey, have you figured out any solution yet?

lorentey commented 2 months ago

The solution is to upgrade to Xcode 14.2 with Swift 5.7.2. Do you have a reason for not doing that?

repoluhun commented 2 months ago

My MacBook doesn’t support any higher Xcode versions On 2024. Feb 19., Mon at 2:00, Karoy Lorentey @.***> wrote:

The solution is to upgrade to Xcode 14.2 with Swift 5.7.2. Do you have a reason for not doing that?

— Reply to this email directly, view it on GitHub https://github.com/apple/swift-collections/issues/359#issuecomment-1951523877, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMP2BFXAEKNYWD6IRA3WSY3YUKP25AVCNFSM6AAAAABDACUY2WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJRGUZDGOBXG4 . You are receiving this because you commented.Message ID: @.***>

lorentey commented 2 months ago

Xcode 14.2 requires macOS 12.5, just like Xcode 14.0.