Skip to content

Commit 8625aa5

Browse files
authored
Merge pull request #31054 from hborla/roop-buildStorageReference_lvalue
[Property Wrappers] Fix computation of lvalue-ness in buildStorageReference
2 parents dc42259 + b27b8cf commit 8625aa5

File tree

10 files changed

+461
-65
lines changed

10 files changed

+461
-65
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ SWIFT_TYPEID_NAMED(NamedPattern *, NamedPattern)
4747
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
4848
SWIFT_TYPEID_NAMED(OpaqueTypeDecl *, OpaqueTypeDecl)
4949
SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl)
50+
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperLValueness>,
51+
PropertyWrapperLValueness)
5052
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>,
5153
PropertyWrapperMutability)
5254
SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class PrefixOperatorDecl;
4949
struct PropertyWrapperBackingPropertyInfo;
5050
struct PropertyWrapperTypeInfo;
5151
enum class CtorInitializerKind;
52+
struct PropertyWrapperLValueness;
5253
struct PropertyWrapperMutability;
5354
class ProtocolDecl;
5455
class Requirement;

include/swift/AST/PropertyWrappers.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ struct PropertyWrapperMutability {
127127

128128
void simple_display(llvm::raw_ostream &os, PropertyWrapperMutability m);
129129

130+
/// Describes whether the reference to a property wrapper instance used for
131+
/// accessing a wrapped property should be an l-value or not.
132+
struct PropertyWrapperLValueness {
133+
llvm::SmallVector<bool, 4> isLValueForGetAccess;
134+
llvm::SmallVector<bool, 4> isLValueForSetAccess;
135+
136+
PropertyWrapperLValueness(unsigned numWrappers)
137+
: isLValueForGetAccess(numWrappers), isLValueForSetAccess(numWrappers) {}
138+
139+
bool operator==(PropertyWrapperLValueness other) const {
140+
return (isLValueForGetAccess == other.isLValueForGetAccess &&
141+
isLValueForSetAccess == other.isLValueForSetAccess);
142+
}
143+
};
144+
145+
void simple_display(llvm::raw_ostream &os, PropertyWrapperLValueness l);
146+
130147
/// Describes the backing property of a property that has an attached wrapper.
131148
struct PropertyWrapperBackingPropertyInfo {
132149
/// The backing property.

include/swift/AST/TypeCheckRequests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ClosureExpr;
4141
class GenericParamList;
4242
class PrecedenceGroupDecl;
4343
struct PropertyWrapperBackingPropertyInfo;
44+
struct PropertyWrapperLValueness;
4445
struct PropertyWrapperMutability;
4546
class RequirementRepr;
4647
class SpecializeAttr;
@@ -632,6 +633,26 @@ class PropertyWrapperMutabilityRequest :
632633
bool isCached() const;
633634
};
634635

636+
/// Request information about the l-valueness of composed property wrappers.
637+
class PropertyWrapperLValuenessRequest :
638+
public SimpleRequest<PropertyWrapperLValuenessRequest,
639+
Optional<PropertyWrapperLValueness> (VarDecl *),
640+
RequestFlags::Cached> {
641+
public:
642+
using SimpleRequest::SimpleRequest;
643+
644+
private:
645+
friend SimpleRequest;
646+
647+
// Evaluation.
648+
Optional<PropertyWrapperLValueness>
649+
evaluate(Evaluator &evaluator, VarDecl *var) const;
650+
651+
public:
652+
// Caching
653+
bool isCached() const;
654+
};
655+
635656
/// Request information about the backing property for properties that have
636657
/// attached property wrappers.
637658
class PropertyWrapperBackingPropertyInfoRequest :

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ SWIFT_REQUEST(TypeChecker, PropertyWrapperBackingPropertyInfoRequest,
150150
NoLocationInfo)
151151
SWIFT_REQUEST(TypeChecker, PropertyWrapperBackingPropertyTypeRequest,
152152
Type(VarDecl *), Cached, NoLocationInfo)
153+
SWIFT_REQUEST(TypeChecker, PropertyWrapperLValuenessRequest,
154+
Optional<PropertyWrapperLValueness>(VarDecl *), Cached,
155+
NoLocationInfo)
153156
SWIFT_REQUEST(TypeChecker, PropertyWrapperMutabilityRequest,
154157
Optional<PropertyWrapperMutability>(VarDecl *), Cached,
155158
NoLocationInfo)

lib/AST/TypeCheckRequests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ bool PropertyWrapperMutabilityRequest::isCached() const {
573573
return !var->getAttrs().isEmpty();
574574
}
575575

576+
bool PropertyWrapperLValuenessRequest::isCached() const {
577+
auto var = std::get<0>(getStorage());
578+
return !var->getAttrs().isEmpty();
579+
}
580+
576581
void swift::simple_display(
577582
llvm::raw_ostream &out, const PropertyWrapperTypeInfo &propertyWrapper) {
578583
out << "{ ";
@@ -615,6 +620,14 @@ void swift::simple_display(llvm::raw_ostream &os, PropertyWrapperMutability m) {
615620
os << "getter " << names[m.Getter] << ", setter " << names[m.Setter];
616621
}
617622

623+
void swift::simple_display(llvm::raw_ostream &out, PropertyWrapperLValueness l) {
624+
out << "is lvalue for get: {";
625+
simple_display(out, l.isLValueForGetAccess);
626+
out << "}, is lvalue for set: {";
627+
simple_display(out, l.isLValueForSetAccess);
628+
out << "}";
629+
}
630+
618631
void swift::simple_display(llvm::raw_ostream &out,
619632
ResilienceExpansion value) {
620633
switch (value) {

0 commit comments

Comments
 (0)