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-8019] Conditional conformance typealias segfault #50552

Closed
stephencelis opened this issue Jun 16, 2018 · 9 comments
Closed

[SR-8019] Conditional conformance typealias segfault #50552

stephencelis opened this issue Jun 16, 2018 · 9 comments
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

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-8019
Radar rdar://problem/41216423
Original Reporter @stephencelis
Type Bug
Status Resolved
Resolution Done
Environment

Swift 4.15 (Xcode 8 beta)

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

md5: 3aa5f0bde3771054f7a549acb48e1558

Issue Description:

The following code segfaults:

struct A<C: Collection> {
  typealias Element = C.Element
}

extension A: Equatable where C: Equatable, Element: Equatable {
  public static func == (lhs: A, rhs: A) -> Bool {
    return true
  }
}

With:

error: associated type 'Element' can only be used with a concrete type or generic parameter base
  typealias Element = Collection.Element
                                 ^
0  swift                    0x000000010af94c5a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010af94066 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff7d995d9a _sigtramp + 26
3  swift                    0x00000001087322d6 swift::GenericSignature::enumeratePairedRequirements(llvm::function_ref<bool (swift::Type, llvm::ArrayRef<swift::Requirement>)>) const + 1446
4  swift                    0x00000001086618f0 swift::ASTContext::getConformance(swift::Type, swift::ProtocolDecl*, swift::SourceLoc, swift::DeclContext*, swift::ProtocolConformanceState) + 656
5  swift                    0x00000001086fd51f swift::ConformanceLookupTable::getConformance(swift::NominalTypeDecl*, swift::ConformanceLookupTable::ConformanceEntry*) + 1199
6  swift                    0x000000010879469c swift::NominalTypeDecl::lookupConformance(swift::ModuleDecl*, swift::ProtocolDecl*, llvm::SmallVectorImpl<swift::ProtocolConformance*>&) const + 684
7  swift                    0x0000000108774bd4 swift::ModuleDecl::lookupConformance(swift::Type, swift::ProtocolDecl*) + 1892
8  swift                    0x0000000108745583 swift::GenericSignatureBuilder::lookupConformance(swift::CanType, swift::Type, swift::ProtocolType*) + 227
9  swift                    0x00000001087423b2 swift::GenericSignatureBuilder::addTypeRequirement(llvm::PointerUnion<swift::GenericSignatureBuilder::PotentialArchetype*, swift::Type>, llvm::PointerUnion<swift::GenericSignatureBuilder::PotentialArchetype*, swift::Type>, swift::GenericSignatureBuilder::FloatingRequirementSource, swift::GenericSignatureBuilder::UnresolvedHandlingKind, swift::ModuleDecl*) + 3266
10 swift                    0x000000010874a1cf swift::GenericSignatureBuilder::addRequirement(swift::RequirementRepr const*, swift::GenericSignatureBuilder::FloatingRequirementSource, swift::SubstitutionMap const*, swift::ModuleDecl*) + 1807
11 swift                    0x00000001083b9646 swift::TypeChecker::checkGenericParamList(swift::GenericSignatureBuilder*, swift::GenericParamList*, swift::GenericSignature*, swift::GenericTypeResolver*) + 646
12 swift                    0x00000001083bf45d swift::TypeChecker::checkGenericEnvironment(swift::GenericParamList*, swift::DeclContext*, swift::GenericSignature*, bool, swift::ExtensionDecl*, llvm::function_ref<void (swift::GenericSignatureBuilder&)>, bool) + 1421
13 swift                    0x0000000108382803 swift::TypeChecker::validateExtension(swift::ExtensionDecl*) + 563
14 swift                    0x000000010839dafc (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 332
15 swift                    0x0000000108435616 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1830
16 swift                    0x000000010806c995 swift::CompilerInstance::performSema() + 4933
17 swift                    0x00000001072678db performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 731
18 swift                    0x000000010726410f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7839
19 swift                    0x000000010720dc48 main + 13144
20 libdyld.dylib            0x00007fff7d793ee1 start + 1
@belkadan
Copy link
Contributor

Plenty of things wrong with this code, but there should never be a crash!

@swift-ci create

@stephencelis
Copy link
Contributor Author

It's a reduced case. It should compile just fine, no?

@belkadan
Copy link
Contributor

Well, no. The typealias should say C.Element, not Collection.Element, and the conditional conformance says A: Equatable where A: Equatable, which makes no sense.

@stephencelis
Copy link
Contributor Author

Sorry those were typos that snuck in when reducing. I've updated the example.

@belkadan
Copy link
Contributor

That version doesn't crash for me. Can you double-check?

@huonw
Copy link
Mannequin

huonw mannequin commented Jun 19, 2018

As Jordan says, I see a crash with the original:

struct A<C: Collection> { 
    typealias Element = Collection.Element 
} 

extension A: Equatable where A: Equatable, Element: Equatable { 
    public static func == (lhs: NonEmpty, rhs: NonEmpty) -> Bool { 
        return true 
    } 
}

but not with the updated one. If that's the correct reduction, then it's related to https://bugs.swift.org/browse/SR-6569.

@huonw
Copy link
Mannequin

huonw mannequin commented Jun 21, 2018

I resolved the crash in the original version of the code in #17356 so since we can't reproduce it in the new, I'm going to call this done. Please open another bug if you find the other crash you mention!

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Jul 26, 2018

@stephencelis, Could you verify if the problem is fixed and if so move the JIRA to "Closed"?
Thanks!
Anna

@stephencelis
Copy link
Contributor Author

Yup, looks good! Sorry for the original confusing report 🙂

@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
Projects
None yet
Development

No branches or pull requests

3 participants