swiftlang / swift

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

Compiler gets Signal 11 when using types as keys in dictionary #58555

Open funcJeff opened 2 years ago

funcJeff commented 2 years ago

Describe the bug Compiler crashes and informs me to go here and open bug report.

I searched for "useConformancesFromType" among open bugs and found nothing.

To Reproduce Steps to reproduce the behavior:

  1. Place attached 26 lines of code into file named compilercrash.swift in present working directory.
  2. Run swiftc compilercrash.swift
  3. Signal 11.

Expected behavior swift creates object file instead.

Screenshots

2022-04-30T09:03:11 ~/Code
‹pliny› 🐵 swiftc compilercrash.swift 
error: compile command failed due to signal 11 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file compilercrash.swift -target x86_64-apple-macosx12.0 -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -color-diagnostics -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name compilercrash -target-sdk-version 12.3 -o /var/folders/gv/cjrdp6v5317djql1cf6185dw0000gn/T/TemporaryDirectory.KZfgFE/compilercrash-1.o
1.  Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
2.  Compiling with the current language version
3.  While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "compilercrash.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           0x00000001081e3de7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x00000001081e2e38 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x00000001081e4440 SignalHandler(int) + 288
3  libsystem_platform.dylib 0x00007ff8093c9dfd _sigtramp + 29
4  libsystem_platform.dylib 0x00007ff7bd082e90 _sigtramp + 18446744072431046832
5  swift-frontend           0x00000001036ce3cc void llvm::function_ref<void (swift::CanType)>::callback_fn<swift::Lowering::SILGenModule::useConformancesFromType(swift::CanType)::$_0>(long, swift::CanType) + 204
6  swift-frontend           0x000000010314814d bool llvm::function_ref<bool (swift::CanType)>::callback_fn<swift::CanType::visit(llvm::function_ref<void (swift::CanType)>) const::'lambda'(swift::Type)>(long, swift::CanType) + 13
7  swift-frontend           0x000000010445ba4e swift::Type::findIf(llvm::function_ref<bool (swift::Type)>) const::Walker::walkToTypePre(swift::Type) + 14
8  swift-frontend           0x00000001036ccde2 swift::Lowering::SILGenModule::useConformancesFromType(swift::CanType) + 274
9  swift-frontend           0x000000010362847b swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 7803
10 swift-frontend           0x0000000103716513 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 195
11 swift-frontend           0x000000010362bdb9 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 649
12 swift-frontend           0x0000000102f0c1fb swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 15131
13 swift-frontend           0x0000000102ecb5d4 swift::mainEntry(int, char const**) + 1108
14 dyld                     0x0000000110a4d51e start + 462
2022-04-30T09:05:51 ~/Code
‹pliny› 🐵 swiftc --version                                                                                                                                                                             1 ↵
swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
Target: x86_64-apple-macosx12.0

Environment (please complete the following information):

Additional context Contents of compilercrash.swift:

class Lumber { }
class Fruit { }

enum Size {
    case small
    case medium
    case large
}

let lumberSize = [
    Size.small: "2x4",
    Size.medium: "4x6",
    Size.large: "6x10"
]

let fruitSize = [
    Size.small: "grape",
    Size.medium: "apple",
    Size.large: "watermelon"
]

let size:[AnyObject.Type:Dictionary] = [
    Lumber.self: lumberSize,
    Fruit.self: fruitSize
]
print(size)
CodaFi commented 2 years ago

Reduced

class Lumber { }

let size:[AnyObject.Type:Dictionary] = [
   Lumber.self: ["":""]
]

We're skipping validating the Hashable conformance - or lack thereof - of AnyObject.Type in key position because of the unbound Dictionary in the type.