swiftlang / swift

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

[SR-3240] Compiler crash when building PerfectTemplate #45828

Open aciidgh opened 7 years ago

aciidgh commented 7 years ago
Previous ID SR-3240
Radar None
Original Reporter @aciidb0mb3r
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash, TypeChecker | |Assignee | None | |Priority | Medium | md5: c58c8e0d14408796846fbe80b3fba3e1

Issue Description:

$ xcrun --find swift
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-11-15-a.xctoolchain/usr/bin/swift
$ git clone https://github.com/PerfectlySoft/PerfectTemplate
$ swift build

➜  PerfectTemplate git:(master) swift build
Compile Swift Module 'PerfectHTTPServer' (5 sources)
Assertion failed: (!outerOrigType.isTuple()), function planTupleIntoDirectResult, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SILGen/SILGenPoly.cpp, line 1849.
0  swift                    0x000000010f1a9ec6 llvm::sys::RunSignalHandlers() + 86
1  swift                    0x000000010f1ab579 SignalHandler(int) + 361
2  libsystem_platform.dylib 0x00007fff97b30bba _sigtramp + 26
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-11-15-a.xctoolchain/usr/bin/swift -frontend -c /private/tmp/tests/PerfectTemplate/Packages/PerfectHTTPServer-2.0.4/Sources/PerfectHTTPServer/HPACK.swift -primary-file /private/tmp/tests/PerfectTemplate/Packages/PerfectHTTPServer-2.0.4/Sources/PerfectHTTPServer/HTTP11Request.swift /private/tmp/tests/PerfectTemplate/Packages/PerfectHTTPServer-2.0.4/Sources/PerfectHTTPServer/HTTP11Response.swift /private/tmp/tests/PerfectTemplate/Packages/PerfectHTTPServer-2.0.4/Sources/PerfectHTTPServer/HTTP2.swift /private/tmp/tests/PerfectTemplate/Packages/PerfectHTTPServer-2.0.4/Sources/PerfectHTTPServer/HTTPServer.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /private/tmp/tests/PerfectTemplate/.build/debug -I /private/tmp/tests/PerfectTemplate/Packages/COpenSSL-2.0.2/COpenSSL/include -I /private/tmp/tests/PerfectTemplate/Packages/PerfectHTTPServer-2.0.4/Sources/CHTTPParser/include -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /private/tmp/tests/PerfectTemplate/.build/debug/ModuleCache -D SWIFT_PACKAGE -Xcc -fmodule-map-file=/private/tmp/tests/PerfectTemplate/Packages/COpenSSL-2.0.2/COpenSSL/include/module.modulemap -Xcc -fmodule-map-file=/private/tmp/tests/PerfectTemplate/.build/debug/CHTTPParser.build/module.modulemap -emit-module-doc-path /private/tmp/tests/PerfectTemplate/.build/debug/PerfectHTTPServer.build/HTTP11Request~partial.swiftdoc -Onone -parse-as-library -module-name PerfectHTTPServer -emit-module-path /private/tmp/tests/PerfectTemplate/.build/debug/PerfectHTTPServer.build/HTTP11Request~partial.swiftmodule -emit-dependencies-path /private/tmp/tests/PerfectTemplate/.build/debug/PerfectHTTPServer.build/HTTP11Request.d -emit-reference-dependencies-path /private/tmp/tests/PerfectTemplate/.build/debug/PerfectHTTPServer.build/HTTP11Request.swiftdeps -num-threads 8 -o /private/tmp/tests/PerfectTemplate/.build/debug/PerfectHTTPServer.build/HTTP11Request.swift.o
1.  While emitting SIL for 'parserBody' at /private/tmp/tests/PerfectTemplate/Packages/PerfectHTTPServer-2.0.4/Sources/PerfectHTTPServer/HTTP11Request.swift:224:2
2.  While emitting reabstraction thunk in SIL function @_TTRXFo_dGSPVs5UInt8___XFo_dGSPS___dGSqT__zoPs5Error__<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-11-15-a.xctoolchain/usr/bin/swift-build-tool -f /private/tmp/tests/PerfectTemplate/.build/debug.yaml
swift-ci commented 7 years ago

Comment by Kyle Jessup (JIRA)

Compiling a SPM package containing only the following code will cause the crash:

func parserBody(data: UnsafePointer<Int8>?, length: Int) -> Int {
    data?.withMemoryRebound(to: UInt8.self, capacity: length) {
        data in
        for i in 0..<length {

        }
    }
    return 0
}
aciidgh commented 7 years ago

Thanks badthing (JIRA User) for the reduced test case

belkadan commented 7 years ago

Assertion failed: (!outerOrigType.isTuple()), function planTupleIntoDirectResult, file /Volumes/Data/swift-public/swift/lib/SILGen/SILGenPoly.cpp, line 1851.

It looks like we infer the wrong result type for the closure:

      (optional_evaluation_expr implicit type='()?' location=<stdin>:2:8 range=[<stdin>:2:2 - line:7:2]
        (call_expr type='()?' location=<stdin>:2:8 range=[<stdin>:2:2 - line:7:2] nothrow  arg_labels=to:capacity:_:
          (dot_syntax_call_expr type='(UInt8.Type, Int, (UnsafePointer<UInt8>) throws -> ()?) throws -> ()?' location=<stdin>:2:8 range=[<stdin>:2:2 - line:2:8] nothrow

so over to the type-checker. (I think we've seen this before too.)