swift: Compiler Crash on nested associatedtype (5.7 XCode beta6)
Describe the bug
Compiler Crash using Swift 5.7 (XCode 14-Beta6) on the following code snippet. Just run swift test.swift
(use v5.7 on XCode14-beta6).
Steps to reproduce: Compile the attached code using Swift 5.7 - Xcode14-beta6. Compiles fine on 5.6 & before.
Expected behavior The compiler should not crash but emit a diagnostic error.
Code
import Foundation
class Object { init(){} }
class GlobalSettings {init(){}}
class RealmGlobalSettings: Object {}
protocol DomainConvertibleType {
associatedtype DomainType
var toDomainObject: DomainType { get }
}
protocol RealmConvertible {
associatedtype RealmType: DomainConvertibleType
var identifier: String { get }
func toRealmObject(realm: String?) -> RealmType
}
public protocol RepositoryType {
associatedtype T
func save(entity: T)
}
class Repository<T: RealmConvertible>: RepositoryType where T == T.RealmType.DomainType, T.RealmType: Object {
public func save(entity: T) {
print("Test")
}
}
extension Repository: SetGlobalSettingsUseCase where T == GlobalSettings {
func save(globalSettings entity: GlobalSettings) {}
}
extension RealmGlobalSettings: DomainConvertibleType {
var toDomainObject: GlobalSettings {
GlobalSettings()
}
}
public protocol SetGlobalSettingsUseCase {
func save(globalSettings: GlobalSettings)
}
extension GlobalSettings: RealmConvertible {
typealias RealmType = RealmGlobalSettings
func toRealmObject(realm: String?) -> RealmGlobalSettings {
return RealmGlobalSettings()
}
}
Environment (please fill out the following information)
- OS: macOS 12.5.1
- Xcode 14 beta 6
- swift-driver version: 1.62.3 Apple Swift version 5.7 (swiftlang-5.7.0.123.8 clang-1400.0.29.50) Target: x86_64-apple-macosx12.0
Crash Dump
Cannot build interface type for term τ_0_0.[RealmConvertible:RealmType].[DomainConvertibleType:DomainType]
Prefix term does not not have a nested type named RealmType: τ_0_0
Property map entry: τ_0_0 => { layout: _NativeClass superclass: [superclass: GlobalSettings] concrete_type: [concrete: GlobalSettings] }
Property map: {
τ_0_0 => { layout: _NativeClass superclass: [superclass: GlobalSettings] concrete_type: [concrete: GlobalSettings] }
}
Stack dump:
0. Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret test.swift -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-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name test -disable-clang-spi -target-sdk-version 12.3
1. Apple Swift version 5.7 (swiftlang-5.7.0.123.8 clang-1400.0.29.50)
2. Compiling with the current language version
3. While evaluating request TypeCheckSourceFileRequest(source_file "test.swift")
4. While type-checking extension of Repository (at test.swift:33:1)
5. While evaluating request GenericSignatureRequest(extension of Repository)
6. While evaluating request InferredGenericSignatureRequest(test, NULL, <T>, extension of Repository, {}, {(Repository<T>, null)}, 1)
7. While evaluating request InferredGenericSignatureRequestRQM(NULL, <T>, extension of Repository, {}, {(Repository<T>, null)}, 1)
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 0x000000010a777827 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1 swift-frontend 0x000000010a776858 llvm::sys::RunSignalHandlers() + 248
2 swift-frontend 0x000000010a777e40 SignalHandler(int) + 288
3 libsystem_platform.dylib 0x00007ff810b77dfd _sigtramp + 29
4 swift-frontend 0x00000001068feb97 swift::rewriting::Symbol::dump(llvm::raw_ostream&) const + 2423
5 libsystem_c.dylib 0x00007ff810aadd24 abort + 123
6 swift-frontend 0x00000001068bc861 getTypeForSymbolRange(swift::rewriting::Symbol const*, swift::rewriting::Symbol const*, swift::ArrayRefView<swift::Type, swift::GenericTypeParamType*, swift::GenericTypeParamType* swift::staticCastHelper<swift::GenericTypeParamType>(swift::Type const&), true>, swift::rewriting::PropertyMap const&) + 2465
7 swift-frontend 0x00000001068d00be swift::rewriting::RequirementMachine::buildRequirementsFromRules(llvm::ArrayRef<unsigned int>, llvm::ArrayRef<unsigned int>, swift::ArrayRefView<swift::Type, swift::GenericTypeParamType*, swift::GenericTypeParamType* swift::staticCastHelper<swift::GenericTypeParamType>(swift::Type const&), true>, bool, std::__1::vector<swift::Requirement, std::__1::allocator<swift::Requirement> >&, std::__1::vector<swift::ProtocolTypeAlias, std::__1::allocator<swift::ProtocolTypeAlias> >&) const + 718
8 swift-frontend 0x00000001068deea4 swift::rewriting::RequirementMachine::computeMinimalGenericSignature(bool) + 244
9 swift-frontend 0x00000001068e1b3d swift::InferredGenericSignatureRequestRQM::evaluate(swift::Evaluator&, swift::GenericSignatureImpl const*, swift::GenericParamList*, swift::WhereClauseOwner, llvm::SmallVector<swift::Requirement, 2u>, llvm::SmallVector<swift::TypeLoc, 2u>, bool) const + 3213
10 swift-frontend 0x000000010633f0b7 swift::SimpleRequest<swift::InferredGenericSignatureRequestRQM, llvm::PointerIntPair<swift::GenericSignature, 3u, swift::OptionSet<swift::GenericSignatureErrorFlags, unsigned int>, llvm::PointerLikeTypeTraits<swift::GenericSignature>, llvm::PointerIntPairInfo<swift::GenericSignature, 3u, llvm::PointerLikeTypeTraits<swift::GenericSignature> > > (swift::GenericSignatureImpl const*, swift::GenericParamList*, swift::WhereClauseOwner, llvm::SmallVector<swift::Requirement, 2u>, llvm::SmallVector<swift::TypeLoc, 2u>, bool), (swift::RequestFlags)2>::evaluateRequest(swift::InferredGenericSignatureRequestRQM const&, swift::Evaluator&) + 343
11 swift-frontend 0x0000000106816a2e llvm::Expected<swift::InferredGenericSignatureRequestRQM::OutputType> swift::Evaluator::getResultCached<swift::InferredGenericSignatureRequestRQM, (void*)0>(swift::InferredGenericSignatureRequestRQM const&) + 2158
12 swift-frontend 0x00000001068095d5 swift::InferredGenericSignatureRequest::evaluate(swift::Evaluator&, swift::ModuleDecl*, swift::GenericSignatureImpl const*, swift::GenericParamList*, swift::WhereClauseOwner, llvm::SmallVector<swift::Requirement, 2u>, llvm::SmallVector<swift::TypeLoc, 2u>, bool) const + 421
13 swift-frontend 0x000000010633ef1f swift::SimpleRequest<swift::InferredGenericSignatureRequest, llvm::PointerIntPair<swift::GenericSignature, 3u, swift::OptionSet<swift::GenericSignatureErrorFlags, unsigned int>, llvm::PointerLikeTypeTraits<swift::GenericSignature>, llvm::PointerIntPairInfo<swift::GenericSignature, 3u, llvm::PointerLikeTypeTraits<swift::GenericSignature> > > (swift::ModuleDecl*, swift::GenericSignatureImpl const*, swift::GenericParamList*, swift::WhereClauseOwner, llvm::SmallVector<swift::Requirement, 2u>, llvm::SmallVector<swift::TypeLoc, 2u>, bool), (swift::RequestFlags)2>::evaluateRequest(swift::InferredGenericSignatureRequest const&, swift::Evaluator&) + 351
14 swift-frontend 0x000000010621454d llvm::Expected<swift::InferredGenericSignatureRequest::OutputType> swift::Evaluator::getResultUncached<swift::InferredGenericSignatureRequest>(swift::InferredGenericSignatureRequest const&) + 733
15 swift-frontend 0x000000010621415e llvm::Expected<swift::InferredGenericSignatureRequest::OutputType> swift::Evaluator::getResultCached<swift::InferredGenericSignatureRequest, (void*)0>(swift::InferredGenericSignatureRequest const&) + 702
16 swift-frontend 0x00000001062da36c swift::GenericSignatureRequest::evaluate(swift::Evaluator&, swift::GenericContext*) const + 2380
17 swift-frontend 0x00000001066de60e swift::GenericContext::getGenericSignature() const + 1934
18 swift-frontend 0x00000001062af581 swift::ASTVisitor<(anonymous namespace)::DeclChecker, void, void, void, void, void, void>::visit(swift::Decl*) + 2193
19 swift-frontend 0x00000001062ab629 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 441
20 swift-frontend 0x00000001062ab461 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 193
21 swift-frontend 0x0000000106387cf7 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 567
22 swift-frontend 0x000000010638ae9d llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 669
23 swift-frontend 0x0000000106387a72 swift::performTypeChecking(swift::SourceFile&) + 114
24 swift-frontend 0x00000001053b3a84 swift::CompilerInstance::performSema() + 292
25 swift-frontend 0x0000000105336e17 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4711
26 swift-frontend 0x00000001052cd12a swift::mainEntry(int, char const**) + 3082
27 dyld 0x000000011c40e52e start + 462
[1] 19966 abort test.swift
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 19 (7 by maintainers)
The bug is in the ‘concrete contraction’ pass of the requirement machine, which I need to remove at some point… in the mean time I’ll come up with a fix.
The following reduction attempt does not reach the more descriptive abortion, and hits an immediately preceding
assert
instead: