Skip to content

Can't build swift-format@main because it keeps picking up swift-syntax at af18ea40 #604

Closed
@natikgadzhi

Description

@natikgadzhi

It's very likely a user problem, and I'll verify and try building on a different machine from scratch. If it works, I'll close the issue. If not, let that be my investigation log.

So, I was learning swift-syntax and working on swiftlang/swift-syntax#2112, and I think @ahoppen mentioned that we're using swift-format@main, so I thought I would build myself a nice new swift-format. I've already had a repository locally.

I tried building with Xcode and swift build and swift build -c release, and I get compilation errors:

swift-format main
 ❯ swift package reset
sw⏎

swift-format main
 ❯ swift package clean
sw⏎

swift-format main
 ❯ swift package purge-cache

swift-format main
 ❯ rm -rf .build

swift-format main
 ❯ swift build
Fetching https://github.com/apple/swift-syntax.git
Fetched https://github.com/apple/swift-syntax.git (4.39s)
Fetching https://github.com/apple/swift-markdown.git
Fetching https://github.com/apple/swift-cmark.git
Fetching https://github.com/apple/swift-argument-parser.git
Fetched https://github.com/apple/swift-cmark.git (2.34s)
Fetched https://github.com/apple/swift-markdown.git (2.34s)
Fetched https://github.com/apple/swift-argument-parser.git (2.34s)
Computing version for https://github.com/apple/swift-markdown.git
Computed https://github.com/apple/swift-markdown.git at 0.2.0 (0.43s)
Computing version for https://github.com/apple/swift-argument-parser.git
Computed https://github.com/apple/swift-argument-parser.git at 1.2.2 (0.41s)
Computing version for https://github.com/apple/swift-cmark.git
Computed https://github.com/apple/swift-cmark.git at 0.2.0 (0.42s)
Creating working copy for https://github.com/apple/swift-cmark.git
Working copy of https://github.com/apple/swift-cmark.git resolved at 0.2.0
Creating working copy for https://github.com/apple/swift-markdown.git
Working copy of https://github.com/apple/swift-markdown.git resolved at 0.2.0
Creating working copy for https://github.com/apple/swift-argument-parser.git
Working copy of https://github.com/apple/swift-argument-parser.git resolved at 1.2.2
Creating working copy for https://github.com/apple/swift-syntax.git
Working copy of https://github.com/apple/swift-syntax.git resolved at main
Building for debugging...
/Users/nategadzhi/src/apple/swift-format/Sources/SwiftFormat/Rules/OrderedImports.swift:517:30: error: value of optional type 'AttributeListSyntax?' must be unwrapped to refer to member 'firstToken' of wrapped base type 'AttributeListSyntax'
    if let attr = importDecl.attributes.firstToken(viewMode: .sourceAccurate),
                             ^
/Users/nategadzhi/src/apple/swift-format/Sources/SwiftFormat/Rules/OrderedImports.swift:517:30: note: chain the optional using '?' to access member 'firstToken' only for non-'nil' base values
    if let attr = importDecl.attributes.firstToken(viewMode: .sourceAccurate),
                             ^
                                       ?
/Users/nategadzhi/src/apple/swift-format/Sources/SwiftFormat/Rules/OrderedImports.swift:517:30: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
    if let attr = importDecl.attributes.firstToken(viewMode: .sourceAccurate),
                             ^
                                       !
/Users/nategadzhi/src/apple/swift-format/Sources/SwiftFormat/Rules/OrderedImports.swift:519:33: error: cannot infer contextual base in reference to member 'sourceAccurate'
      attr.nextToken(viewMode: .sourceAccurate)?.text == "testable"
                               ~^~~~~~~~~~~~~~
/Users/nategadzhi/src/apple/swift-format/Sources/SwiftFormat/Rules/OrderedImports.swift:517:30: error: value of optional type 'AttributeListSyntax?' must be unwrapped to refer to member 'firstToken' of wrapped base type 'AttributeListSyntax'
    if let attr = importDecl.attributes.firstToken(viewMode: .sourceAccurate),
                             ^
/Users/nategadzhi/src/apple/swift-format/Sources/SwiftFormat/Rules/OrderedImports.swift:517:30: note: chain the optional using '?' to access member 'firstToken' only for non-'nil' base values
    if let attr = importDecl.attributes.firstToken(viewMode: .sourceAccurate),

And so on.

I'm running XCode 15 beta 7:

swift-syntax
 ❯ swift --version
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.106 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0

When I try to build swift-format and check what the problem is, I found that for some reason, swift package manager and Xcode resolve swift-syntax@main to this commit from August 4th. Seems like since then, swift-format changes require a fresh version of swift-syntax, and for some reason, SwiftPM does not resolve to it.

swift-format main
 ❯ cd .build/checkouts/swift-syntax

swift-syntax
 ❯ git show
commit af18ea40a3552b72f57094809efe4be53df2df3a (HEAD)
Merge: 5a914f9c 925a0c04
Author: Kim de Vos <kimdevos12@hotmail.com>
Date:   Fri Aug 4 23:18:52 2023 +0200

    Merge pull request #1999 from kimdv/kimdv/fix-deprecation-warning

    Fix deprecation warning


swift-syntax
 ❯

One of the compilation errors in FullyIndirectEnum:27 is Value of optional type 'DeclModifierListSyntax?' must be unwrapped to refer to member 'has' of wrapped base type 'DeclModifierListSyntax', which is totally fair — because in that August 4th commit, members returns an optional. But on actual main it does return DeclModifierListSyntax.

It feels like it's a Swift Package Manager package resolution problem, and not specifically a SwiftFormat problem.

  • I have not tried to build on Xcode 14 / Swift 5.8. I can do that if you'd like me to investigate.
  • Have I tried resetting swift package manager's package cache? yep. swift package reset && swift package clean && swift package purge-cache && rm -rf .build for good measure. It looks like it fetches swift-syntax from GitHub, not from local cache.
  • Have I tried making a clean build in Xcode and resetting package cache and resolving package deps? Yes, I have. No luck.

The next thing that comes to mind is to try and set the swift-syntax dependency to my fork @ main, or make a tag and check if versioned resolution will work. I am pretty sure that would work.

It's likely that I'm missing something obvious, though. What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions