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

[SR-14668] Compiler crash involving optional param for closure param of override #57019

Closed
swift-ci opened this issue May 27, 2021 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14668
Radar rdar://problem/78587664
Original Reporter ericsink (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 5.4.1 on Windows 10

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: b60ce4fb2ae507852714515d5259a70a

Issue Description:

If I put the following code into over.swift:

class A { }
class B<T> : A { }
class C {
 public func bar(x : (A?) -> Void) { }
}
class D<T> : C {
 public override func bar(x : (B<T>?) -> Void) { }
}

and compile like this:

swiftc -emit-module -parse-as-library over.swift

then I get this crash:

Assertion failed: !substType->hasTypeParameter() && !substType->hasArchetype(), file D:\a\1\s\swift\lib\SIL\IR\SILFunctionType.cpp, line 1297
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0. Program arguments: C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -frontend -emit-module -primary-file over.swift -emit-module-doc-path C:\Users\eric\AppData\Local\Temp\over-dc8f5a.swiftdoc -emit-module-source-info-path C:\Users\eric\AppData\Local\Temp\over-dc8f5a.swiftsourceinfo -target x86_64-unknown-windows-msvc -disable-objc-interop -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -color-diagnostics -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -parse-as-library -module-name over -o C:\Users\eric\AppData\Local\Temp\over-dc8f5a.swiftmodule
1. compnerd.org Swift version 5.4.1 (swift-5.4.1-RELEASE)
2. While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "over.swift")
 #&#8203;0 0x00007ff6a9a4bf25 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x457bf25)
 #&#8203;1 0x00007ffce9581881 (C:\WINDOWS\System32\ucrtbase.dll+0x71881)
 #&#8203;2 0x00007ffce9582851 (C:\WINDOWS\System32\ucrtbase.dll+0x72851)
 #&#8203;3 0x00007ffce95841b5 (C:\WINDOWS\System32\ucrtbase.dll+0x741b5)
 #&#8203;4 0x00007ffce95844f1 (C:\WINDOWS\System32\ucrtbase.dll+0x744f1)
 #&#8203;5 0x00007ff6a613ddff (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc6ddff)
 #&#8203;6 0x00007ff6a6145a5d (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc75a5d)
 #&#8203;7 0x00007ff6a614624f (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc7624f)
 #&#8203;8 0x00007ff6a613c1f4 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc6c1f4)
 #&#8203;9 0x00007ff6a612e93a (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc5e93a)
#&#8203;10 0x00007ff6a613ac89 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc6ac89)
#&#8203;11 0x00007ff6a613ae36 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc6ae36)
#&#8203;12 0x00007ff6a60bf372 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xbef372)
#&#8203;13 0x00007ff6a60bd138 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xbed138)
#&#8203;14 0x00007ff6a60b6d3c (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xbe6d3c)
#&#8203;15 0x00007ff6a6145aa4 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc75aa4)
#&#8203;16 0x00007ff6a614624f (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc7624f)
#&#8203;17 0x00007ff6a613c1f4 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc6c1f4)
#&#8203;18 0x00007ff6a612e93a (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc5e93a)
#&#8203;19 0x00007ff6a613ac89 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc6ac89)
#&#8203;20 0x00007ff6a6136f04 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xc66f04)
#&#8203;21 0x00007ff6a5a6a129 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x59a129)
#&#8203;22 0x00007ff6a5a696ea (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x5996ea)
#&#8203;23 0x00007ff6a5a69176 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x599176)
#&#8203;24 0x00007ff6a5a6e078 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x59e078)
#&#8203;25 0x00007ff6a5a338a0 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x5638a0)
#&#8203;26 0x00007ff6a5a2cbfd (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x55cbfd)
#&#8203;27 0x00007ff6a5a2d649 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x55d649)
#&#8203;28 0x00007ff6a5a34318 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x564318)
#&#8203;29 0x00007ff6a5a24552 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x554552)
#&#8203;30 0x00007ff6a5a32093 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x562093)
#&#8203;31 0x00007ff6a55caef0 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xfaef0)
#&#8203;32 0x00007ff6a55c9e6a (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xf9e6a)
#&#8203;33 0x00007ff6a55cbf05 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0xfbf05)
#&#8203;34 0x00007ff6a554bdfe (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x7bdfe)
#&#8203;35 0x00007ff6a554df36 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x7df36)
#&#8203;36 0x00007ff6a9ae53c4 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x46153c4)
#&#8203;37 0x00007ffceb707034 (C:\WINDOWS\System32\KERNEL32.DLL+0x17034)
#&#8203;38 0x00007ffceb842651 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x52651)
<unknown>:0: error: compile command failed due to signal -2147483645 (use -v to see invocation)

If I remove the two question marks in the code snippet (thus making those params not-optional), the crash goes away.

@typesanitizer
Copy link

@swift-ci create

Triggers an assertion failure on main.

Assertion failed: (!substType->hasTypeParameter() && !substType->hasArchetype()), function getSubstitutedInterfaceType, file SILFunctionType.cpp, line 1297.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.      Program arguments: /Users/varun/foss-swift/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -c -primary-file tmp.swift -target x86_64-apple-macosx12.0 -enable-objc-interop -sdk /Applications/Xcode3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -color-diagnostics -new-driver-path /Users/varun/foss-swift/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift-driver -resource-dir /Users/varun/foss-swift/build/Ninja-ReleaseAssert/swift-macosx-x86_64/lib/swift -module-name tmp -target-sdk-version 12.0.0 -o /var/folders/9t/dn6p4v392nb8c8cwxfyxc84c0000gn/T/TemporaryDirectory.6xWDmG/tmp-1.o
1.      Swift version 5.5-dev (LLVM f31c285aff37dd7, Swift a0b1c0b45b82541)
2.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "tmp.swift")
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010bad61f7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x000000010bad5108 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x000000010bad6836 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007fff2034d4ad _sigtramp + 29
4  libsystem_platform.dylib 0x0000000117cef690 _sigtramp + 18446603344670237184
5  libsystem_c.dylib        0x00007fff20287f10 abort + 123
6  libsystem_c.dylib        0x00007fff202872e3 err + 0
7  swift-frontend           0x000000010bb521c3 (anonymous namespace)::SubstFunctionTypeCollector::getSubstitutedInterfaceType(swift::Lowering::AbstractionPattern, swift::CanType) (.cold.4) + 35
8  swift-frontend           0x000000010713c031 (anonymous namespace)::SubstFunctionTypeCollector::getSubstitutedInterfaceType(swift::Lowering::AbstractionPattern, swift::CanType) + 353
9  swift-frontend           0x000000010713ba0b (anonymous namespace)::DestructureInputs::visit(swift::ValueOwnership, bool, swift::Lowering::AbstractionPattern, swift::CanType, bool) + 187
10 swift-frontend           0x0000000107139e84 getSILFunctionType(swift::Lowering::TypeConverter&, swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILExtInfoBuilder, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, swift::ProtocolConformanceRef) + 2084
 

@slavapestov
Copy link
Member

No longer crashes. I'll add a regression test.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants