Skip to content

Commit 5a124f1

Browse files
authored
Merge pull request #25484 from DougGregor/property-wrappers-5.1
[5.1] Bring property wrappers up-to-date with the proposal under review
2 parents 6e36612 + b450fea commit 5a124f1

24 files changed

+814
-387
lines changed

include/swift/AST/Decl.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5078,26 +5078,39 @@ class VarDecl : public AbstractStorageDecl {
50785078
Bits.VarDecl.IsREPLVar = IsREPLVar;
50795079
}
50805080

5081-
/// Retrieve the custom attribute that attaches a property wrapper to this
5082-
/// property.
5083-
CustomAttr *getAttachedPropertyWrapper() const;
5081+
/// Retrieve the custom attributes that attach property wrappers to this
5082+
/// property. The returned list contains all of the attached property wrapper attributes in source order,
5083+
/// which means the outermost wrapper attribute is provided first.
5084+
llvm::TinyPtrVector<CustomAttr *> getAttachedPropertyWrappers() const;
50845085

5086+
/// Whether this property has any attached property wrappers.
5087+
bool hasAttachedPropertyWrapper() const;
5088+
5089+
/// Whether all of the attached property wrappers have an init(initialValue:) initializer.
5090+
bool allAttachedPropertyWrappersHaveInitialValueInit() const;
5091+
50855092
/// Retrieve the type of the attached property wrapper as a contextual
50865093
/// type.
50875094
///
5095+
/// \param index Which property wrapper type is being computed, where 0
5096+
/// indicates the first (outermost) attached property wrapper.
5097+
///
50885098
/// \returns a NULL type for properties without attached wrappers,
50895099
/// an error type when the property wrapper type itself is erroneous,
50905100
/// or the wrapper type itself, which may involve unbound generic
50915101
/// types.
5092-
Type getAttachedPropertyWrapperType() const;
5102+
Type getAttachedPropertyWrapperType(unsigned index) const;
50935103

50945104
/// Retrieve information about the attached property wrapper type.
5095-
PropertyWrapperTypeInfo getAttachedPropertyWrapperTypeInfo() const;
5105+
///
5106+
/// \param i Which attached property wrapper type is being queried, where 0 is the outermost (first)
5107+
/// attached property wrapper type.
5108+
PropertyWrapperTypeInfo getAttachedPropertyWrapperTypeInfo(unsigned i) const;
50965109

50975110
/// Retrieve the fully resolved attached property wrapper type.
50985111
///
50995112
/// This type will be the fully-resolved form of
5100-
/// \c getAttachedPropertyWrapperType(), which will not contain any
5113+
/// \c getAttachedPropertyWrapperType(0), which will not contain any
51015114
/// unbound generic types. It will be the type of the backing property.
51025115
Type getPropertyWrapperBackingPropertyType() const;
51035116

@@ -5111,8 +5124,8 @@ class VarDecl : public AbstractStorageDecl {
51115124
///
51125125
/// The backing storage property will be a stored property of the
51135126
/// wrapper's type. This will be equivalent to
5114-
/// \c getAttachedPropertyWrapperType() when it is fully-specified;
5115-
/// if \c getAttachedPropertyWrapperType() involves an unbound
5127+
/// \c getAttachedPropertyWrapperType(0) when it is fully-specified;
5128+
/// if \c getAttachedPropertyWrapperType(0) involves an unbound
51165129
/// generic type, the backing storage property will be the appropriate
51175130
/// bound generic version.
51185131
VarDecl *getPropertyWrapperBackingProperty() const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4372,7 +4372,8 @@ ERROR(property_wrapper_ambiguous_value_property, none,
43724372
"named %1", (Type, Identifier))
43734373
ERROR(property_wrapper_wrong_initial_value_init, none,
43744374
"'init(initialValue:)' parameter type (%0) must be the same as its "
4375-
"'value' property type (%1) or an @autoclosure thereof", (Type, Type))
4375+
"'wrappedValue' property type (%1) or an @autoclosure thereof",
4376+
(Type, Type))
43764377
ERROR(property_wrapper_failable_init, none,
43774378
"%0 cannot be failable", (DeclName))
43784379
ERROR(property_wrapper_ambiguous_initial_value_init, none,
@@ -4391,11 +4392,6 @@ ERROR(property_wrapper_attribute_not_on_property, none,
43914392
NOTE(property_wrapper_declared_here,none,
43924393
"property wrapper type %0 declared here", (DeclName))
43934394

4394-
ERROR(property_wrapper_multiple,none,
4395-
"only one property wrapper can be attached to a given property", ())
4396-
NOTE(previous_property_wrapper_here,none,
4397-
"previous property wrapper specified here", ())
4398-
43994395
ERROR(property_wrapper_local,none,
44004396
"property wrappers are not yet supported on local properties", ())
44014397
ERROR(property_wrapper_let, none,
@@ -4419,18 +4415,12 @@ ERROR(property_with_wrapper_overrides,none,
44194415
"property %0 with attached wrapper cannot override another property",
44204416
(DeclName))
44214417

4422-
ERROR(property_wrapper_and_normal_init,none,
4423-
"property %0 with attached wrapper cannot initialize both the "
4424-
"wrapper type and the property", (DeclName))
4425-
ERROR(property_wrapper_init_without_initial_value, none,
4426-
"initializing property %0 with wrapper %1 that lacks "
4427-
"an 'init(initialValue:)' initializer", (DeclName, Type))
44284418
NOTE(property_wrapper_direct_init,none,
44294419
"initialize the property wrapper type directly with "
44304420
"'(...') on the attribute", ())
44314421

44324422
ERROR(property_wrapper_incompatible_property, none,
4433-
"property type %0 does not match that of the 'value' property of "
4423+
"property type %0 does not match that of the 'wrappedValue' property of "
44344424
"its wrapper type %1", (Type, Type))
44354425

44364426
ERROR(property_wrapper_type_access,none,
@@ -4450,6 +4440,9 @@ ERROR(property_wrapper_type_not_usable_from_inline,none,
44504440
WARNING(property_wrapper_delegateValue,none,
44514441
"property wrapper's `delegateValue` property should be renamed to "
44524442
"'wrapperValue'; use of 'delegateValue' is deprecated", ())
4443+
WARNING(property_wrapper_value,none,
4444+
"property wrapper's `value` property should be renamed to "
4445+
"'wrappedValue'; use of 'value' is deprecated", ())
44534446

44544447
//------------------------------------------------------------------------------
44554448
// MARK: function builder diagnostics

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ IDENTIFIER_WITH_NAME(value_, "_value")
120120
IDENTIFIER(with)
121121
IDENTIFIER(withArguments)
122122
IDENTIFIER(withKeywordArguments)
123+
IDENTIFIER(wrappedValue)
123124
IDENTIFIER(wrapperValue)
124125

125126
// Kinds of layout constraints

include/swift/AST/TypeCheckRequests.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ class PropertyWrapperTypeInfoRequest
420420

421421
/// Request the nominal type declaration to which the given custom attribute
422422
/// refers.
423-
class AttachedPropertyWrapperRequest :
424-
public SimpleRequest<AttachedPropertyWrapperRequest,
423+
class AttachedPropertyWrappersRequest :
424+
public SimpleRequest<AttachedPropertyWrappersRequest,
425425
CacheKind::Cached,
426-
CustomAttr *,
426+
llvm::TinyPtrVector<CustomAttr *>,
427427
VarDecl *> {
428428
public:
429429
using SimpleRequest::SimpleRequest;
@@ -432,7 +432,7 @@ class AttachedPropertyWrapperRequest :
432432
friend SimpleRequest;
433433

434434
// Evaluation.
435-
llvm::Expected<CustomAttr *>
435+
llvm::Expected<llvm::TinyPtrVector<CustomAttr *>>
436436
evaluate(Evaluator &evaluator, VarDecl *) const;
437437

438438
public:
@@ -450,7 +450,7 @@ class AttachedPropertyWrapperTypeRequest :
450450
public SimpleRequest<AttachedPropertyWrapperTypeRequest,
451451
CacheKind::Cached,
452452
Type,
453-
VarDecl *> {
453+
VarDecl *, unsigned> {
454454
public:
455455
using SimpleRequest::SimpleRequest;
456456

@@ -459,7 +459,7 @@ class AttachedPropertyWrapperTypeRequest :
459459

460460
// Evaluation.
461461
llvm::Expected<Type>
462-
evaluate(Evaluator &evaluator, VarDecl *var) const;
462+
evaluate(Evaluator &evaluator, VarDecl *var, unsigned i) const;
463463

464464
public:
465465
// Caching

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SWIFT_TYPEID(USRGenerationRequest)
2525
SWIFT_TYPEID(DefaultTypeRequest)
2626
SWIFT_TYPEID(MangleLocalTypeDeclRequest)
2727
SWIFT_TYPEID(PropertyWrapperTypeInfoRequest)
28-
SWIFT_TYPEID(AttachedPropertyWrapperRequest)
28+
SWIFT_TYPEID(AttachedPropertyWrappersRequest)
2929
SWIFT_TYPEID(AttachedPropertyWrapperTypeRequest)
3030
SWIFT_TYPEID(PropertyWrapperBackingPropertyTypeRequest)
3131
SWIFT_TYPEID(PropertyWrapperBackingPropertyInfoRequest)

include/swift/Basic/AnyValue.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/Basic/SimpleDisplay.h"
2222
#include "swift/Basic/TypeID.h"
2323
#include "llvm/ADT/PointerUnion.h" // to define hash_value
24+
#include "llvm/ADT/TinyPtrVector.h"
2425

2526
namespace llvm {
2627
// FIXME: Belongs in LLVM itself
@@ -146,6 +147,26 @@ class AnyValue {
146147

147148
} // end namespace swift
148149

150+
namespace llvm {
151+
template<typename T>
152+
bool operator==(const TinyPtrVector<T> &lhs, const TinyPtrVector<T> &rhs) {
153+
if (lhs.size() != rhs.size())
154+
return false;
155+
156+
for (unsigned i = 0, n = lhs.size(); i != n; ++i) {
157+
if (lhs[i] != rhs[i])
158+
return false;
159+
}
160+
161+
return true;
162+
}
163+
164+
template<typename T>
165+
bool operator!=(const TinyPtrVector<T> &lhs, const TinyPtrVector<T> &rhs) {
166+
return !(lhs == rhs);
167+
}
168+
} // end namespace llvm
169+
149170
#endif //
150171

151172

include/swift/Basic/SimpleDisplay.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef SWIFT_BASIC_SIMPLE_DISPLAY_H
2020
#define SWIFT_BASIC_SIMPLE_DISPLAY_H
2121

22+
#include "llvm/ADT/TinyPtrVector.h"
2223
#include "llvm/Support/raw_ostream.h"
2324
#include <tuple>
2425
#include <type_traits>
@@ -92,6 +93,20 @@ namespace swift {
9293
const std::tuple<Types...> &value) {
9394
simple_display_tuple<0>(out, value);
9495
}
96+
97+
template<typename T>
98+
void simple_display(llvm::raw_ostream &out,
99+
const llvm::TinyPtrVector<T> &vector) {
100+
out << "{";
101+
bool first = true;
102+
for (const T &value : vector) {
103+
if (first) first = false;
104+
else out << ", ";
105+
106+
simple_display(out, value);
107+
}
108+
out << "}";
109+
}
95110
}
96111

97112
#endif // SWIFT_BASIC_SIMPLE_DISPLAY_H

0 commit comments

Comments
 (0)