swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.59k stars 10.36k forks source link

[SR-4277] fascinating link error #46860

Open dabrahams opened 7 years ago

dabrahams commented 7 years ago
Previous ID SR-4277
Radar None
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 111d82246fad6b4743a2b0ee3dde9b80

Issue Description:

$ git fetch https://github.com/dabrahams/swift refs/bugs/SR-fascinating-link-error:BUG && git checkout BUG

Build the compiler and run the Prototypes/AnyUnicode.swift test. I get:

rm -rf /Users/Shared/dabrahams/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/Prototypes/Output/AnyUnicode.swift.tmp && mkdir -p /Users/Shared/dabrahams/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/Prototypes/Output/AnyUnicode.swift.tmp && xcrun --toolchain default --sdk /Applications/Xcode-8W109m.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk /Users/Shared/dabrahams/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./bin/swiftc -target x86_64-apple-macosx10.9  -module-cache-path '/var/folders/8v/9769m3ps7ds7h9pg23lzcls00000gn/T/swift-testsuite-clang-module-cacheilhhDS' -F /Applications/Xcode-8W109m.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks -Xlinker -rpath -Xlinker /Applications/Xcode-8W109m.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks  -swift-version 3  -module-cache-path '/var/folders/8v/9769m3ps7ds7h9pg23lzcls00000gn/T/swift-testsuite-clang-module-cacheilhhDS' /Users/Shared/dabrahams/s/swift/test/Prototypes/AnyUnicode.swift -o /Users/Shared/dabrahams/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/Prototypes/Output/AnyUnicode.swift.tmp/a.out -module-name main &&  /Users/Shared/dabrahams/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/Prototypes/Output/AnyUnicode.swift.tmp/a.out
/Users/Shared/dabrahams/s/swift/test/Prototypes/AnyUnicode.swift:877:7: warning: variable 's16' was never mutated; consider changing to 'let' constant
  var s16 = AnyStringContents(_UTF16StringStorage(sample.utf16))
  ~~~ ^
  let
/Users/Shared/dabrahams/s/swift/test/Prototypes/AnyUnicode.swift:880:7: warning: initialization of immutable value 's16r16' was never used; consider replacing with assignment to '_' or removing it
  let s16r16 = Array(s16.rawUTF16)
  ~~~~^~~~~~
  _
Undefined symbols for architecture x86_64:
  "__TWPVSS9UTF16Views22RandomAccessCollection10Foundation", referenced from:
      __TF4mainU0_FT_T_ in AnyUnicode-7a169e.o
      __TMaGVs26LazyRandomAccessCollectionVSS9UTF16View_ in AnyUnicode-7a169e.o
      __TMaGVs29LazyMapRandomAccessCollectionVSS9UTF16ViewVs6UInt32_ in AnyUnicode-7a169e.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

Why it should be complaining about something in Foundation… well, it probably has to do with the fact that String's UTF16View only conforms to RandomAccessCollection if you import Foundation. But the compiler shouldn't have knowledge of that conformance without Foundation imported, right?!

Other hashes

clang                              61c6b90825 Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
cmark                              d875488 Merge pull request #&#8203;4 from llvm-beanz/generate-cmark-exports
compiler-rt                        2a37e0f29 Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
llbuild                            360bcdd [devel] Add a Vagrantfile.
lldb                               9ca9758f9 Merge pull request #&#8203;149 from bitjammer/swift-typealias-equal-sourceloc
llvm                               7c5d644f877 Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
Traceback (most recent call last):
...
dabrahams commented 7 years ago

Here is a much simpler reproducer that almost certainly also reproduces with a standard build:

import StdlibUnittest
func f() {
  _ = "foo".utf16.lazy.map { $0 }
}

Probably StdlibUnittest imports Foundation, and that's what causes the problem. @belkadan Doesn't this reveal a fundamental issue with our model for conformance visibility?

belkadan commented 7 years ago

We've had this bug/feature for a long time, and the current intent is that we'd link against Foundation. I thought we fixed that a long time ago.