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-13884] Swift Compiler Issue #56282

Closed
swift-ci opened this issue Nov 21, 2020 · 10 comments
Closed

[SR-13884] Swift Compiler Issue #56282

swift-ci opened this issue Nov 21, 2020 · 10 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13884
Radar rdar://problem/71677712
Original Reporter Vithanco (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Toolchain from 9th Nov.

Xcode 12.2

macOS 11.0.1

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

md5: 4f22d84bca359abf17972ab5966b810b

duplicates:

  • SR-10033 GSB crash: All constraints were self-derived

Issue Description:

1. Apple Swift version 5.3-dev (LLVM 618cb95, Swift 4aa1ef3)

2. While evaluating request TypeCheckSourceFileRequest(source_file "/Users/klauskneupner/Documents/xcode/vithanco/VCore/TempCore/TempGraph.swift")

3. While type-checking 'TempEdge' (at /Users/klauskneupner/Documents/xcode/vithanco/VCore/TempCore/TempGraph.swift:347:8)

4. While type-checking protocol conformance to 'VEdge' (at /Users/klauskneupner/Documents/xcode/vithanco/VCore/Sources/VCore/VEdge.swift:60:8) for type 'TempEdge' (declared at [/Users/klauskneupner/Documents/xcode/vithanco/VCore/TempCore/TempGraph.swift:347:8 - line:437:1] RangeText="class TempEdge : VEdge, CleanUpNeeded {

public static var entityName: String = "TempEdge"

public var from: TempNode {

    willSet {

        from.outgoing.remove(self)

    }

    didSet {

        from.outgoing.insert(self)

    }

}



public var graph: TempGraph? {

    willSet {

        if let g = graph {

            g.vEdges.removeObject(self)

        }

    }

    didSet {

        graph?.vEdges.append(self)

    }

}



public var to: TempNode {

    willSet {

        from.incoming.remove(self)

    }

    didSet {

        from.incoming.insert(self)

    }

}



public func set(from: TempNode, to: TempNode){

    self.from = from

    self.to = to

}



public var type: EdgeType = .directed



public var created: Date? = nil

public var changed: Date? = nil



public var usedForRanking: Bool = true



public var edgeType: EdgeType = .directed



public var renderableText =  FlexibleSizeText()



public var name: String {

    return "TempEdge(self.uid)"

}



public typealias N = TempNode



public var uid: Int64 = nextID()



public var itemText: String = "TempEdge"



public var annotationText: String = "TempEdge"



public var drawingOrder: Int64 = nextID()



public var straighteningWeight: Int = 0



public var probability: Percent = 1.0



public func deleteYourself() {

}



public static func == (lhs: TempEdge, rhs: TempEdge) -\> Bool {

    return lhs === rhs

}



init(from: N, to: N) {

    self.from = from

    self.to = to

}

public var isValid: Bool {

    return true

}

public var cldIsDelayed: Bool = false



deinit {

    prepareDeinit()

}



public func prepareDeinit() {

    graph = nil

}

")

5. While evaluating request AbstractGenericSignatureRequest(NULL, {τ_0_0}, {τ_0_0 : TempEdge, τ_0_0 : VEdge})

0 swift-frontend 0x0000000105bacb45 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37

1 swift-frontend 0x0000000105babda5 llvm::sys::RunSignalHandlers() + 85

2 swift-frontend 0x0000000105bad116 SignalHandler(int) + 262

3 libsystem_platform.dylib 0x00007fff20378d7d _sigtramp + 29

4 swift-frontend 0x0000000108753458 cmark_strbuf__initbuf + 198755

5 libsystem_c.dylib 0x00007fff20287720 abort + 120

6 libsystem_c.dylib 0x00007fff202869d6 err + 0

7 swift-frontend 0x000000010610b5b3 bool (anonymous namespace)::removeSelfDerived<swift::Type>(swift::GenericSignatureBuilder&, std::_1::vector<swift::GenericSignatureBuilder::Constraint<swift::Type>, std::_1::allocator<swift::GenericSignatureBuilder::Constraint<swift::Type> > >&, swift::ProtocolDecl*, bool, bool) (.cold.1) + 35

8 swift-frontend 0x000000010265a9c8 bool (anonymous namespace)::removeSelfDerived<swift::Type>(swift::GenericSignatureBuilder&, std::_1::vector<swift::GenericSignatureBuilder::Constraint<swift::Type>, std::_1::allocator<swift::GenericSignatureBuilder::Constraint<swift::Type> > >&, swift::ProtocolDecl*, bool, bool) + 1224

9 swift-frontend 0x000000010265abec ZN5swift23GenericSignatureBuilder19checkConstraintListINS_4TypeES2_EENS0_10ConstraintIT_EENS_12ArrayRefViewIS2_PNS_20GenericTypeParamTypeEL_ZNS_16staticCastHelperIS7_EEPS4_RKS2_ELb1EEERNSt3_16vectorIS5_NSE_9allocatorIS5_EEEEN4llvm12function_refIFbRKS5_EEENSL_IFNS0_18ConstraintRelationESN_EEENSK_8OptionalINS_4DiagIJjS2_T0_SV_EEEEENSU_IJS2_SV_EEENSU_IJjS2_SV_EEENSL_IFSV_RKS4_EEEb + 92

10 swift-frontend 0x000000010265498c swift::GenericSignatureBuilder::checkConcreteTypeConstraints(swift::ArrayRefView<swift::Type, swift::GenericTypeParamType*, swift::GenericTypeParamType* swift::staticCastHelper<swift::GenericTypeParamType>(swift::Type const&), true>, swift::GenericSignatureBuilder::EquivalenceClass*) + 332

11 swift-frontend 0x00000001026531f1 swift::GenericSignatureBuilder::finalize(swift::SourceLoc, swift::ArrayRefView<swift::Type, swift::GenericTypeParamType*, swift::GenericTypeParamType* swift::staticCastHelper<swift::GenericTypeParamType>(swift::Type const&), true>, bool) + 513

12 swift-frontend 0x000000010265c6ca swift::GenericSignatureBuilder::computeGenericSignature(swift::SourceLoc, bool, bool) && + 42

13 swift-frontend 0x000000010265d862 swift::AbstractGenericSignatureRequest::evaluate(swift::Evaluator&, swift::GenericSignatureImpl const*, llvm::SmallVector<swift::GenericTypeParamType*, 2u>, llvm::SmallVector<swift::Requirement, 2u>) const + 802

14 swift-frontend 0x00000001022f2808 swift::GenericSignature swift::SimpleRequest<swift::AbstractGenericSignatureRequest, swift::GenericSignature (swift::GenericSignatureImpl const*, llvm::SmallVector<swift::GenericTypeParamType*, 2u>, llvm::SmallVector<swift::Requirement, 2u>), (swift::RequestFlags)2>::callDerived<0ul, 1ul, 2ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul, 1ul, 2ul>) const + 120

15 swift-frontend 0x00000001024e0072 llvm::Expected<swift::AbstractGenericSignatureRequest::OutputType> swift::Evaluator::getResultUncached<swift::AbstractGenericSignatureRequest>(swift::AbstractGenericSignatureRequest const&) + 338

16 swift-frontend 0x00000001024dfc95 llvm::Expected<swift::AbstractGenericSignatureRequest::OutputType> swift::Evaluator::getResultCached<swift::AbstractGenericSignatureRequest, (void*)0>(swift::AbstractGenericSignatureRequest const&) + 213

17 swift-frontend 0x00000001024cb24f swift::AbstractGenericSignatureRequest::OutputType swift::evaluateOrDefault<swift::AbstractGenericSignatureRequest>(swift::Evaluator&, swift::AbstractGenericSignatureRequest, swift::AbstractGenericSignatureRequest::OutputType) + 63

18 swift-frontend 0x00000001026dd35e swift::RequirementEnvironment::RequirementEnvironment(swift::DeclContext*, swift::GenericSignature, swift::ProtocolDecl*, swift::ClassDecl*, swift::ProtocolConformance*) + 2558

19 swift-frontend 0x00000001022b18c7 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*) + 471

20 swift-frontend 0x00000001022b252e swift::WitnessChecker::findBestWitness(swift::ValueDecl*, bool*, swift::NormalProtocolConformance*, llvm::SmallVectorImpl<swift::RequirementMatch>&, unsigned int&, unsigned int&, bool&) + 638

21 swift-frontend 0x00000001022bc5d5 swift::ConformanceChecker::resolveWitnessViaLookup(swift::ValueDecl*) + 693

22 swift-frontend 0x00000001022befbb swift::ConformanceChecker::resolveValueWitnesses() + 363

23 swift-frontend 0x00000001022b7a75 swift::ConformanceChecker::checkConformance(swift::MissingWitnessDiagnosisKind) + 245

24 swift-frontend 0x00000001022b5931 swift::MultiConformanceChecker::checkIndividualConformance(swift::NormalProtocolConformance*, bool) + 8001

25 swift-frontend 0x00000001022b3775 swift::MultiConformanceChecker::checkAllConformances() + 149

26 swift-frontend 0x00000001022c1894 swift::TypeChecker::checkConformancesInContext(swift::IterableDeclContext*) + 5172

27 swift-frontend 0x0000000102280ba0 (anonymous namespace)::DeclChecker::visitClassDecl(swift::ClassDecl*) + 3424

28 swift-frontend 0x000000010227c96f (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 159

29 swift-frontend 0x000000010227c8b2 swift::TypeChecker::typeCheckDecl(swift::Decl*) + 130

30 swift-frontend 0x0000000102329ac8 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 184

31 swift-frontend 0x000000010232ab61 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 369

32 swift-frontend 0x000000010232a8c2 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 66

33 swift-frontend 0x000000010232a80e llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::operator()<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 110

34 swift-frontend 0x000000010232990e swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 46

35 swift-frontend 0x00000001015c440a swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<void (swift::SourceFile&)>) + 90

36 swift-frontend 0x00000001015c42fa swift::CompilerInstance::performSema() + 74

37 swift-frontend 0x00000001014a8f5e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4718

38 swift-frontend 0x000000010143f692 main + 866

39 libdyld.dylib 0x00007fff2034f631 start + 1

error: Abort trap: 6 (in target 'VCore' from project 'VCore')

@swift-ci
Copy link
Collaborator Author

Comment by Klaus Kneupner (JIRA)

Just tried the same with the snapshot from the 17th. Same issue.

@swift-ci
Copy link
Collaborator Author

Comment by Klaus Kneupner (JIRA)

This part compiles with the standard XCode 12.2 toolchain, but then I get an illegal instruction:4 problem later on. There might be a relationship between both issues.

I make heavy use of PAT (protocols with associated types) in my code.

@typesanitizer
Copy link

Are you able to reduce the code which causes the compiler to crash? That would help in reproducing the bug. Also, does the snapshot from the 17th report any assertion failure?

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Klaus Kneupner (JIRA)

This code will reproduce the problem:

import Foundation

public protocol VBase : class, DeleteYourself{

}

public protocol HasDrawingOrder {

}

public protocol VDrawableBase : class, VBase, Hashable, HasDrawingOrder {

}

public extension VDrawableBase {

}

public protocol VNodeType: VDrawableBase {

**associatedtype** N: VNode

**var** nodes: \[N\] {**get** **set**}

}

public protocol VNode: VDrawableBase {

**associatedtype** C: VCluster

**associatedtype** E: VEdge

}

public protocol VEdge: VDrawableBase {

**associatedtype** N: VNode **where** N.E == Self

**typealias** NT = N.NT

**typealias** C = N.C

**typealias** D = NT.D

**var** from: N {**get**}

**var** to: N {**get**}

**func** set(from: N, to: N)



**func** changeDirection()

}

public extension VEdge {

**func** changeDirection() {

    **\_** = set(from: to, to: from)

}

}

public protocol VCluster: VDrawableBase {

**associatedtype** N: VNode

**associatedtype** NT :VNodeType

**typealias** C = Self

}

public protocol VDomain: class, VBase, Hashable {

**associatedtype** NT: VNodeType

}

public protocol VGraph: class, VBase, SupportCombinedActivities where C.NT == D.NT, E.D == D, E.C == C{

**typealias** N = NT.N

**typealias** C = N.C

**typealias** E = N.E

**associatedtype** D: VDomain

**typealias** NT = D.NT

}

public final class TempNode : VNode, CleanUpNeeded {

**public** **typealias** C = TempCluster

**public** **typealias** D = TempDomain

**public** **typealias** E = TempEdge

**public** **typealias** G = TempGraph

}

public class TempEdge : VEdge, CleanUpNeeded {

**public** **var** from: TempNode {

    **willSet** {

        from.outgoing.remove(**self**)

    }

    **didSet** {

        from.outgoing.insert(**self**)

    }

}

}

public class TempGraph : VGraph {

**public** **typealias** E = TempEdge

**public** **typealias** G = TempGraph

**public** **var** allDomains = Set\<TempDomain\>()

}

@artemcm
Copy link
Contributor

artemcm commented Dec 3, 2020

Vithanco (JIRA User), could you please try to reduce this code to a standalone program to help us in reproducing this issue? The snippet in the above comment does not compile even after I tried removing extraneous characters, as it seems to be missing declarations of a few types it uses.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Dec 3, 2020

Comment by Klaus Kneupner (JIRA)

Hi @artemcm,

thanks for reaching out. I added my "test project".

From my side, this is not a test to compile without errors. The test is to compile without crashing.

The code above leads to a compiler crash: "error: Abort trap: 6". Indeed, I deleted several types and plenty of lines that were not relevant to crash the compiler. Btw, the problem doesn't occur in the official release - only in the toolchain snapshots (tested on versions from 9th, 17th and 30th Nov). I assume that an assertion or similar is triggered. I added my "test project".

Does this help?

Thanks again!
Klaus

PS: Fun Fact: my code triggers a different compiler crash in a module further down the line - with the official release, an illegal instruction: 4. I cannot get that far with the toolchain snapshot. There is a good chance that these two problems are connected.

ReproduceTrap6.zip

@swift-ci
Copy link
Collaborator Author

Comment by Klaus Kneupner (JIRA)

Hi @artemcm, were you able to reproduce the problem?

@slavapestov
Copy link
Member

I've reduced this further:

public protocol VNode {
    associatedtype E: VEdge
}

public protocol VEdge {
    associatedtype N: VNode where N.E == Self
}

public class TempNode : VNode {
    public typealias E = TempEdge
}

public class TempEdge : VEdge {
    public typealias N = TempNode
}

public func foo<T : VEdge & TempEdge>(_: T) {}
Assertion failed: ((!constraints.empty() || allCanBeSelfDerived) && "All constraints were self-derived!"), function removeSelfDerived, file /Users/spestov/src/swift/lib/AST/GenericSignatureBuilder.cpp, line 5782.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Users/spestov/src/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swift-frontend -frontend -c -primary-file code.swift -target x86_64-apple-macos11b -enable-objc-interop -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -color-diagnostics -target-sdk-version 10.15.6 -module-name code -o /var/folders/tt/_9_c2h053h7b0wspkfyskxrw0000gn/T/code-bf5223.o 
1.  Swift version 5.4-dev (LLVM e2976fe639d1f50, Swift 8052394932dd361)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "code.swift")
3.  While type-checking 'foo(_:)' (at code.swift:17:8)
4.  While evaluating request InterfaceTypeRequest(code.(file).foo@code.swift:17:13)
5.  While evaluating request GenericSignatureRequest(code.(file).foo@code.swift:17:13)
6.  While evaluating request InferredGenericSignatureRequest(code.code, NULL, code.(file).foo@code.swift:17:13, {}, {(T, T)}, 0)
0  swift-frontend           0x000000010adb7a25 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift-frontend           0x000000010adb6cf5 llvm::sys::RunSignalHandlers() + 85
2  swift-frontend           0x000000010adb7ff6 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff70e755fd _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338621954592
5  libsystem_c.dylib        0x00007fff70d4b808 abort + 120
6  libsystem_c.dylib        0x00007fff70d4aac6 err + 0
7  swift-frontend           0x000000010b354973 bool (anonymous namespace)::removeSelfDerived<swift::Type>(swift::GenericSignatureBuilder&, std::__1::vector<swift::GenericSignatureBuilder::Constraint<swift::Type>, std::__1::allocator<swift::GenericSignatureBuilder::Constraint<swift::Type> > >&, swift::ProtocolDecl*, bool, bool) (.cold.1) + 35
8  swift-frontend           0x00000001078f2ee8 bool (anonymous namespace)::removeSelfDerived<swift::Type>(swift::GenericSignatureBuilder&, std::__1::vector<swift::GenericSignatureBuilder::Constraint<swift::Type>, std::__1::allocator<swift::GenericSignatureBuilder::Constraint<swift::Type> > >&, swift::ProtocolDecl*, bool, bool) + 1224

@slavapestov
Copy link
Member

Even shorter reproducer:

public protocol Q {
  associatedtype A: Q where A == Self
}
public class C : Q {
  public typealias A = C
}
public func foo3<T : Q & C>(_: T) {}

We infer that T == C via the same-type constraint T.A == T and the type alias A = C, but we don't have a proper requirement source for T == C so we crash.

@slavapestov
Copy link
Member

#36746

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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.
Projects
None yet
Development

No branches or pull requests

4 participants