swiftlang / swift

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

[SR-4959] UnresolvedDot in wrong phase #47536

Open dabrahams opened 7 years ago

dabrahams commented 7 years ago
Previous ID SR-4959
Radar rdar://problem/32315362
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 1 | |Component/s | Compiler | |Labels | Bug, CompilerCrash, TypeChecker | |Assignee | @DougGregor | |Priority | Medium | md5: b40669f3339f6c172e75017672b4032e

Issue Description:

$ git fetch https://github.com/dabrahams/swift refs/bugs/silgen-crash-index-interchange:BUG && git checkout BUG

--skip-build-ios-device --skip-build-tvos-device --skip-build-compiler-rt --debug-swift-stdlib --skip-build-benchmarks --release --swift-stdlib-assertions --swift-stdlib-build-type=Debug

cd /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/stdlib/public/core && /usr/bin/python /Users/dave/src/s/swift/utils/line-directive @/Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/stdlib/public/core/URwCj.txt -- /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./bin/swiftc -c -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -target x86_64-apple-macosx10.9 -resource-dir /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks -Onone -g -D INTERNAL_CHECKS_ENABLED -I /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift/macosx/x86_64 -module-cache-path /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./module-cache -no-link-objc-runtime -Xfrontend -enable-cow-existentials -nostdimport -parse-stdlib -module-name Swift -Xfrontend -group-info-path -Xfrontend /Users/dave/src/s/swift/stdlib/public/core/GroupInfo.json -Xfrontend -sil-serialize-all -swift-version 3 -warn-swift3-objc-inference-complete -Xllvm -sil-inline-generics -Xllvm -sil-partial-specialization -module-link-name swiftCore -force-single-frontend-invocation -Xcc -D__SWIFT_CURRENT_DYLIB=swiftCore -parse-as-library -o /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/stdlib/public/core/macosx/x86_64/Swift.o @/Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/stdlib/public/core/URwCj.txt
Assertion failed: ((HadError || !M.is<SourceFile*>() || M.get<SourceFile*>()->ASTStage < SourceFile::TypeChecked) && "UnresolvedDot" "in wrong phase"), function walkToExprPre, file /Users/dave/src/s/swift/include/swift/AST/ExprNodes.def, line 87.
0  swift                    0x0000000110fff748 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000110fffdf6 SignalHandler(int) + 454
2  libsystem_platform.dylib 0x00007fffc210ab3a _sigtramp + 26
3  libsystem_platform.dylib 0x0000145b021b11c8 _sigtramp + 1074423464
4  libsystem_c.dylib        0x00007fffc1f8f420 abort + 129
5  libsystem_c.dylib        0x00007fffc1f56893 basename_r + 0
6  swift                    0x000000010ebc89dc (anonymous namespace)::Verifier::walkToExprPre(swift::Expr*) + 140
7  swift                    0x000000010ebdd8a4 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 36
8  swift                    0x000000010ebdc110 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 9472
9  swift                    0x000000010ebdd953 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 211
10 swift                    0x000000010ebddf61 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 961
11 swift                    0x000000010ebddd5d swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 445
12 swift                    0x000000010ebe0280 (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 704
13 swift                    0x000000010ebd94d7 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 327
14 swift                    0x000000010ebd966a (anonymous namespace)::Traversal::doIt(swift::Decl*) + 730
15 swift                    0x000000010ebd937b swift::Decl::walk(swift::ASTWalker&) + 27
16 swift                    0x000000010ec63efa swift::SourceFile::walk(swift::ASTWalker&) + 170
17 swift                    0x000000010ebc839b swift::verify(swift::SourceFile&) + 59
18 swift                    0x000000010eb4ba2f swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 2079
19 swift                    0x000000010e69c399 swift::CompilerInstance::performSema() + 3881
20 swift                    0x000000010dc01f8b performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 2427
21 swift                    0x000000010dc0053a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2650
22 swift                    0x000000010dbbcae0 main + 3312
23 libdyld.dylib            0x00007fffc1efb235 start + 1
24 libdyld.dylib            0x000000000000002c start + 1041255928
Stack dump:
0.  Program arguments: /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/bin/swift -frontend -c -filelist /var/folders/8v/9769m3ps7ds7h9pg23lzcls00000gn/T/sources-f4e0ce -disable-objc-attr-requires-foundation-module -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift/macosx/x86_64 -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks -g -module-cache-path /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./module-cache -module-link-name swiftCore -nostdimport -parse-stdlib -resource-dir /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift -swift-version 3 -D INTERNAL_CHECKS_ENABLED -enable-cow-existentials -group-info-path /Users/dave/src/s/swift/stdlib/public/core/GroupInfo.json -sil-serialize-all -Xllvm -sil-inline-generics -Xllvm -sil-partial-specialization -Xcc -D__SWIFT_CURRENT_DYLIB=swiftCore -Onone -parse-as-library -module-name Swift -o /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/stdlib/public/core/macosx/x86_64/Swift.o 
1.  While walking into decl extension of Character.UnicodeScalarView at /Users/dave/src/s/swift/stdlib/public/core/CharacterUnicodeScalars.swift:64:1
2.  While walking into body of 'index' at /Users/dave/src/s/swift/stdlib/public/core/CharacterUnicodeScalars.swift:71:10
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

Other hashes

clang                              b6369bdc96 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                        cbf6089b1 Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
llbuild                            79f182e Extract the `isLocatedUnderRootPath` check (#169)
lldb                               4cd935b4a Don't override the SDKs and force the use of /System/Library/Frameworks to find the python headers when buiding crashinfo.c <rdar://problem/32288076>
llvm                               f61cc3ca1f3 Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
ninja                              (not checked out)
swift                              8a8e9128e7b [stdlib] String index interchange, part III (UTF8)
swift-corelibs-foundation          2e50a38 Add tests for Scanner.atEnd. (#992)
swift-corelibs-libdispatch         0b6c22e Merge pull request #&#8203;249 from dgrove-oss/update-docs
swift-corelibs-xctest              2e0aedc Merge pull request #&#8203;189 from tkremenek/force-tests-swift-ver-3
swift-integration-tests            641971a Merge pull request #&#8203;21 from apple/revert-20-revert-19-revert-6a20dc2
swift-xcode-playground-support     05737c4 Merge pull request #&#8203;14 from tkremenek/update-swift-4
swiftpm                            b589f985 Merge pull request #&#8203;1193 from aciidb0mb3r/enable-prefetching
dabrahams commented 7 years ago

@swift-ci create

dabrahams commented 7 years ago

So this was triggered by commenting out the IndexDistance associated type in Collection, which is duplicated or shadowed by another declaration in _Indexable. If you uncomment it, you get this error which makes it look like the compiler thinks IndexDistance can be two different types:

cd /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/stdlib/public/core && /Users/dave/brew/Cellar/cmake/3.8.0/bin/cmake -E remove -f /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift/macosx/x86_64/Swift.swiftmodule && /Users/dave/brew/Cellar/cmake/3.8.0/bin/cmake -E remove -f /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift/macosx/x86_64/Swift.swiftdoc && /usr/bin/python /Users/dave/src/s/swift/utils/line-directive @/Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/stdlib/public/core/URwCj.txt -- /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./bin/swiftc -emit-module -o /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift/macosx/x86_64/Swift.swiftmodule -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -target x86_64-apple-macosx10.9 -resource-dir /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/../../../Developer/Library/Frameworks -Onone -g -D INTERNAL_CHECKS_ENABLED -I /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./lib/swift/macosx/x86_64 -module-cache-path /Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/./module-cache -no-link-objc-runtime -Xfrontend -enable-cow-existentials -nostdimport -parse-stdlib -module-name Swift -Xfrontend -group-info-path -Xfrontend /Users/dave/src/s/swift/stdlib/public/core/GroupInfo.json -Xfrontend -sil-serialize-all -swift-version 3 -warn-swift3-objc-inference-complete -Xllvm -sil-inline-generics -Xllvm -sil-partial-specialization -module-link-name swiftCore -force-single-frontend-invocation -Xcc -D__SWIFT_CURRENT_DYLIB=swiftCore -parse-as-library @/Users/dave/src/s/build/Ninja-ReleaseAssert+stdlib-DebugAssert/swift-macosx-x86_64/stdlib/public/core/URwCj.txt
/Users/dave/src/s/swift/stdlib/public/core/StringUnicodeScalarView.swift:528:38: error: 'IndexDistance' is ambiguous for type lookup in this context
    from i: Index?, to j: Index?) -> IndexDistance {
                                     ^~~~~~~~~~~~~
/Users/dave/src/s/swift/stdlib/public/core/Collection.swift:182:18: note: found this candidate
  associatedtype IndexDistance : SignedInteger = Int
                 ^
/Users/dave/src/s/swift/stdlib/public/core/Collection.swift:646:18: note: found this candidate
  associatedtype IndexDistance = Int
                 ^
/Users/dave/src/s/swift/stdlib/public/core/StringUnicodeScalarView.swift:523:46: error: 'IndexDistance' is ambiguous for type lookup in this context
  public func index(_ i: Index?, offsetBy n: IndexDistance) -> Index {
                                             ^~~~~~~~~~~~~
/Users/dave/src/s/swift/stdlib/public/core/Collection.swift:182:18: note: found this candidate
  associatedtype IndexDistance : SignedInteger = Int
                 ^
/Users/dave/src/s/swift/stdlib/public/core/Collection.swift:646:18: note: found this candidate
  associatedtype IndexDistance = Int
                 ^

Which don't seem right neither.