Skip to content

Commit 7c082c4

Browse files
committed
[ConstraintSystem] NFC: Remove obsolete ValueWitness constraint
1 parent f33640c commit 7c082c4

File tree

5 files changed

+9
-194
lines changed

5 files changed

+9
-194
lines changed

include/swift/Sema/Constraint.h

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ 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,
145140
/// The first type can be defaulted to the second (which currently
146141
/// cannot be dependent). This is more like a type property than a
147142
/// relational constraint.
@@ -409,18 +404,11 @@ class Constraint final : public llvm::ilist_node<Constraint>,
409404
/// The type of the member.
410405
Type Second;
411406

412-
union {
413-
/// If non-null, the name of a member of the first type is that
414-
/// being related to the second type.
415-
///
416-
/// Used for ValueMember an UnresolvedValueMember constraints.
417-
DeclNameRef Name;
418-
419-
/// If non-null, the member being referenced.
420-
///
421-
/// Used for ValueWitness constraints.
422-
ValueDecl *Ref;
423-
} Member;
407+
/// If non-null, the name of a member of the first type is that
408+
/// being related to the second type.
409+
///
410+
/// Used for ValueMember an UnresolvedValueMember constraints.
411+
DeclNameRef Name;
424412

425413
/// The DC in which the use appears.
426414
DeclContext *UseDC;
@@ -535,12 +523,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
535523
FunctionRefKind functionRefKind,
536524
ConstraintLocator *locator);
537525

538-
/// Create a new value witness constraint.
539-
static Constraint *createValueWitness(
540-
ConstraintSystem &cs, ConstraintKind kind, Type first, Type second,
541-
ValueDecl *requirement, DeclContext *useDC,
542-
FunctionRefKind functionRefKind, ConstraintLocator *locator);
543-
544526
/// Create an overload-binding constraint.
545527
static Constraint *createBindOverload(ConstraintSystem &cs, Type type,
546528
OverloadChoice choice,
@@ -688,7 +670,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
688670

689671
case ConstraintKind::ValueMember:
690672
case ConstraintKind::UnresolvedValueMember:
691-
case ConstraintKind::ValueWitness:
692673
case ConstraintKind::PropertyWrapper:
693674
return ConstraintClassification::Member;
694675

@@ -728,7 +709,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
728709

729710
case ConstraintKind::ValueMember:
730711
case ConstraintKind::UnresolvedValueMember:
731-
case ConstraintKind::ValueWitness:
732712
return Member.First;
733713

734714
case ConstraintKind::SyntacticElement:
@@ -750,7 +730,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
750730

751731
case ConstraintKind::ValueMember:
752732
case ConstraintKind::UnresolvedValueMember:
753-
case ConstraintKind::ValueWitness:
754733
return Member.Second;
755734

756735
default:
@@ -776,20 +755,13 @@ class Constraint final : public llvm::ilist_node<Constraint>,
776755
DeclNameRef getMember() const {
777756
assert(Kind == ConstraintKind::ValueMember ||
778757
Kind == ConstraintKind::UnresolvedValueMember);
779-
return Member.Member.Name;
780-
}
781-
782-
/// Retrieve the requirement being referenced by a value witness constraint.
783-
ValueDecl *getRequirement() const {
784-
assert(Kind == ConstraintKind::ValueWitness);
785-
return Member.Member.Ref;
758+
return Member.Name;
786759
}
787760

788761
/// Determine the kind of function reference we have for a member reference.
789762
FunctionRefKind getFunctionRefKind() const {
790763
if (Kind == ConstraintKind::ValueMember ||
791-
Kind == ConstraintKind::UnresolvedValueMember ||
792-
Kind == ConstraintKind::ValueWitness)
764+
Kind == ConstraintKind::UnresolvedValueMember)
793765
return static_cast<FunctionRefKind>(TheFunctionRefKind);
794766

795767
// Conservative answer: drop all of the labels.
@@ -849,8 +821,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
849821
/// Retrieve the DC in which the member was used.
850822
DeclContext *getMemberUseDC() const {
851823
assert(Kind == ConstraintKind::ValueMember ||
852-
Kind == ConstraintKind::UnresolvedValueMember ||
853-
Kind == ConstraintKind::ValueWitness);
824+
Kind == ConstraintKind::UnresolvedValueMember);
854825
return Member.UseDC;
855826
}
856827

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,26 +4050,6 @@ class ConstraintSystem {
40504050
}
40514051
}
40524052

4053-
/// Add a value witness constraint to the constraint system.
4054-
void addValueWitnessConstraint(
4055-
Type baseTy, ValueDecl *requirement, Type memberTy, DeclContext *useDC,
4056-
FunctionRefKind functionRefKind, ConstraintLocatorBuilder locator) {
4057-
assert(baseTy);
4058-
assert(memberTy);
4059-
assert(requirement);
4060-
assert(useDC);
4061-
switch (simplifyValueWitnessConstraint(
4062-
ConstraintKind::ValueWitness, baseTy, requirement, memberTy, useDC,
4063-
functionRefKind, TMF_GenerateConstraints, locator)) {
4064-
case SolutionKind::Unsolved:
4065-
llvm_unreachable("Unsolved result when generating constraints!");
4066-
4067-
case SolutionKind::Solved:
4068-
case SolutionKind::Error:
4069-
break;
4070-
}
4071-
}
4072-
40734053
/// Add an explicit conversion constraint (e.g., \c 'x as T').
40744054
///
40754055
/// \param fromType The type of the expression being converted.

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,6 @@ void PotentialBindings::infer(Constraint *constraint) {
14671467

14681468
case ConstraintKind::ValueMember:
14691469
case ConstraintKind::UnresolvedValueMember:
1470-
case ConstraintKind::ValueWitness:
14711470
case ConstraintKind::PropertyWrapper: {
14721471
// If current type variable represents a member type of some reference,
14731472
// it would be bound once member is resolved either to a actual member

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,6 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
21822182
case ConstraintKind::SelfObjectOfProtocol:
21832183
case ConstraintKind::UnresolvedValueMember:
21842184
case ConstraintKind::ValueMember:
2185-
case ConstraintKind::ValueWitness:
21862185
case ConstraintKind::BridgingConversion:
21872186
case ConstraintKind::OneWayEqual:
21882187
case ConstraintKind::OneWayBindParam:
@@ -2346,7 +2345,6 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
23462345
case ConstraintKind::SelfObjectOfProtocol:
23472346
case ConstraintKind::UnresolvedValueMember:
23482347
case ConstraintKind::ValueMember:
2349-
case ConstraintKind::ValueWitness:
23502348
case ConstraintKind::OneWayEqual:
23512349
case ConstraintKind::OneWayBindParam:
23522350
case ConstraintKind::DefaultClosureType:
@@ -2793,7 +2791,6 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
27932791
case ConstraintKind::SelfObjectOfProtocol:
27942792
case ConstraintKind::UnresolvedValueMember:
27952793
case ConstraintKind::ValueMember:
2796-
case ConstraintKind::ValueWitness:
27972794
case ConstraintKind::BridgingConversion:
27982795
case ConstraintKind::OneWayEqual:
27992796
case ConstraintKind::OneWayBindParam:
@@ -6031,7 +6028,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
60316028
case ConstraintKind::SelfObjectOfProtocol:
60326029
case ConstraintKind::UnresolvedValueMember:
60336030
case ConstraintKind::ValueMember:
6034-
case ConstraintKind::ValueWitness:
60356031
case ConstraintKind::OneWayEqual:
60366032
case ConstraintKind::OneWayBindParam:
60376033
case ConstraintKind::DefaultClosureType:
@@ -9125,8 +9121,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
91259121
markMemberTypeAsPotentialHole(memberTy);
91269122
return SolutionKind::Solved;
91279123
}
9128-
} else if ((kind == ConstraintKind::ValueMember ||
9129-
kind == ConstraintKind::ValueWitness) &&
9124+
} else if (kind == ConstraintKind::ValueMember &&
91309125
baseObjTy->getMetatypeInstanceType()->isPlaceholder()) {
91319126
// If base type is a "hole" there is no reason to record any
91329127
// more "member not found" fixes for chained member references.
@@ -9548,67 +9543,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
95489543
return SolutionKind::Error;
95499544
}
95509545

9551-
ConstraintSystem::SolutionKind
9552-
ConstraintSystem::simplifyValueWitnessConstraint(
9553-
ConstraintKind kind, Type baseType, ValueDecl *requirement, Type memberType,
9554-
DeclContext *useDC, FunctionRefKind functionRefKind,
9555-
TypeMatchOptions flags, ConstraintLocatorBuilder locator) {
9556-
// We'd need to record original base type because it might be a type
9557-
// variable representing another missing member.
9558-
auto origBaseType = baseType;
9559-
9560-
auto formUnsolved = [&] {
9561-
// If requested, generate a constraint.
9562-
if (flags.contains(TMF_GenerateConstraints)) {
9563-
auto *witnessConstraint = Constraint::createValueWitness(
9564-
*this, kind, origBaseType, memberType, requirement, useDC,
9565-
functionRefKind, getConstraintLocator(locator));
9566-
9567-
addUnsolvedConstraint(witnessConstraint);
9568-
return SolutionKind::Solved;
9569-
}
9570-
9571-
return SolutionKind::Unsolved;
9572-
};
9573-
9574-
// Resolve the base type, if we can. If we can't resolve the base type,
9575-
// then we can't solve this constraint.
9576-
Type baseObjectType = getFixedTypeRecursive(
9577-
baseType, flags, /*wantRValue=*/true);
9578-
if (baseObjectType->isTypeVariableOrMember()) {
9579-
return formUnsolved();
9580-
}
9581-
9582-
// Check conformance to the protocol. If it doesn't conform, this constraint
9583-
// fails. Don't attempt to fix it.
9584-
// FIXME: Look in the constraint system to see if we've resolved the
9585-
// conformance already?
9586-
auto proto = requirement->getDeclContext()->getSelfProtocolDecl();
9587-
assert(proto && "Value witness constraint for a non-requirement");
9588-
auto conformance = useDC->getParentModule()->lookupConformance(
9589-
baseObjectType, proto);
9590-
if (!conformance) {
9591-
// The conformance failed, so mark the member type as a "hole". We cannot
9592-
// do anything further here.
9593-
if (!shouldAttemptFixes())
9594-
return SolutionKind::Error;
9595-
9596-
recordAnyTypeVarAsPotentialHole(memberType);
9597-
9598-
return SolutionKind::Solved;
9599-
}
9600-
9601-
// Reference the requirement.
9602-
Type resolvedBaseType = simplifyType(baseType, flags);
9603-
if (resolvedBaseType->isTypeVariableOrMember())
9604-
return formUnsolved();
9605-
9606-
auto choice = OverloadChoice(resolvedBaseType, requirement, functionRefKind);
9607-
resolveOverload(getConstraintLocator(locator), memberType, choice,
9608-
useDC);
9609-
return SolutionKind::Solved;
9610-
}
9611-
96129546
ConstraintSystem::SolutionKind ConstraintSystem::simplifyDefaultableConstraint(
96139547
Type first, Type second, TypeMatchOptions flags,
96149548
ConstraintLocatorBuilder locator) {
@@ -13221,7 +13155,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1322113155

1322213156
case ConstraintKind::ValueMember:
1322313157
case ConstraintKind::UnresolvedValueMember:
13224-
case ConstraintKind::ValueWitness:
1322513158
case ConstraintKind::BindOverload:
1322613159
case ConstraintKind::Disjunction:
1322713160
case ConstraintKind::Conjunction:
@@ -13712,16 +13645,6 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1371213645
/*outerAlternatives=*/{},
1371313646
/*flags*/ None, constraint.getLocator());
1371413647

13715-
case ConstraintKind::ValueWitness:
13716-
return simplifyValueWitnessConstraint(constraint.getKind(),
13717-
constraint.getFirstType(),
13718-
constraint.getRequirement(),
13719-
constraint.getSecondType(),
13720-
constraint.getMemberUseDC(),
13721-
constraint.getFunctionRefKind(),
13722-
/*flags*/ None,
13723-
constraint.getLocator());
13724-
1372513648
case ConstraintKind::Defaultable:
1372613649
return simplifyDefaultableConstraint(constraint.getFirstType(),
1372713650
constraint.getSecondType(),

lib/Sema/Constraint.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
9090

9191
case ConstraintKind::ValueMember:
9292
case ConstraintKind::UnresolvedValueMember:
93-
case ConstraintKind::ValueWitness:
9493
llvm_unreachable("Wrong constructor for member constraint");
9594

9695
case ConstraintKind::Defaultable:
@@ -150,7 +149,6 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second, Type Third,
150149
case ConstraintKind::ApplicableFunction:
151150
case ConstraintKind::DynamicCallableApplicableFunction:
152151
case ConstraintKind::ValueMember:
153-
case ConstraintKind::ValueWitness:
154152
case ConstraintKind::UnresolvedValueMember:
155153
case ConstraintKind::Defaultable:
156154
case ConstraintKind::BindOverload:
@@ -197,28 +195,6 @@ Constraint::Constraint(ConstraintKind kind, Type first, Type second,
197195
std::copy(typeVars.begin(), typeVars.end(), getTypeVariablesBuffer().begin());
198196
}
199197

200-
Constraint::Constraint(ConstraintKind kind, Type first, Type second,
201-
ValueDecl *requirement, DeclContext *useDC,
202-
FunctionRefKind functionRefKind,
203-
ConstraintLocator *locator,
204-
SmallPtrSetImpl<TypeVariableType *> &typeVars)
205-
: Kind(kind), HasRestriction(false), IsActive(false), IsDisabled(false),
206-
IsDisabledForPerformance(false), RememberChoice(false), IsFavored(false),
207-
IsIsolated(false), NumTypeVariables(typeVars.size()), Locator(locator) {
208-
Member.First = first;
209-
Member.Second = second;
210-
Member.Member.Ref = requirement;
211-
Member.UseDC = useDC;
212-
TheFunctionRefKind = static_cast<unsigned>(functionRefKind);
213-
214-
assert(kind == ConstraintKind::ValueWitness);
215-
assert(getFunctionRefKind() == functionRefKind);
216-
assert(requirement && "Value witness constraint has no requirement");
217-
assert(useDC && "Member constraint has no use DC");
218-
219-
std::copy(typeVars.begin(), typeVars.end(), getTypeVariablesBuffer().begin());
220-
}
221-
222198
Constraint::Constraint(Type type, OverloadChoice choice, DeclContext *useDC,
223199
ConstraintFix *fix, ConstraintLocator *locator,
224200
SmallPtrSetImpl<TypeVariableType *> &typeVars)
@@ -324,11 +300,6 @@ Constraint *Constraint::clone(ConstraintSystem &cs) const {
324300
getMember(), getMemberUseDC(), getFunctionRefKind(),
325301
getLocator());
326302

327-
case ConstraintKind::ValueWitness:
328-
return createValueWitness(
329-
cs, getKind(), getFirstType(), getSecondType(), getRequirement(),
330-
getMemberUseDC(), getFunctionRefKind(), getLocator());
331-
332303
case ConstraintKind::Disjunction:
333304
return createDisjunction(
334305
cs, getNestedConstraints(), getLocator(),
@@ -509,14 +480,6 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
509480
Out << "[(implicit) ." << getMember() << ": value] == ";
510481
break;
511482

512-
case ConstraintKind::ValueWitness: {
513-
auto requirement = getRequirement();
514-
auto selfNominal = requirement->getDeclContext()->getSelfNominalTypeDecl();
515-
Out << "[." << selfNominal->getName() << "::" << requirement->getName()
516-
<< ": witness] == ";
517-
break;
518-
}
519-
520483
case ConstraintKind::Defaultable:
521484
Out << " can default to ";
522485
break;
@@ -672,7 +635,6 @@ gatherReferencedTypeVars(Constraint *constraint,
672635
case ConstraintKind::Subtype:
673636
case ConstraintKind::UnresolvedValueMember:
674637
case ConstraintKind::ValueMember:
675-
case ConstraintKind::ValueWitness:
676638
case ConstraintKind::DynamicTypeOf:
677639
case ConstraintKind::EscapableFunctionOf:
678640
case ConstraintKind::OpenedExistentialOf:
@@ -818,26 +780,6 @@ Constraint *Constraint::createMember(ConstraintSystem &cs, ConstraintKind kind,
818780
functionRefKind, locator, typeVars);
819781
}
820782

821-
Constraint *Constraint::createValueWitness(
822-
ConstraintSystem &cs, ConstraintKind kind, Type first, Type second,
823-
ValueDecl *requirement, DeclContext *useDC,
824-
FunctionRefKind functionRefKind, ConstraintLocator *locator) {
825-
assert(kind == ConstraintKind::ValueWitness);
826-
827-
// Collect type variables.
828-
SmallPtrSet<TypeVariableType *, 4> typeVars;
829-
if (first->hasTypeVariable())
830-
first->getTypeVariables(typeVars);
831-
if (second->hasTypeVariable())
832-
second->getTypeVariables(typeVars);
833-
834-
// Create the constraint.
835-
unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size());
836-
void *mem = cs.getAllocator().Allocate(size, alignof(Constraint));
837-
return new (mem) Constraint(kind, first, second, requirement, useDC,
838-
functionRefKind, locator, typeVars);
839-
}
840-
841783
Constraint *Constraint::createBindOverload(ConstraintSystem &cs, Type type,
842784
OverloadChoice choice,
843785
DeclContext *useDC,

0 commit comments

Comments
 (0)