Skip to content

Commit 267733a

Browse files
committed
[Property Wrappers] Check property wrapper actor isolation and initializer
effects in PropertyWrapperInitializerInfoRequest. Now that property wrapper initializer synthesis and checking is separated from creating the auxiliary variables, checking actor isolation from PropertyWrapperInitializerInfoRequest will not create a circular dependency. This also fixes a local property wrapper crash due to effects checking never being done on synthesized default wrapper initializers.
1 parent de221dd commit 267733a

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,31 +1792,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
17921792
});
17931793
}
17941794

1795-
/// If the given pattern binding has a property wrapper, check the
1796-
/// isolation and effects of the backing storage initializer.
1797-
void checkPropertyWrapperBackingInitializer(PatternBindingDecl *PBD) {
1798-
auto singleVar = PBD->getSingleVar();
1799-
if (!singleVar)
1800-
return;
1801-
1802-
if (!singleVar->hasAttachedPropertyWrapper())
1803-
return;
1804-
1805-
auto *backingVar = singleVar->getPropertyWrapperBackingProperty();
1806-
if (!backingVar)
1807-
return;
1808-
1809-
auto backingPBD = backingVar->getParentPatternBinding();
1810-
if (!backingPBD)
1811-
return;
1812-
1813-
auto initInfo = singleVar->getPropertyWrapperInitializerInfo();
1814-
if (auto initializer = initInfo.getInitFromWrappedValue()) {
1815-
checkPropertyWrapperActorIsolation(backingPBD, initializer);
1816-
TypeChecker::checkPropertyWrapperEffects(backingPBD, initializer);
1817-
}
1818-
}
1819-
18201795
void visitPatternBindingDecl(PatternBindingDecl *PBD) {
18211796
DeclContext *DC = PBD->getDeclContext();
18221797

@@ -1963,8 +1938,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
19631938
}
19641939
}
19651940
}
1966-
1967-
checkPropertyWrapperBackingInitializer(PBD);
19681941
}
19691942

19701943
void visitSubscriptDecl(SubscriptDecl *SD) {

lib/Sema/TypeCheckStorage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,6 +2584,11 @@ static void typeCheckSynthesizedWrapperInitializer(VarDecl *wrappedVar,
25842584
dyn_cast_or_null<Initializer>(parentPBD->getInitContext(i))) {
25852585
TypeChecker::contextualizeInitializer(initializerContext, initializer);
25862586
}
2587+
2588+
auto *backingVar = wrappedVar->getPropertyWrapperBackingProperty();
2589+
auto *backingPBD = backingVar->getParentPatternBinding();
2590+
checkPropertyWrapperActorIsolation(backingPBD, initializer);
2591+
TypeChecker::checkPropertyWrapperEffects(backingPBD, initializer);
25872592
}
25882593

25892594
static PropertyWrapperMutability::Value

test/SILGen/property_wrapper_local.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,30 @@ func testCaptures() {
190190
// closure #1 in testCaptures()
191191
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local12testCapturesyyFyycfU_ : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> ()
192192
}
193+
194+
@propertyWrapper
195+
struct DefaultInit {
196+
var wrappedValue: Int
197+
198+
// CHECK-LABEL: sil hidden [ossa] @$s22property_wrapper_local11DefaultInitVACycfC : $@convention(method) (@thin DefaultInit.Type) -> DefaultInit
199+
init() {
200+
self.wrappedValue = 0
201+
}
202+
203+
// CHECK-LABEL: sil hidden [ossa] @$s22property_wrapper_local11DefaultInitV5valueACSi_tcfC : $@convention(method) (Int, @thin DefaultInit.Type) -> DefaultInit
204+
init(value: Int) {
205+
self.wrappedValue = value
206+
}
207+
}
208+
209+
// CHECK-LABEL: sil hidden [ossa] @$s22property_wrapper_local20testLocalDefaultInityyF : $@convention(thin) () -> ()
210+
func testLocalDefaultInit() {
211+
// CHECK: function_ref @$s22property_wrapper_local11DefaultInitVACycfC : $@convention(method) (@thin DefaultInit.Type) -> DefaultInit
212+
@DefaultInit var x: Int
213+
214+
// CHECK: function_ref @$s22property_wrapper_local11DefaultInitV5valueACSi_tcfC : $@convention(method) (Int, @thin DefaultInit.Type) -> DefaultInit
215+
@DefaultInit(value: 10) var z: Int
216+
217+
// CHECK: function_ref @$s22property_wrapper_local11DefaultInitVACycfC : $@convention(method) (@thin DefaultInit.Type) -> DefaultInit
218+
@DefaultInit() var y: Int
219+
}

0 commit comments

Comments
 (0)