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

With Swift 6, swift run --repl causes "redefinition of module" errors, depending on dependencies #7971

Open
1 task done
ORBAT opened this issue Sep 18, 2024 · 0 comments
Open
1 task done
Labels

Comments

@ORBAT
Copy link

ORBAT commented Sep 18, 2024

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

Depending on the packages in the dependencies array in Package.swift, running swift run --repl and typing anything in the REPL leads to an couldn't IRGen expression: Clang importer error and redefinition of module errors and I can't even tell whether anything is getting executed or not.

Not all packages cause this; so far I've had this problem with

  • .package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0")
  • .package(url: "https://github.com/pointfreeco/swift-parsing", branch: "main")
  • .package(url: "https://github.com/ordo-one/package-benchmark", from: "1.4.0")

But for example .package(url: "https://github.com/apple/swift-collections.git", from: "1.1.0") has not caused this.

I've tried

  • swift package reset && swift package purge-cache
  • rm -rf ~/Library/Caches/org.swift.swiftpm/
  • fd --hidden --no-ignore --ignore-case --glob "*modulecache*" /var/folders --exec rm -rf (to clear clang's module cache, based on an answer to this SO question)

Expected behavior

No errors.

Actual behavior

Example with only .package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0") as a dependency:

❯ swift run --repl 
Building for debugging...
[5/5] Linking libProblemLib.dylib
Build complete! (2.92s)
Launching Swift REPL with arguments: repl -I/Users/teklof/Documents/Programming/swift/problem-package/.build/arm64-apple-macosx/debug -L/Users/myusername/Documents/Programming/swift/problem-package/.build/arm64-apple-macosx/debug -lproblem-package__REPL
Welcome to Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2).
Type :help for assistance.
  1> let a = 1
a: Int = <extracting data from value failed>

couldn't IRGen expression: Clang importer error
error: /Users/myusername/Documents/Programming/swift/problem-package/.build/arm64-apple-macosx/debug/ArgumentParserToolInfo.build/module.modulemap:1:8: redefinition of module 'ArgumentParserToolInfo'
module ArgumentParserToolInfo {
       ^

error: /Users/myusername/Documents/Programming/swift/problem-package/.build/arm64-apple-macosx/debug/ArgumentParser.build/module.modulemap:1:8: redefinition of module 'ArgumentParser'
module ArgumentParser {
       ^

The exact module redefinition errors vary depending on which package(s) I've got in my dependencies.

Full swift run --repl -v outputs for the 3 problematic packages in an empty project like in the reproduction steps (includes one :swift-healthcheck output):

https://gist.github.com/ORBAT/f29e1b15da3be9aeca9371f34ffe1752

Steps to reproduce

  1. mkdir problem-package && cd problem-package
  2. swift package init --type=library --disable-xctest --disable-swift-testing
  3. run one of:
    1. swift package add-dependency https://github.com/apple/swift-argument-parser --from 1.3.0
    2. swift package add-dependency https://github.com/pointfreeco/swift-parsing --branch main
    3. swift package add-dependency https://github.com/ordo-one/package-benchmark --from 1.4.0
  4. swift run --repl
  5. let a = 1

Swift Package Manager version/commit hash

Swift Package Manager - Swift 6.0.0-dev

Swift & OS version (output of swift --version ; uname -a)

Using the Swift toolchain from Xcode 16.0 (16A242d)

❯ swift --version ; uname -a

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0
Darwin Myhostname.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:46 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6031 arm64
@ORBAT ORBAT added the bug label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant