@@ -137,6 +137,11 @@ enum class ConstraintKind : char {
137137 // / name, and the type of that member, when referenced as a value, is the
138138 // / second type.
139139 UnresolvedValueMember,
140+ // / The first type conforms to the protocol in which the member requirement
141+ // / resides. Once the conformance is resolved, the value witness will be
142+ // / determined, and the type of that witness, when referenced as a value,
143+ // / will be bound to the second type.
144+ ValueWitness,
140145 // / The first type can be defaulted to the second (which currently
141146 // / cannot be dependent). This is more like a type property than a
142147 // / relational constraint.
@@ -406,11 +411,18 @@ class Constraint final : public llvm::ilist_node<Constraint>,
406411 // / The type of the member.
407412 Type Second;
408413
409- // / If non-null, the name of a member of the first type is that
410- // / being related to the second type.
411- // /
412- // / Used for ValueMember an UnresolvedValueMember constraints.
413- DeclNameRef Name;
414+ union {
415+ // / If non-null, the name of a member of the first type is that
416+ // / being related to the second type.
417+ // /
418+ // / Used for ValueMember an UnresolvedValueMember constraints.
419+ DeclNameRef Name;
420+
421+ // / If non-null, the member being referenced.
422+ // /
423+ // / Used for ValueWitness constraints.
424+ ValueDecl *Ref;
425+ } Member;
414426
415427 // / The DC in which the use appears.
416428 DeclContext *UseDC;
@@ -525,6 +537,12 @@ class Constraint final : public llvm::ilist_node<Constraint>,
525537 FunctionRefKind functionRefKind,
526538 ConstraintLocator *locator);
527539
540+ // / Create a new value witness constraint.
541+ static Constraint *createValueWitness (
542+ ConstraintSystem &cs, ConstraintKind kind, Type first, Type second,
543+ ValueDecl *requirement, DeclContext *useDC,
544+ FunctionRefKind functionRefKind, ConstraintLocator *locator);
545+
528546 // / Create an overload-binding constraint.
529547 static Constraint *createBindOverload (ConstraintSystem &cs, Type type,
530548 OverloadChoice choice,
@@ -672,6 +690,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
672690
673691 case ConstraintKind::ValueMember:
674692 case ConstraintKind::UnresolvedValueMember:
693+ case ConstraintKind::ValueWitness:
675694 case ConstraintKind::PropertyWrapper:
676695 return ConstraintClassification::Member;
677696
@@ -711,6 +730,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
711730
712731 case ConstraintKind::ValueMember:
713732 case ConstraintKind::UnresolvedValueMember:
733+ case ConstraintKind::ValueWitness:
714734 return Member.First ;
715735
716736 case ConstraintKind::SyntacticElement:
@@ -732,6 +752,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
732752
733753 case ConstraintKind::ValueMember:
734754 case ConstraintKind::UnresolvedValueMember:
755+ case ConstraintKind::ValueWitness:
735756 return Member.Second ;
736757
737758 default :
@@ -757,13 +778,20 @@ class Constraint final : public llvm::ilist_node<Constraint>,
757778 DeclNameRef getMember () const {
758779 assert (Kind == ConstraintKind::ValueMember ||
759780 Kind == ConstraintKind::UnresolvedValueMember);
760- return Member.Name ;
781+ return Member.Member .Name ;
782+ }
783+
784+ // / Retrieve the requirement being referenced by a value witness constraint.
785+ ValueDecl *getRequirement () const {
786+ assert (Kind == ConstraintKind::ValueWitness);
787+ return Member.Member .Ref ;
761788 }
762789
763790 // / Determine the kind of function reference we have for a member reference.
764791 FunctionRefKind getFunctionRefKind () const {
765792 if (Kind == ConstraintKind::ValueMember ||
766- Kind == ConstraintKind::UnresolvedValueMember)
793+ Kind == ConstraintKind::UnresolvedValueMember ||
794+ Kind == ConstraintKind::ValueWitness)
767795 return static_cast <FunctionRefKind>(TheFunctionRefKind);
768796
769797 // Conservative answer: drop all of the labels.
@@ -823,7 +851,8 @@ class Constraint final : public llvm::ilist_node<Constraint>,
823851 // / Retrieve the DC in which the member was used.
824852 DeclContext *getMemberUseDC () const {
825853 assert (Kind == ConstraintKind::ValueMember ||
826- Kind == ConstraintKind::UnresolvedValueMember);
854+ Kind == ConstraintKind::UnresolvedValueMember ||
855+ Kind == ConstraintKind::ValueWitness);
827856 return Member.UseDC ;
828857 }
829858
0 commit comments