Skip to content

Commit 3332df6

Browse files
authored
Merge pull request swiftlang#33777 from hborla/rename-storage-wrapper
[NFC][Property Wrappers] Rename "storage wrapper var" to "projection var/projected value"
2 parents 1372414 + 3fd882c commit 3332df6

16 files changed

+69
-69
lines changed

include/swift/AST/Decl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4883,9 +4883,9 @@ enum class PropertyWrapperSynthesizedPropertyKind {
48834883
/// The backing storage property, which is a stored property of the
48844884
/// wrapper type.
48854885
Backing,
4886-
/// A storage wrapper (e.g., `$foo`), which is a wrapper over the
4887-
/// wrapper instance's `projectedValue` property.
4888-
StorageWrapper,
4886+
/// A projection (e.g., `$foo`), which is a computed property to access the
4887+
/// wrapper instance's \c projectedValue property.
4888+
Projection,
48894889
};
48904890

48914891
/// VarDecl - 'var' and 'let' declarations.
@@ -5208,9 +5208,9 @@ class VarDecl : public AbstractStorageDecl {
52085208
/// bound generic version.
52095209
VarDecl *getPropertyWrapperBackingProperty() const;
52105210

5211-
/// Retreive the storage wrapper for a property that has an attached
5212-
/// property wrapper.
5213-
VarDecl *getPropertyWrapperStorageWrapper() const;
5211+
/// Retreive the projection var for a property that has an attached
5212+
/// property wrapper with a \c projectedValue .
5213+
VarDecl *getPropertyWrapperProjectionVar() const;
52145214

52155215
/// Retrieve the backing storage property for a lazy property.
52165216
VarDecl *getLazyStorageProperty() const;

include/swift/AST/PropertyWrappers.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ struct PropertyWrapperBackingPropertyInfo {
145145
/// The backing property.
146146
VarDecl *backingVar = nullptr;
147147

148-
/// The storage wrapper property, if any. When present, this takes the name
149-
/// '$foo' from `backingVar`.
150-
VarDecl *storageWrapperVar = nullptr;
148+
/// The synthesized projection property, if any. When present, this takes the name
149+
/// of the original wrapped property prefixed with \c $
150+
VarDecl *projectionVar = nullptr;
151151

152152
/// An expression that initializes the backing property from a value of
153153
/// the original property's type (e.g., via `init(wrappedValue:)`), or
@@ -161,10 +161,10 @@ struct PropertyWrapperBackingPropertyInfo {
161161
PropertyWrapperBackingPropertyInfo() { }
162162

163163
PropertyWrapperBackingPropertyInfo(VarDecl *backingVar,
164-
VarDecl *storageWrapperVar,
164+
VarDecl *projectionVar,
165165
Expr *initializeFromOriginal,
166166
PropertyWrapperValuePlaceholderExpr *placeholder)
167-
: backingVar(backingVar), storageWrapperVar(storageWrapperVar),
167+
: backingVar(backingVar), projectionVar(projectionVar),
168168
initializeFromOriginal(initializeFromOriginal),
169169
wrappedValuePlaceholder(placeholder) { }
170170

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,8 +4840,8 @@ VarDecl *VarDecl::getOriginalWrappedProperty(
48404840
case PropertyWrapperSynthesizedPropertyKind::Backing:
48414841
return this == wrapperInfo.backingVar ? original : nullptr;
48424842

4843-
case PropertyWrapperSynthesizedPropertyKind::StorageWrapper:
4844-
return this == wrapperInfo.storageWrapperVar ? original : nullptr;
4843+
case PropertyWrapperSynthesizedPropertyKind::Projection:
4844+
return this == wrapperInfo.projectionVar ? original : nullptr;
48454845
}
48464846
llvm_unreachable("covered switch");
48474847
}

lib/AST/Decl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5909,17 +5909,17 @@ VarDecl::getPropertyWrapperSynthesizedPropertyKind() const {
59095909
PropertyWrapperSynthesizedPropertyKind::Backing))
59105910
return PropertyWrapperSynthesizedPropertyKind::Backing;
59115911
if (getOriginalWrappedProperty(
5912-
PropertyWrapperSynthesizedPropertyKind::StorageWrapper))
5913-
return PropertyWrapperSynthesizedPropertyKind::StorageWrapper;
5912+
PropertyWrapperSynthesizedPropertyKind::Projection))
5913+
return PropertyWrapperSynthesizedPropertyKind::Projection;
59145914
return None;
59155915
}
59165916

59175917
VarDecl *VarDecl::getPropertyWrapperBackingProperty() const {
59185918
return getPropertyWrapperBackingPropertyInfo().backingVar;
59195919
}
59205920

5921-
VarDecl *VarDecl::getPropertyWrapperStorageWrapper() const {
5922-
return getPropertyWrapperBackingPropertyInfo().storageWrapperVar;
5921+
VarDecl *VarDecl::getPropertyWrapperProjectionVar() const {
5922+
return getPropertyWrapperBackingPropertyInfo().projectionVar;
59235923
}
59245924

59255925
VarDecl *VarDecl::getLazyStorageProperty() const {

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3171,7 +3171,7 @@ bool MissingCallFailure::diagnoseAsError() {
31713171
}
31723172

31733173
bool ExtraneousPropertyWrapperUnwrapFailure::diagnoseAsError() {
3174-
auto newPrefix = usingStorageWrapper() ? "$" : "_";
3174+
auto newPrefix = usingProjection() ? "$" : "_";
31753175

31763176
if (auto *member = getReferencedMember()) {
31773177
emitDiagnostic(diag::incorrect_property_wrapper_reference_member,

lib/Sema/CSDiagnostics.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -974,20 +974,20 @@ class MissingCallFailure final : public FailureDiagnostic {
974974

975975
class PropertyWrapperReferenceFailure : public ContextualFailure {
976976
VarDecl *Property;
977-
bool UsingStorageWrapper;
977+
bool UsingProjection;
978978

979979
public:
980980
PropertyWrapperReferenceFailure(const Solution &solution, VarDecl *property,
981-
bool usingStorageWrapper, Type base,
981+
bool usingProjection, Type base,
982982
Type wrapper, ConstraintLocator *locator)
983983
: ContextualFailure(solution, base, wrapper, locator), Property(property),
984-
UsingStorageWrapper(usingStorageWrapper) {}
984+
UsingProjection(usingProjection) {}
985985

986986
VarDecl *getProperty() const { return Property; }
987987

988988
Identifier getPropertyName() const { return Property->getName(); }
989989

990-
bool usingStorageWrapper() const { return UsingStorageWrapper; }
990+
bool usingProjection() const { return UsingProjection; }
991991

992992
ValueDecl *getReferencedMember() const {
993993
auto *locator = getLocator();

lib/Sema/CSFix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,22 +534,22 @@ InsertExplicitCall *InsertExplicitCall::create(ConstraintSystem &cs,
534534

535535
bool UsePropertyWrapper::diagnose(const Solution &solution, bool asNote) const {
536536
ExtraneousPropertyWrapperUnwrapFailure failure(
537-
solution, Wrapped, UsingStorageWrapper, Base, Wrapper, getLocator());
537+
solution, Wrapped, UsingProjection, Base, Wrapper, getLocator());
538538
return failure.diagnose(asNote);
539539
}
540540

541541
UsePropertyWrapper *UsePropertyWrapper::create(ConstraintSystem &cs,
542542
VarDecl *wrapped,
543-
bool usingStorageWrapper,
543+
bool usingProjection,
544544
Type base, Type wrapper,
545545
ConstraintLocator *locator) {
546546
return new (cs.getAllocator()) UsePropertyWrapper(
547-
cs, wrapped, usingStorageWrapper, base, wrapper, locator);
547+
cs, wrapped, usingProjection, base, wrapper, locator);
548548
}
549549

550550
bool UseWrappedValue::diagnose(const Solution &solution, bool asNote) const {
551551
MissingPropertyWrapperUnwrapFailure failure(solution, PropertyWrapper,
552-
usingStorageWrapper(), Base,
552+
usingProjection(), Base,
553553
Wrapper, getLocator());
554554
return failure.diagnose(asNote);
555555
}

lib/Sema/CSFix.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,15 +799,15 @@ class InsertExplicitCall final : public ConstraintFix {
799799

800800
class UsePropertyWrapper final : public ConstraintFix {
801801
VarDecl *Wrapped;
802-
bool UsingStorageWrapper;
802+
bool UsingProjection;
803803
Type Base;
804804
Type Wrapper;
805805

806806
UsePropertyWrapper(ConstraintSystem &cs, VarDecl *wrapped,
807-
bool usingStorageWrapper, Type base, Type wrapper,
807+
bool usingProjection, Type base, Type wrapper,
808808
ConstraintLocator *locator)
809809
: ConstraintFix(cs, FixKind::UsePropertyWrapper, locator),
810-
Wrapped(wrapped), UsingStorageWrapper(usingStorageWrapper), Base(base),
810+
Wrapped(wrapped), UsingProjection(usingProjection), Base(base),
811811
Wrapper(wrapper) {}
812812

813813
public:
@@ -822,7 +822,7 @@ class UsePropertyWrapper final : public ConstraintFix {
822822
}
823823

824824
static UsePropertyWrapper *create(ConstraintSystem &cs, VarDecl *wrapped,
825-
bool usingStorageWrapper, Type base,
825+
bool usingProjection, Type base,
826826
Type wrapper, ConstraintLocator *locator);
827827
};
828828

@@ -836,7 +836,7 @@ class UseWrappedValue final : public ConstraintFix {
836836
: ConstraintFix(cs, FixKind::UseWrappedValue, locator),
837837
PropertyWrapper(propertyWrapper), Base(base), Wrapper(wrapper) {}
838838

839-
bool usingStorageWrapper() const {
839+
bool usingProjection() const {
840840
auto nameStr = PropertyWrapper->getName().str();
841841
return !nameStr.startswith("_");
842842
}

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,7 @@ static ConstraintFix *fixPropertyWrapperFailure(
28972897
return nullptr;
28982898

28992899
enum class Fix : uint8_t {
2900-
StorageWrapper,
2900+
ProjectedValue,
29012901
PropertyWrapper,
29022902
WrappedValue,
29032903
};
@@ -2916,9 +2916,9 @@ static ConstraintFix *fixPropertyWrapperFailure(
29162916
return nullptr;
29172917

29182918
switch (fix) {
2919-
case Fix::StorageWrapper:
2919+
case Fix::ProjectedValue:
29202920
case Fix::PropertyWrapper:
2921-
return UsePropertyWrapper::create(cs, decl, fix == Fix::StorageWrapper,
2921+
return UsePropertyWrapper::create(cs, decl, fix == Fix::ProjectedValue,
29222922
baseTy, toType.getValueOr(type),
29232923
locator);
29242924

@@ -2929,10 +2929,10 @@ static ConstraintFix *fixPropertyWrapperFailure(
29292929
llvm_unreachable("Unhandled Fix type in switch");
29302930
};
29312931

2932-
if (auto storageWrapper =
2933-
cs.getStorageWrapperInformation(*resolvedOverload)) {
2934-
if (auto *fix = applyFix(Fix::StorageWrapper, storageWrapper->first,
2935-
storageWrapper->second))
2932+
if (auto projection =
2933+
cs.getPropertyWrapperProjectionInfo(*resolvedOverload)) {
2934+
if (auto *fix = applyFix(Fix::ProjectedValue, projection->first,
2935+
projection->second))
29362936
return fix;
29372937
}
29382938

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -956,20 +956,20 @@ getPropertyWrapperInformationFromOverload(
956956
}
957957

958958
Optional<std::pair<VarDecl *, Type>>
959-
ConstraintSystem::getStorageWrapperInformation(
959+
ConstraintSystem::getPropertyWrapperProjectionInfo(
960960
SelectedOverload resolvedOverload) {
961961
return getPropertyWrapperInformationFromOverload(
962962
resolvedOverload, DC,
963963
[](VarDecl *decl) -> Optional<std::pair<VarDecl *, Type>> {
964964
if (!decl->hasAttachedPropertyWrapper())
965965
return None;
966966

967-
auto storageWrapper = decl->getPropertyWrapperStorageWrapper();
968-
if (!storageWrapper)
967+
auto projectionVar = decl->getPropertyWrapperProjectionVar();
968+
if (!projectionVar)
969969
return None;
970970

971-
return std::make_pair(storageWrapper,
972-
storageWrapper->getInterfaceType());
971+
return std::make_pair(projectionVar,
972+
projectionVar->getInterfaceType());
973973
});
974974
}
975975

0 commit comments

Comments
 (0)