Skip to content

Commit 9b20012

Browse files
authored
Merge pull request swiftlang#27322 from DougGregor/property-wrapper-composition-di
[DI] Support definite initialization for composed property wrappers.
2 parents adb0e6e + 6549a0d commit 9b20012

36 files changed

+534
-222
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ Entities
290290
entity-spec ::= type 'fu' INDEX // implicit anonymous closure
291291
entity-spec ::= 'fA' INDEX // default argument N+1 generator
292292
entity-spec ::= 'fi' // non-local variable initializer
293+
entity-spec ::= 'fP' // property wrapper backing initializer
293294
entity-spec ::= 'fD' // deallocating destructor; untyped
294295
entity-spec ::= 'fd' // non-deallocating destructor; untyped
295296
entity-spec ::= 'fE' // ivar destroyer; untyped

include/swift/AST/ASTMangler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class ASTMangler : public Mangler {
124124
SymbolKind SKind);
125125

126126
std::string mangleInitializerEntity(const VarDecl *var, SymbolKind SKind);
127+
std::string mangleBackingInitializerEntity(const VarDecl *var,
128+
SymbolKind SKind);
127129

128130
std::string mangleNominalType(const NominalTypeDecl *decl);
129131

@@ -311,6 +313,7 @@ class ASTMangler : public Mangler {
311313
void appendDefaultArgumentEntity(const DeclContext *ctx, unsigned index);
312314

313315
void appendInitializerEntity(const VarDecl *var);
316+
void appendBackingInitializerEntity(const VarDecl *var);
314317

315318
CanType getDeclTypeForMangling(const ValueDecl *decl,
316319
GenericSignature *&genericSig,

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4528,8 +4528,6 @@ ERROR(property_wrapper_wrong_initial_value_init, none,
45284528
(DeclName, Type, Type))
45294529
ERROR(property_wrapper_failable_init, none,
45304530
"%0 cannot be failable", (DeclName))
4531-
ERROR(property_wrapper_ambiguous_initial_value_init, none,
4532-
"property wrapper type %0 has multiple initial-value initializers", (Type))
45334531
ERROR(property_wrapper_ambiguous_default_value_init, none,
45344532
"property wrapper type %0 has multiple default-value initializers", (Type))
45354533
ERROR(property_wrapper_type_requirement_not_accessible,none,

include/swift/AST/PropertyWrappers.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ struct PropertyWrapperTypeInfo {
3535
/// directed.
3636
VarDecl *valueVar = nullptr;
3737

38-
/// The initializer init(wrappedValue:) that will be called when the
38+
/// Whether there is an init(wrappedValue:) that will be called when the
3939
/// initializing the property wrapper type from a value of the property type.
40-
///
41-
/// This initializer is optional, but if present will be used for the `=`
42-
/// initialization syntax.
43-
ConstructorDecl *wrappedValueInit = nullptr;
40+
enum {
41+
NoWrappedValueInit = 0,
42+
HasWrappedValueInit,
43+
HasInitialValueInit
44+
} wrappedValueInit = NoWrappedValueInit;
4445

4546
/// The initializer `init()` that will be called to default-initialize a
4647
/// value with an attached property wrapper.

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ NODE(PostfixOperator)
157157
NODE(PrefixOperator)
158158
NODE(PrivateDeclName)
159159
NODE(PropertyDescriptor)
160+
CONTEXT_NODE(PropertyWrapperBackingInitializer)
160161
CONTEXT_NODE(Protocol)
161162
CONTEXT_NODE(ProtocolSymbolicReference)
162163
NODE(ProtocolConformance)

include/swift/SIL/SILDeclRef.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ struct SILDeclRef {
133133
/// routines have an ivar destroyer, which is emitted as
134134
/// .cxx_destruct.
135135
IVarDestroyer,
136+
137+
/// References the wrapped value injection function used to initialize
138+
/// the backing storage property from a wrapped value.
139+
PropertyWrapperBackingInitializer,
136140
};
137141

138142
/// The ValueDecl or AbstractClosureExpr represented by this SILDeclRef.

lib/AST/ASTMangler.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ std::string ASTMangler::mangleInitializerEntity(const VarDecl *var,
155155
return finalize();
156156
}
157157

158+
std::string ASTMangler::mangleBackingInitializerEntity(const VarDecl *var,
159+
SymbolKind SKind) {
160+
beginMangling();
161+
appendBackingInitializerEntity(var);
162+
appendSymbolKind(SKind);
163+
return finalize();
164+
}
165+
158166
std::string ASTMangler::mangleNominalType(const NominalTypeDecl *decl) {
159167
beginMangling();
160168
appendAnyGenericType(decl);
@@ -2334,6 +2342,11 @@ void ASTMangler::appendInitializerEntity(const VarDecl *var) {
23342342
appendOperator("fi");
23352343
}
23362344

2345+
void ASTMangler::appendBackingInitializerEntity(const VarDecl *var) {
2346+
appendEntity(var, "vp", var->isStatic());
2347+
appendOperator("fP");
2348+
}
2349+
23372350
/// Is this declaration a method for mangling purposes? If so, we'll leave the
23382351
/// Self type out of its mangling.
23392352
static bool isMethodDecl(const Decl *decl) {

lib/AST/Decl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5482,7 +5482,8 @@ bool VarDecl::hasAttachedPropertyWrapper() const {
54825482
return !getAttachedPropertyWrappers().empty();
54835483
}
54845484

5485-
/// Whether all of the attached property wrappers have an init(initialValue:) initializer.
5485+
/// Whether all of the attached property wrappers have an init(wrappedValue:)
5486+
/// initializer.
54865487
bool VarDecl::allAttachedPropertyWrappersHaveInitialValueInit() const {
54875488
for (unsigned i : indices(getAttachedPropertyWrappers())) {
54885489
if (!getAttachedPropertyWrapperTypeInfo(i).wrappedValueInit)

lib/AST/TypeCheckRequests.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,6 @@ void swift::simple_display(
564564
out << propertyWrapper.valueVar->printRef();
565565
else
566566
out << "null";
567-
out << ", ";
568-
if (propertyWrapper.wrappedValueInit)
569-
out << propertyWrapper.wrappedValueInit->printRef();
570-
else
571-
out << "null";
572567
out << " }";
573568
}
574569

lib/Demangling/Demangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ bool Demangle::nodeConsumesGenericArgs(Node *node) {
15771577
case Node::Kind::ExplicitClosure:
15781578
case Node::Kind::DefaultArgumentInitializer:
15791579
case Node::Kind::Initializer:
1580+
case Node::Kind::PropertyWrapperBackingInitializer:
15801581
return false;
15811582
default:
15821583
return true;
@@ -2934,6 +2935,10 @@ NodePointer Demangler::demangleFunctionEntity() {
29342935
case 'u': Args = TypeAndIndex; Kind = Node::Kind::ImplicitClosure; break;
29352936
case 'A': Args = Index; Kind = Node::Kind::DefaultArgumentInitializer; break;
29362937
case 'p': return demangleEntity(Node::Kind::GenericTypeParamDecl);
2938+
case 'P':
2939+
Args = None;
2940+
Kind = Node::Kind::PropertyWrapperBackingInitializer;
2941+
break;
29372942
default: return nullptr;
29382943
}
29392944

0 commit comments

Comments
 (0)