swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.75k stars 1.35k forks source link

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

Open ORBAT opened 2 months ago

ORBAT commented 2 months ago

Is it reproducible with SwiftPM command-line tools: 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

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

I've tried

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