Skip to content

Commit fb5ea36

Browse files
authored
Merge pull request #28987 from slavapestov/property-wrapper-modify-transparent-5.2
Sema: Don't mark property wrapper 'modify' accessors transparent [5.2]
2 parents f447ed7 + 5879382 commit fb5ea36

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,22 +2012,22 @@ IsAccessorTransparentRequest::evaluate(Evaluator &evaluator,
20122012
// Getters and setters for lazy properties are not @_transparent.
20132013
if (storage->getAttrs().hasAttribute<LazyAttr>())
20142014
return false;
2015+
}
20152016

2016-
// Getters/setters for a property with a wrapper are not @_transparent if
2017-
// the backing variable has more-restrictive access than the original
2018-
// property. The same goes for its storage wrapper.
2019-
if (auto var = dyn_cast<VarDecl>(storage)) {
2020-
if (auto backingVar = var->getPropertyWrapperBackingProperty()) {
2021-
if (backingVar->getFormalAccess() < var->getFormalAccess())
2022-
return false;
2023-
}
2017+
// Accessors for a property with a wrapper are not @_transparent if
2018+
// the backing variable has more-restrictive access than the original
2019+
// property. The same goes for its storage wrapper.
2020+
if (auto var = dyn_cast<VarDecl>(storage)) {
2021+
if (auto backingVar = var->getPropertyWrapperBackingProperty()) {
2022+
if (backingVar->getFormalAccess() < var->getFormalAccess())
2023+
return false;
2024+
}
20242025

2025-
if (auto original = var->getOriginalWrappedProperty(
2026-
PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
2027-
auto backingVar = original->getPropertyWrapperBackingProperty();
2028-
if (backingVar->getFormalAccess() < var->getFormalAccess())
2029-
return false;
2030-
}
2026+
if (auto original = var->getOriginalWrappedProperty(
2027+
PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
2028+
auto backingVar = original->getPropertyWrapperBackingProperty();
2029+
if (backingVar->getFormalAccess() < var->getFormalAccess())
2030+
return false;
20312031
}
20322032
}
20332033

test/SILGen/property_wrapper_coroutine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _ = state1.someValues
3434

3535
// >> Check that the _modify coroutine is synthesized properly
3636

37-
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s26property_wrapper_coroutine5StateV6valuesSaySSGvM : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String> {
37+
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_coroutine5StateV6valuesSaySSGvM : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String> {
3838
// CHECK: bb0([[STATE:%.*]] : $*State):
3939
// CHECK: debug_value_addr [[STATE]] : $*State, var, name "self", argno {{.*}}
4040
// CHECK: [[BEGIN_ACCESS:%.*]] = begin_access [modify] [unknown] [[STATE]] : $*State
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
// Makes sure the modify coroutine is not @_transparent, since it references
4+
// private properties.
5+
6+
public class Store {
7+
@Published public var state: Any
8+
init() {}
9+
}
10+
11+
@propertyWrapper public struct Published<Value> {
12+
public init(wrappedValue: Value) {}
13+
public var wrappedValue: Value {
14+
get {}
15+
set {}
16+
}
17+
public static subscript<EnclosingSelf>(
18+
_enclosingInstance object: EnclosingSelf,
19+
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
20+
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Published<Value>>)
21+
-> Value where EnclosingSelf : AnyObject {
22+
get {}
23+
set {}
24+
}
25+
public struct Publisher {}
26+
public var projectedValue: Publisher {
27+
mutating get {}
28+
}
29+
}
30+
31+
// CHECK-LABEL: sil [ossa] @$s33property_wrapper_coroutine_public5StoreC5stateypvM : $@yield_once @convention(method) (@guaranteed Store) -> @yields @inout Any {
32+
// CHECK: keypath $ReferenceWritableKeyPath<Store, Any>, (root $Store; settable_property $Any, id #Store.state!getter.1 : (Store) -> () -> Any, getter @$s33property_wrapper_coroutine_public5StoreC5stateypvpACTK : $@convention(thin) (@in_guaranteed Store) -> @out Any, setter @$s33property_wrapper_coroutine_public5StoreC5stateypvpACTk : $@convention(thin) (@in_guaranteed Any, @in_guaranteed Store) -> ())
33+
// CHECK: keypath $ReferenceWritableKeyPath<Store, Published<Any>>, (root $Store; stored_property #Store._state : $Published<Any>)

0 commit comments

Comments
 (0)