Skip to content

Commit ef0523f

Browse files
committed
[ConstraintSystem] NFC: Remove obsolete ValueWitness constraint
1 parent b7860ea commit ef0523f

File tree

5 files changed

+9
-194
lines changed

5 files changed

+9
-194
lines changed

Diff for: include/swift/Sema/Constraint.h

+8-37
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.
@@ -411,18 +406,11 @@ class Constraint final : public llvm::ilist_node<Constraint>,
411406
/// The type of the member.
412407
Type Second;
413408

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;
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;
426414

427415
/// The DC in which the use appears.
428416
DeclContext *UseDC;
@@ -537,12 +525,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
537525
FunctionRefKind functionRefKind,
538526
ConstraintLocator *locator);
539527

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-
546528
/// Create an overload-binding constraint.
547529
static Constraint *createBindOverload(ConstraintSystem &cs, Type type,
548530
OverloadChoice choice,
@@ -690,7 +672,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
690672

691673
case ConstraintKind::ValueMember:
692674
case ConstraintKind::UnresolvedValueMember:
693-
case ConstraintKind::ValueWitness:
694675
case ConstraintKind::PropertyWrapper:
695676
return ConstraintClassification::Member;
696677

@@ -730,7 +711,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
730711

731712
case ConstraintKind::ValueMember:
732713
case ConstraintKind::UnresolvedValueMember:
733-
case ConstraintKind::ValueWitness:
734714
return Member.First;
735715

736716
case ConstraintKind::SyntacticElement:
@@ -752,7 +732,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
752732

753733
case ConstraintKind::ValueMember:
754734
case ConstraintKind::UnresolvedValueMember:
755-
case ConstraintKind::ValueWitness:
756735
return Member.Second;
757736

758737
default:
@@ -778,20 +757,13 @@ class Constraint final : public llvm::ilist_node<Constraint>,
778757
DeclNameRef getMember() const {
779758
assert(Kind == ConstraintKind::ValueMember ||
780759
Kind == ConstraintKind::UnresolvedValueMember);
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;
760+
return Member.Name;
788761
}
789762

790763
/// Determine the kind of function reference we have for a member reference.
791764
FunctionRefKind getFunctionRefKind() const {
792765
if (Kind == ConstraintKind::ValueMember ||
793-
Kind == ConstraintKind::UnresolvedValueMember ||
794-
Kind == ConstraintKind::ValueWitness)
766+
Kind == ConstraintKind::UnresolvedValueMember)
795767
return static_cast<FunctionRefKind>(TheFunctionRefKind);
796768

797769
// Conservative answer: drop all of the labels.
@@ -851,8 +823,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
851823
/// Retrieve the DC in which the member was used.
852824
DeclContext *getMemberUseDC() const {
853825
assert(Kind == ConstraintKind::ValueMember ||
854-
Kind == ConstraintKind::UnresolvedValueMember ||
855-
Kind == ConstraintKind::ValueWitness);
826+
Kind == ConstraintKind::UnresolvedValueMember);
856827
return Member.UseDC;
857828
}
858829

Diff for: include/swift/Sema/ConstraintSystem.h

-20
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.

Diff for: lib/Sema/CSBindings.cpp

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

Diff for: lib/Sema/CSSimplify.cpp

+1-78
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,6 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
21832183
case ConstraintKind::SelfObjectOfProtocol:
21842184
case ConstraintKind::UnresolvedValueMember:
21852185
case ConstraintKind::ValueMember:
2186-
case ConstraintKind::ValueWitness:
21872186
case ConstraintKind::BridgingConversion:
21882187
case ConstraintKind::OneWayEqual:
21892188
case ConstraintKind::OneWayBindParam:
@@ -2347,7 +2346,6 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
23472346
case ConstraintKind::SelfObjectOfProtocol:
23482347
case ConstraintKind::UnresolvedValueMember:
23492348
case ConstraintKind::ValueMember:
2350-
case ConstraintKind::ValueWitness:
23512349
case ConstraintKind::OneWayEqual:
23522350
case ConstraintKind::OneWayBindParam:
23532351
case ConstraintKind::DefaultClosureType:
@@ -2794,7 +2792,6 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
27942792
case ConstraintKind::SelfObjectOfProtocol:
27952793
case ConstraintKind::UnresolvedValueMember:
27962794
case ConstraintKind::ValueMember:
2797-
case ConstraintKind::ValueWitness:
27982795
case ConstraintKind::BridgingConversion:
27992796
case ConstraintKind::OneWayEqual:
28002797
case ConstraintKind::OneWayBindParam:
@@ -6036,7 +6033,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
60366033
case ConstraintKind::SelfObjectOfProtocol:
60376034
case ConstraintKind::UnresolvedValueMember:
60386035
case ConstraintKind::ValueMember:
6039-
case ConstraintKind::ValueWitness:
60406036
case ConstraintKind::OneWayEqual:
60416037
case ConstraintKind::OneWayBindParam:
60426038
case ConstraintKind::DefaultClosureType:
@@ -9139,8 +9135,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
91399135
markMemberTypeAsPotentialHole(memberTy);
91409136
return SolutionKind::Solved;
91419137
}
9142-
} else if ((kind == ConstraintKind::ValueMember ||
9143-
kind == ConstraintKind::ValueWitness) &&
9138+
} else if (kind == ConstraintKind::ValueMember &&
91449139
baseObjTy->getMetatypeInstanceType()->isPlaceholder()) {
91459140
// If base type is a "hole" there is no reason to record any
91469141
// more "member not found" fixes for chained member references.
@@ -9562,67 +9557,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
95629557
return SolutionKind::Error;
95639558
}
95649559

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

1327913213
case ConstraintKind::ValueMember:
1328013214
case ConstraintKind::UnresolvedValueMember:
13281-
case ConstraintKind::ValueWitness:
1328213215
case ConstraintKind::BindOverload:
1328313216
case ConstraintKind::Disjunction:
1328413217
case ConstraintKind::Conjunction:
@@ -13769,16 +13702,6 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1376913702
/*outerAlternatives=*/{},
1377013703
/*flags*/ None, constraint.getLocator());
1377113704

13772-
case ConstraintKind::ValueWitness:
13773-
return simplifyValueWitnessConstraint(constraint.getKind(),
13774-
constraint.getFirstType(),
13775-
constraint.getRequirement(),
13776-
constraint.getSecondType(),
13777-
constraint.getMemberUseDC(),
13778-
constraint.getFunctionRefKind(),
13779-
/*flags*/ None,
13780-
constraint.getLocator());
13781-
1378213705
case ConstraintKind::Defaultable:
1378313706
return simplifyDefaultableConstraint(constraint.getFirstType(),
1378413707
constraint.getSecondType(),

Diff for: lib/Sema/Constraint.cpp

-58
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;
@@ -674,7 +637,6 @@ gatherReferencedTypeVars(Constraint *constraint,
674637
case ConstraintKind::Subtype:
675638
case ConstraintKind::UnresolvedValueMember:
676639
case ConstraintKind::ValueMember:
677-
case ConstraintKind::ValueWitness:
678640
case ConstraintKind::DynamicTypeOf:
679641
case ConstraintKind::EscapableFunctionOf:
680642
case ConstraintKind::OpenedExistentialOf:
@@ -820,26 +782,6 @@ Constraint *Constraint::createMember(ConstraintSystem &cs, ConstraintKind kind,
820782
functionRefKind, locator, typeVars);
821783
}
822784

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

0 commit comments

Comments
 (0)