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-11639] Compiler crashes when using typealias in an associatedtype constraint #54050

Closed
swift-ci opened this issue Oct 19, 2019 · 3 comments
Closed
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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11639
Radar rdar://problem/56466696
Original Reporter palle (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 5.1.1 (swiftlang-1100.0.275.2 clang-1100.0.33.9)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee @zoecarver
Priority Medium

md5: 19e2f23cca4efe5b3441b20431a327d7

Issue Description:

Given

protocol FooProtocol { 
    associatedtype Bar 
} 
struct Foo<Bar>: FooProtocol { 
    var bar: Bar 
} 

the following protocol declaration crashes the compiler:

protocol BazProtocol: FooProtocol { 
    associatedtype Foo1: FooProtocol where Foo1.Bar == Foo2.Bar 
    associatedtype Foo2Bar 
    typealias Foo2 = Foo<Foo2Bar> 
}

Without the typealias in the associatedtype constraint, the compiler does not crash. The following code compiles just fine.

protocol BazProtocol: FooProtocol { 
    associatedtype Foo1: FooProtocol where Foo1.Bar == Foo<Foo2Bar>.Bar 
    associatedtype Foo2Bar 
} 

When the compiler crashes, the following stack trace is dumped:

1.  While type-checking 'BazProtocol' (at /path/to/file.swift:16:1)
2.  While validating 'BazProtocol' (at /path/to/file.swift:16:1)
0  swift                    0x0000000110b4bb73 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000110b4b346 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff6c985b1d _sigtramp + 29
3  libsystem_platform.dylib 0x00007ffee34fffe0 _sigtramp + 1991746784
4  swift                    0x000000010d6f2300 swift::GenericSignatureBuilder::finalize(swift::SourceLoc, swift::ArrayRefView<swift::Type, swift::GenericTypeParamType*, swift::GenericTypeParamType* swift::staticCastHelper<swift::GenericTypeParamType>(swift::Type const&), true>, bool) + 496
5  swift                    0x000000010d7006fc swift::GenericSignatureBuilder::computeGenericSignature(swift::SourceLoc, bool, bool) && + 44
6  swift                    0x000000010d6905b1 swift::ProtocolDecl::computeRequirementSignature() + 2065
7  swift                    0x000000010d32587b swift::TypeChecker::validateGenericTypeSignature(swift::GenericTypeDecl*) + 75
8  swift                    0x000000010d2edaed swift::TypeChecker::validateDecl(swift::ValueDecl*) + 893
9  swift                    0x000000010d2e6f71 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 2241
10 swift                    0x000000010d3a6da6 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1702
11 swift                    0x000000010ca9a93b swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t)::$_0::operator()(swift::SourceFile&) const + 91
12 swift                    0x000000010ca9969b swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 5371
13 swift                    0x000000010c78ef66 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 806
14 swift                    0x000000010c78b434 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
15 swift                    0x000000010c718933 main + 1219
16 libdyld.dylib            0x00007fff6c780405 start + 1
@belkadan
Copy link
Contributor

With assertions, on recent-ish master:

Assertion failed: (type->isTypeParameter() == static_cast<bool>(equivClass) && "type parameters must have equivalence classes"), function ResolvedType, file /Volumes/Data/swift-public/swift/lib/AST/GenericSignatureBuilderImpl.h, line 33.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin18.7.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode11.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--daf342.o 
1.  Swift version 5.1-dev (LLVM af1f73e9e9, Swift 79a5551a13)
2.  While type-checking 'BazProtocol' (at <stdin>:8:1)
3.  While validating 'BazProtocol' (at <stdin>:8:1)
4.  While evaluating request RequirementSignatureRequest(main.(file).BazProtocol@<stdin>:8:10)

@belkadan
Copy link
Contributor

@swift-ci create

@slavapestov
Copy link
Member

#35956

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants