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-13089] [Swift 5.3] SIGSEGV while type-checking protocol conformance #55535

Open
jegnux opened this issue Jun 26, 2020 · 3 comments
Open

[SR-13089] [Swift 5.3] SIGSEGV while type-checking protocol conformance #55535

jegnux opened this issue Jun 26, 2020 · 3 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 type checker Area → compiler: Semantic analysis

Comments

@jegnux
Copy link

jegnux commented Jun 26, 2020

Previous ID SR-13089
Radar None
Original Reporter @jegnux
Type Bug

Attachment: Download

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

md5: 410cc4d93f5bc6460eee4f1cf31b1237

Issue Description:

The following code compiles fine with Swift 5.2 but not with Swift 5.3:

protocol X {}
protocol Y {}

protocol A {
    static func handle(_ string: String, using x: inout X)
    static func handle(_ string: String, using y: inout Y)
}

enum A_Imp: A {
    static func handle(_ string: String, using x: inout X) {
        // ...
    }
    static func handle(_ string: String, using y: inout Y) {
        // ... 
    }
}

It fails only if:

((X is a protocol) OR (Y is a protocol)) AND ((X is inout) AND (Y is inout))
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret Contents.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode-11.5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -target-sdk-version 10.15.4 -module-name Contents
1.  Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "Contents.swift")
3.  While type-checking 'A_Imp' (at Contents.swift:10:1)
4.  While type-checking protocol conformance to 'A' (at Contents.swift:5:1) for type 'A_Imp' (declared at [Contents.swift:10:1 - line:17:1] RangeText="enum A_Imp: A {
    static func handle(_ string: String, using x: inout X) {

    }
    static func handle(_ string: String, using y: inout Y) {

    }
")
0  swift                    0x0000000108e6bf65 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000108e6af65 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000108e6c51f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff70e405fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338622171680
5  swift                    0x000000010572569b swift::constraints::ConstraintSystem::simplifyRestrictedConstraint(swift::constraints::ConversionRestrictionKind, swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 779
6  swift                    0x00000001057153d0 swift::constraints::ConstraintSystem::matchTypes(swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 14960
7  swift                    0x0000000105720535 swift::constraints::ConstraintSystem::repairFailures(swift::Type, swift::Type, swift::constraints::ConstraintKind, llvm::SmallVectorImpl<swift::constraints::RestrictionOrFix>&, swift::constraints::ConstraintLocatorBuilder) + 12677
8  swift                    0x0000000105715365 swift::constraints::ConstraintSystem::matchTypes(swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 14853
9  swift                    0x0000000105715789 swift::constraints::ConstraintSystem::matchTypes(swift::Type, swift::Type, swift::constraints::ConstraintKind, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 15913
10 swift                    0x0000000105739f90 swift::constraints::ConstraintSystem::addConstraintImpl(swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocatorBuilder, bool) + 96
11 swift                    0x0000000105711162 swift::constraints::ConstraintSystem::addConstraint(swift::constraints::ConstraintKind, swift::Type, swift::Type, swift::constraints::ConstraintLocatorBuilder, bool) + 66
12 swift                    0x000000010594225d llvm::Optional<swift::RequirementMatch> llvm::function_ref<llvm::Optional<swift::RequirementMatch> (swift::Type, swift::Type)>::callback_fn<swift::matchWitness(llvm::DenseMap<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, swift::RequirementEnvironment, llvm::DenseMapInfo<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*> >, llvm::detail::DenseMapPair<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, swift::RequirementEnvironment> >&, swift::ProtocolDecl*, swift::ProtocolConformance*, swift::DeclContext*, swift::ValueDecl*, swift::ValueDecl*)::$_1>(long, swift::Type, swift::Type) + 93
13 swift                    0x00000001059236fa swift::matchWitness(swift::DeclContext*, swift::ValueDecl*, swift::ValueDecl*, llvm::function_ref<std::__1::tuple<llvm::Optional<swift::RequirementMatch>, swift::Type, swift::Type> ()>, llvm::function_ref<llvm::Optional<swift::RequirementMatch> (swift::Type, swift::Type)>, llvm::function_ref<swift::RequirementMatch (bool, llvm::ArrayRef<swift::OptionalAdjustment>)>) + 8778
14 swift                    0x0000000105925233 swift::matchWitness(llvm::DenseMap<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, swift::RequirementEnvironment, llvm::DenseMapInfo<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*> >, llvm::detail::DenseMapPair<std::__1::pair<swift::GenericSignatureImpl const*, swift::ClassDecl const*>, swift::RequirementEnvironment> >&, swift::ProtocolDecl*, swift::ProtocolConformance*, swift::DeclContext*, swift::ValueDecl*, swift::ValueDecl*) + 1187
15 swift                    0x0000000105925d82 swift::WitnessChecker::findBestWitness(swift::ValueDecl*, bool*, swift::NormalProtocolConformance*, llvm::SmallVectorImpl<swift::RequirementMatch>&, unsigned int&, unsigned int&, bool&) + 946
16 swift                    0x0000000105930423 swift::ConformanceChecker::resolveWitnessViaLookup(swift::ValueDecl*) + 643
17 swift                    0x000000010592b305 swift::MultiConformanceChecker::checkIndividualConformance(swift::NormalProtocolConformance*, bool) + 14821
18 swift                    0x00000001059273c3 swift::MultiConformanceChecker::checkAllConformances() + 147
19 swift                    0x0000000105936f77 swift::TypeChecker::checkConformancesInContext(swift::DeclContext*, swift::IterableDeclContext*) + 8295
20 swift                    0x00000001058e1626 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 11702
21 swift                    0x00000001059a6c89 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 953
22 swift                    0x00000001059a99c9 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 953
23 swift                    0x00000001059a6744 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 164
24 swift                    0x0000000104b29c47 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 6439
25 swift                    0x00000001049ebee1 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6849
26 swift                    0x0000000104970a97 main + 1255
27 libdyld.dylib            0x00007fff70c47cc9 start + 1
28 libdyld.dylib            0x000000000000000d start + 18446603338624238405
fish: '/Applications/Xcode-beta.app/Co…' terminated by signal SIGSEGV (Address boundary error)

With Swift 5.3 I can workaround by avoiding polymorphism and changing method signature:

struct X {}
struct Y {}

protocol A {
    static func handle(_ string: String, usingX x: inout X)
    static func handle(_ string: String, usingY y: inout Y)
}

enum A_Imp: A {
    static func handle(_ string: String, usingX x: inout X) {
        // ... 
    }
    static func handle(_ string: String, usingY y: inout Y) {
        // ... 
    }
}
@theblixguy
Copy link
Collaborator

Works fine on master. Could you verify with the latest development snapshot from swift.org?

@typesanitizer
Copy link

To add to Suyash's comment: this does crash on Xcode 12 beta 1 for me, so you won't be able to verify using that.

@jegnux
Copy link
Author

jegnux commented Jun 29, 2020

@theblixguy

I don't know if I did it wrong, but I have this ouput:

❯ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-06-22-a.xctoolchain/usr/bin/swift ~/Downloads/Contents.swift
fish: '/Library/Developer/Toolchains/s…' terminated by signal SIGKILL (Forced quit)

@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
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