Skip to content

Commit 3891dc7

Browse files
committed
[ConstraintSystem] Added necessary logic so that a constraint locator can recognize a composed property wrapper’s wrapped value type.
1 parent 16adf76 commit 3891dc7

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ class ConstraintLocator : public llvm::FoldingSetNode {
212212
/// Determine whether this locator points to the generic parameter.
213213
bool isForGenericParameter() const;
214214

215+
/// Determine whether this locator points to the outer
216+
/// property wrapper's type for a given composed property
217+
/// wrapper.
218+
bool isForWrappedValue() const;
219+
215220
/// Determine whether this locator points to the element type of a
216221
/// sequence in a for ... in ... loop.
217222
bool isForSequenceElementType() const;
@@ -355,6 +360,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
355360

356361
/// If this locator points to generic parameter return its type.
357362
GenericTypeParamType *getGenericParameter() const;
363+
364+
/// If this locator points to the outer property wrapper's
365+
/// type for a given composed property wrapper.
366+
TypeBase *getWrappedValue() const;
358367

359368
/// Produce a profile of this locator, for use in a folding set.
360369
static void Profile(llvm::FoldingSetNodeID &id, ASTNode anchor,
@@ -692,6 +701,21 @@ class LocatorPathElt::GenericParameter final : public StoredPointerElement<Gener
692701
}
693702
};
694703

704+
class LocatorPathElt::WrappedValue final : public StoredPointerElement<TypeBase> {
705+
public:
706+
WrappedValue(TypeBase *type)
707+
: StoredPointerElement(PathElementKind::WrappedValue, type) {
708+
}
709+
710+
TypeBase *getType() const {
711+
return getStoredPointer();
712+
}
713+
714+
static bool classof(const LocatorPathElt *elt) {
715+
return elt->getKind() == PathElementKind::WrappedValue;
716+
}
717+
};
718+
695719
class LocatorPathElt::OpenedGeneric final : public StoredPointerElement<GenericSignatureImpl> {
696720
public:
697721
OpenedGeneric(GenericSignature sig)

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ SIMPLE_LOCATOR_PATH_ELT(InstanceType)
9696
/// Also contains the generic parameter type itself.
9797
CUSTOM_LOCATOR_PATH_ELT(GenericParameter)
9898

99+
/// The former wrappedValue type for a property wrapper.
100+
///
101+
/// Must equal the property declaration's property wrapper type.
102+
CUSTOM_LOCATOR_PATH_ELT(WrappedValue)
103+
99104
/// A component of a key path.
100105
CUSTOM_LOCATOR_PATH_ELT(KeyPathComponent)
101106

lib/Sema/ConstraintLocator.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
6060
case ConstraintLocator::DynamicType:
6161
case ConstraintLocator::SubscriptMember:
6262
case ConstraintLocator::OpenedGeneric:
63+
case ConstraintLocator::WrappedValue:
6364
case ConstraintLocator::GenericParameter:
6465
case ConstraintLocator::GenericArgument:
6566
case ConstraintLocator::NamedTupleElement:
@@ -188,6 +189,10 @@ bool ConstraintLocator::isForGenericParameter() const {
188189
return isLastElement<LocatorPathElt::GenericParameter>();
189190
}
190191

192+
bool ConstraintLocator::isForWrappedValue() const {
193+
return isLastElement<LocatorPathElt::WrappedValue>();
194+
}
195+
191196
bool ConstraintLocator::isForSequenceElementType() const {
192197
return isLastElement<LocatorPathElt::SequenceElementType>();
193198
}
@@ -218,6 +223,11 @@ GenericTypeParamType *ConstraintLocator::getGenericParameter() const {
218223
castLastElementTo<LocatorPathElt::GenericParameter>().getType() : nullptr;
219224
}
220225

226+
TypeBase *ConstraintLocator::getWrappedValue() const {
227+
return isForWrappedValue() ?
228+
castLastElementTo<LocatorPathElt::WrappedValue>().getType() : nullptr;
229+
}
230+
221231
void ConstraintLocator::dump(SourceManager *sm) const {
222232
dump(sm, llvm::errs());
223233
llvm::errs() << "\n";
@@ -270,6 +280,12 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
270280
out << "generic parameter '" << gpElt.getType()->getString(PO) << "'";
271281
break;
272282
}
283+
case WrappedValue: {
284+
auto wrappedValueElt = elt.castTo<LocatorPathElt::WrappedValue>();
285+
out << "composed property wrapper type '"
286+
<< wrappedValueElt.getType()->getString(PO) << "'";
287+
break;
288+
}
273289
case ApplyArgument:
274290
out << "apply argument";
275291
break;

0 commit comments

Comments
 (0)