mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Inference of type witnesses for associated types was previously implemented as part of value witness matching in the constraint solver. This led to a number of serious problems, including: - Recursion problems with the solver hunting for a type witness, which triggers more attemts to match value witnesses... - Arbitrarily crummy attempts to break the recursion causing type-check failures in fun places. - Ordering dependencies abound: different results depending on which value witnesses were satisfied first, failures because of the order in which we attempted to infer type witnesses, etc. This new implementation of type witness inference uses a separate pass that occurs whenever we're looking for any type witness, and solves all of the type witnesses within a given conformance simultaneously. We still look at potential value witnesses to infer type witnesses, but we match them structurally, without invoking the constraint solver. There are a few caveats to this implementation: * We're not currently able to infer type witnesses from value witnesses that are global operators, so some tricks involving global operators (*cough* ~> *cough*) might require some manually-specified type witnesses. Note that the standard library doesn't include any such cases. * Yes, it's another kind of solver. At simple one, fortunately. On the other hand, this implementation should be a big step forward: * It's far more predictable, order-invariant, and non-recursive. * The diagnostics for failures to infer type witnesses have improved. Fixes rdar://problem/20598513. Swift SVN r27616
48 lines
2.1 KiB
Swift
48 lines
2.1 KiB
Swift
// ---------------------------------------------------------------------------
|
|
// Multiple explicit conformances to the same protocol
|
|
// ---------------------------------------------------------------------------
|
|
|
|
extension MFExplicit1 : P1 { }
|
|
|
|
struct MFExplicit2 : P1 { } // expected-note{{'MFExplicit2' declares conformance to protocol 'P1' here}}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Multiple implicit conformances, with no ambiguities
|
|
// ---------------------------------------------------------------------------
|
|
|
|
struct MFMultipleImplicit1 : P2a { }
|
|
|
|
struct MFMultipleImplicit3 : P4 { }
|
|
|
|
struct MFMultipleImplicit4 : P4 { }
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Multiple implicit conformances, with ambiguities
|
|
// ---------------------------------------------------------------------------
|
|
struct MFBadMultipleImplicit1 : P2a { } // expected-note{{'MFBadMultipleImplicit1' implicitly conforms to protocol 'P1' (via conformance to 'P2a') here}}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Explicit conformances conflicting with inherited conformances
|
|
// ---------------------------------------------------------------------------
|
|
|
|
class MFExplicitSub1 : ImplicitSuper1 { } // expected-note{{'MFExplicitSub1' inherits conformance to protocol 'P1' from superclass here}}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Suppression of synthesized conformances
|
|
// ---------------------------------------------------------------------------
|
|
extension MFSynthesizedClass1 : AnyObject { }
|
|
|
|
class MFSynthesizedClass2 { }
|
|
|
|
class MFSynthesizedClass3 : AnyObjectRefinement { }
|
|
|
|
class MFSynthesizedSubClass2 : MFSynthesizedClass2 { } // expected-note{{'MFSynthesizedSubClass2' inherits conformance to protocol 'AnyObject' from superclass here}}
|
|
|
|
class MFSynthesizedSubClass3 : MFSynthesizedClass1 { }
|
|
|
|
extension MFSynthesizedSubClass4 : AnyObjectRefinement { }
|
|
|
|
enum MFSynthesizedEnum1 : Int { case a }
|
|
extension MFSynthesizedEnum2 : RawRepresentable { }
|
|
|