Skip to content

[Property Wrappers] Fix computation of lvalue-ness in buildStorageReference #29069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/AST/ASTTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ SWIFT_TYPEID_NAMED(NamedPattern *, NamedPattern)
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
SWIFT_TYPEID_NAMED(OpaqueTypeDecl *, OpaqueTypeDecl)
SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl)
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperLValueness>,
PropertyWrapperLValueness)
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>,
PropertyWrapperMutability)
SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl)
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/ASTTypeIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PrecedenceGroupDecl;
struct PropertyWrapperBackingPropertyInfo;
struct PropertyWrapperTypeInfo;
enum class CtorInitializerKind;
struct PropertyWrapperLValueness;
struct PropertyWrapperMutability;
class ProtocolDecl;
class Requirement;
Expand Down
14 changes: 14 additions & 0 deletions include/swift/AST/PropertyWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ struct PropertyWrapperMutability {

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

/// Describes whether the reference to a property wrapper instance used for
/// accessing a wrapped property should be an l-value or not.
struct PropertyWrapperLValueness {
llvm::SmallVector<bool, 1> isLValueForGetAccess;
llvm::SmallVector<bool, 1> isLValueForSetAccess;

bool operator==(PropertyWrapperLValueness other) const {
return (isLValueForGetAccess == other.isLValueForGetAccess &&
isLValueForSetAccess == other.isLValueForSetAccess);
}
};

void simple_display(llvm::raw_ostream &os, PropertyWrapperLValueness l);

/// Describes the backing property of a property that has an attached wrapper.
struct PropertyWrapperBackingPropertyInfo {
/// The backing property.
Expand Down
21 changes: 21 additions & 0 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DefaultArgumentExpr;
class GenericParamList;
class PrecedenceGroupDecl;
struct PropertyWrapperBackingPropertyInfo;
struct PropertyWrapperLValueness;
struct PropertyWrapperMutability;
class RequirementRepr;
class SpecializeAttr;
Expand Down Expand Up @@ -619,6 +620,26 @@ class PropertyWrapperMutabilityRequest :
bool isCached() const;
};

/// Request information about the l-valueness of composed property wrappers.
class PropertyWrapperLValuenessRequest :
public SimpleRequest<PropertyWrapperLValuenessRequest,
Optional<PropertyWrapperLValueness> (VarDecl *),
CacheKind::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

// Evaluation.
llvm::Expected<Optional<PropertyWrapperLValueness>>
evaluate(Evaluator &evaluator, VarDecl *var) const;

public:
// Caching
bool isCached() const;
};

/// Request information about the backing property for properties that have
/// attached property wrappers.
class PropertyWrapperBackingPropertyInfoRequest :
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ SWIFT_REQUEST(TypeChecker, PropertyWrapperBackingPropertyInfoRequest,
NoLocationInfo)
SWIFT_REQUEST(TypeChecker, PropertyWrapperBackingPropertyTypeRequest,
Type(VarDecl *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, PropertyWrapperLValuenessRequest,
Optional<PropertyWrapperLValueness>(VarDecl *), Cached,
NoLocationInfo)
SWIFT_REQUEST(TypeChecker, PropertyWrapperMutabilityRequest,
Optional<PropertyWrapperMutability>(VarDecl *), Cached,
NoLocationInfo)
Expand Down
13 changes: 13 additions & 0 deletions lib/AST/TypeCheckRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ bool PropertyWrapperMutabilityRequest::isCached() const {
return !var->getAttrs().isEmpty();
}

bool PropertyWrapperLValuenessRequest::isCached() const {
auto var = std::get<0>(getStorage());
return !var->getAttrs().isEmpty();
}

void swift::simple_display(
llvm::raw_ostream &out, const PropertyWrapperTypeInfo &propertyWrapper) {
out << "{ ";
Expand Down Expand Up @@ -589,6 +594,14 @@ void swift::simple_display(llvm::raw_ostream &os, PropertyWrapperMutability m) {
os << "getter " << names[m.Getter] << ", setter " << names[m.Setter];
}

void swift::simple_display(llvm::raw_ostream &out, PropertyWrapperLValueness l) {
out << "is lvalue for get: {";
simple_display(out, l.isLValueForGetAccess);
out << "}, is lvalue for set: {";
simple_display(out, l.isLValueForSetAccess);
out << "}";
}

void swift::simple_display(llvm::raw_ostream &out,
const ResilienceExpansion &value) {
out << value;
Expand Down
Loading