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-15920] Compiler crashes while type-checking: Right hand side does not have a canonical parent: same_type: τ_0_0.[AProtocol]B τ_1_0.[CProtocol]A.[AProtocol]B.[BProtocol]A.[AProtocol]B #58181

Closed
dnadoba opened this issue Feb 27, 2022 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types type checker Area → compiler: Semantic analysis

Comments

@dnadoba
Copy link
Member

dnadoba commented Feb 27, 2022

Previous ID SR-15920
Radar rdar://problem/89641532
Original Reporter @dnadoba
Type Bug
Status Resolved
Resolution Done
Environment

Trunk Development (main) from February 22, 2022

Additional Detail from JIRA
Votes 0
Component/s swift
Labels Bug
Assignee @slavapestov
Priority Medium

md5: ecbcc37ae24218338a09623c8d9f1626

Issue Description:

Compiler crashes while type-checking Foo.bar:

public protocol AProtocol {
    associatedtype B: BProtocol where B.A == Self
}


public protocol BProtocol {
    associatedtype A: AProtocol
}


public protocol CProtocol {
    associatedtype A: AProtocol
}


struct Foo<Value> {
    func bar<C: CProtocol>(c: C) where C.A == Value {}
}
CompileSwift normal arm64 /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift (in target 'PlaygroundPackage' from project 'PlaygroundPackage')
    cd /Users/davidnadoba/Repositories/PlaygroundPackage
    /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-02-22-a.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/ChangeObserver.swift -primary-file /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/main.swift -emit-dependencies-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.d -emit-reference-dependencies-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.swiftdeps -serialize-diagnostics-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.dia -target arm64-apple-macos10.10 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-13.3.0-Beta.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -I /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Products/Debug -I /Applications/Xcode-13.3.0-Beta.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Products/Debug -F /Applications/Xcode-13.3.0-Beta.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity\=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-02-22-a.xctoolchain/usr/bin/swift-driver -serialize-debugging-options -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-02-22-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Products/Debug/include -Xcc -I/Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/DerivedSources-normal/arm64 -Xcc -I/Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/DerivedSources/arm64 -Xcc -I/Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG\=1 -Xcc -working-directory/Users/davidnadoba/Repositories/PlaygroundPackage -module-name PlaygroundPackage -target-sdk-version 12.3 -o /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.o -index-unit-output-path /PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.o -index-store-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Index/DataStore -index-system-modules


Right hand side does not have a canonical parent: same_type: τ_0_0.[AProtocol]B τ_1_0.[CProtocol]A.[AProtocol]B.[BProtocol]A.[AProtocol]B
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-02-22-a.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/ChangeObserver.swift -primary-file /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/main.swift -emit-dependencies-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.d -emit-reference-dependencies-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.swiftdeps -serialize-diagnostics-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.dia -target arm64-apple-macos10.10 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-13.3.0-Beta.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -I /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Products/Debug -I /Applications/Xcode-13.3.0-Beta.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Products/Debug -F /Applications/Xcode-13.3.0-Beta.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-02-22-a.xctoolchain/usr/bin/swift-driver -serialize-debugging-options -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-02-22-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Products/Debug/include -Xcc -I/Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/DerivedSources-normal/arm64 -Xcc -I/Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/DerivedSources/arm64 -Xcc -I/Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -Xcc -working-directory/Users/davidnadoba/Repositories/PlaygroundPackage -module-name PlaygroundPackage -target-sdk-version 12.3 -o /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Build/Intermediates.noindex/PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.o -index-unit-output-path /PlaygroundPackage.build/Debug/PlaygroundPackage.build/Objects-normal/arm64/Changeable.o -index-store-path /Users/davidnadoba/Library/Developer/Xcode/DerivedData/PlaygroundPackage-gcucpqaknclhbxajrgurwpwagvcg/Index/DataStore -index-system-modules
1.  Apple Swift version 5.7-dev (LLVM f255403e4661ee9, Swift 496da9dda967e76)
2.  Compiling with the current language version
3.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift")
4.  While type-checking 'Foo' (at /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift:13:1)
5.  While type-checking 'bar(c:)' (at /Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift:14:5)
6.  While evaluating request InterfaceTypeRequest(PlaygroundPackage.(file).Foo.bar(c:)@/Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift:14:10)
7.  While evaluating request GenericSignatureRequest(PlaygroundPackage.(file).Foo.bar(c:)@/Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift:14:10)
8.  While evaluating request InferredGenericSignatureRequest(PlaygroundPackage, <Value>, <C : CProtocol>, PlaygroundPackage.(file).Foo.bar(c:)@/Users/davidnadoba/Repositories/PlaygroundPackage/Sources/PlaygroundPackage/Changeable.swift:14:10, {}, {(C, C)}, 0)
9.  While checking generic signature <τ_0_0, τ_1_0 where τ_0_0 == τ_1_0.A, τ_1_0 : CProtocol, τ_0_0.B == τ_1_0.A.B.A.B>
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           0x000000010876b218 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010876a478 llvm::sys::RunSignalHandlers() + 128
2  swift-frontend           0x000000010876b87c SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001b9a784e4 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001b9a60eb0 pthread_kill + 288
5  libsystem_c.dylib        0x00000001b999e314 abort + 164
6  swift-frontend           0x0000000108b9ff1c swift::GenericSignature::verify(llvm::ArrayRef<swift::Requirement>) const (.cold.42) + 0
7  swift-frontend           0x00000001053d26a4 swift::GenericSignature::verify(llvm::ArrayRef<swift::Requirement>) const + 2492
8  swift-frontend           0x00000001053f4fcc swift::GenericSignatureBuilder::computeGenericSignature(bool, swift::ProtocolDecl const*) && + 692
9  swift-frontend           0x00000001053f6a7c 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::$_68::operator()() const + 832
10 swift-frontend           0x00000001053f6480 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 + 192
11 swift-frontend           0x0000000104f97a20 llvm::PointerIntPair<swift::GenericSignature, 1u, unsigned int, llvm::PointerLikeTypeTraits<swift::GenericSignature>, llvm::PointerIntPairInfo<swift::GenericSignature, 1u, llvm::PointerLikeTypeTraits<swift::GenericSignature> > > swift::SimpleRequest<swift::InferredGenericSignatureRequest, llvm::PointerIntPair<swift::GenericSignature, 1u, unsigned int, llvm::PointerLikeTypeTraits<swift::GenericSignature>, llvm::PointerIntPairInfo<swift::GenericSignature, 1u, 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>::callDerived<0ul, 1ul, 2ul, 3ul, 4ul, 5ul, 6ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul, 1ul, 2ul, 3ul, 4ul, 5ul, 6ul>) const + 204
12 swift-frontend           0x0000000104fd3418 llvm::Expected<swift::InferredGenericSignatureRequest::OutputType> swift::Evaluator::getResultUncached<swift::InferredGenericSignatureRequest>(swift::InferredGenericSignatureRequest const&) + 372
13 swift-frontend           0x0000000104fd30cc llvm::Expected<swift::InferredGenericSignatureRequest::OutputType> swift::Evaluator::getResultCached<swift::InferredGenericSignatureRequest, (void*)0>(swift::InferredGenericSignatureRequest const&) + 1312
14 swift-frontend           0x0000000104fcd618 swift::InferredGenericSignatureRequest::OutputType swift::evaluateOrDefault<swift::InferredGenericSignatureRequest>(swift::Evaluator&, swift::InferredGenericSignatureRequest, swift::InferredGenericSignatureRequest::OutputType) + 44
15 swift-frontend           0x0000000104f44748 swift::GenericSignatureRequest::evaluate(swift::Evaluator&, swift::GenericContext*) const + 916
16 swift-frontend           0x00000001052d50d8 llvm::Expected<swift::GenericSignatureRequest::OutputType> swift::Evaluator::getResultUncached<swift::GenericSignatureRequest>(swift::GenericSignatureRequest const&) + 388
17 swift-frontend           0x00000001052d4e6c llvm::Expected<swift::GenericSignatureRequest::OutputType> swift::Evaluator::getResultCached<swift::GenericSignatureRequest, (void*)0>(swift::GenericSignatureRequest const&) + 140
18 swift-frontend           0x00000001052ac2b0 swift::GenericContext::getGenericSignature() const + 84
19 swift-frontend           0x0000000104efa6e4 swift::InterfaceTypeRequest::evaluate(swift::Evaluator&, swift::ValueDecl*) const + 236
20 swift-frontend           0x00000001052f9204 llvm::Expected<swift::InterfaceTypeRequest::OutputType> swift::Evaluator::getResultUncached<swift::InterfaceTypeRequest>(swift::InterfaceTypeRequest const&) + 392
21 swift-frontend           0x00000001052f8f94 llvm::Expected<swift::InterfaceTypeRequest::OutputType> swift::Evaluator::getResultCached<swift::InterfaceTypeRequest, (void*)0>(swift::InterfaceTypeRequest const&) + 140
22 swift-frontend           0x00000001052b4a78 swift::InterfaceTypeRequest::OutputType swift::evaluateOrDefault<swift::InterfaceTypeRequest>(swift::Evaluator&, swift::InterfaceTypeRequest, swift::InterfaceTypeRequest::OutputType) + 52
23 swift-frontend           0x00000001052a9ab0 swift::ValueDecl::getInterfaceType() const + 76
24 swift-frontend           0x0000000104f27478 (anonymous namespace)::DeclChecker::visitFuncDecl(swift::FuncDecl*) + 48
25 swift-frontend           0x0000000104f1f490 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 224
26 swift-frontend           0x0000000104f23944 swift::ASTVisitor<(anonymous namespace)::DeclChecker, void, void, void, void, void, void>::visit(swift::Decl*) + 4068
27 swift-frontend           0x0000000104f1f490 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 224
28 swift-frontend           0x0000000104f1f39c swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 116
29 swift-frontend           0x0000000104fccdcc swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 176
30 swift-frontend           0x0000000104fceb48 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 400
31 swift-frontend           0x0000000104fce8e8 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 124
32 swift-frontend           0x0000000104fccc10 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 44
33 swift-frontend           0x000000010434ceb8 bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_6>(long, swift::SourceFile&) + 16
34 swift-frontend           0x0000000104349724 swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) + 76
35 swift-frontend           0x00000001043496ac swift::CompilerInstance::performSema() + 76
36 swift-frontend           0x00000001042fae50 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>) + 56
37 swift-frontend           0x00000001042f1a10 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2940
38 swift-frontend           0x0000000104206690 swift::mainEntry(int, char const**) + 524
39 dyld                     0x0000000110fd50f4 start + 520
error: Abort trap: 6 (in target 'PlaygroundPackage' from project 'PlaygroundPackage')

Does not crash with Swift 5.5.2 (Xcode 13.2.1) and Swift 5.6 (Xcode 13.3 Beta 3)

@dnadoba
Copy link
Member Author

dnadoba commented Feb 27, 2022

@swift-ci create

@slavapestov
Copy link
Member

The bug is also present in Swift 5.5 and 5.6, but the toolchains shipped in Xcode do not have asserts enabled so they don't catch these kinds of internal errors. The test case builds successfully with -Xfrontend -requirement-machine-inferred-signatures=on with a trunk snapshot.

@slavapestov
Copy link
Member

I'll add a regression test and close this bug once the flag is on by default.

@slavapestov
Copy link
Member

#42113

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added generics Feature: generic declarations and types compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis crash Bug: A crash, i.e., an abnormal termination of software compiler crash and removed swift labels Jan 16, 2023
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 crash Bug: A crash, i.e., an abnormal termination of software generics Feature: generic declarations and types type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants