Skip to content

Sema: Don't mark property wrapper 'modify' accessors transparent [5.2] #28987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/Sema/TypeCheckStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2012,22 +2012,22 @@ IsAccessorTransparentRequest::evaluate(Evaluator &evaluator,
// Getters and setters for lazy properties are not @_transparent.
if (storage->getAttrs().hasAttribute<LazyAttr>())
return false;
}

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

if (auto original = var->getOriginalWrappedProperty(
PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
auto backingVar = original->getPropertyWrapperBackingProperty();
if (backingVar->getFormalAccess() < var->getFormalAccess())
return false;
}
if (auto original = var->getOriginalWrappedProperty(
PropertyWrapperSynthesizedPropertyKind::StorageWrapper)) {
auto backingVar = original->getPropertyWrapperBackingProperty();
if (backingVar->getFormalAccess() < var->getFormalAccess())
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/property_wrapper_coroutine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _ = state1.someValues

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

// CHECK-LABEL: sil hidden [transparent] [ossa] @$s26property_wrapper_coroutine5StateV6valuesSaySSGvM : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String> {
// CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_coroutine5StateV6valuesSaySSGvM : $@yield_once @convention(method) (@inout State) -> @yields @inout Array<String> {
// CHECK: bb0([[STATE:%.*]] : $*State):
// CHECK: debug_value_addr [[STATE]] : $*State, var, name "self", argno {{.*}}
// CHECK: [[BEGIN_ACCESS:%.*]] = begin_access [modify] [unknown] [[STATE]] : $*State
Expand Down
33 changes: 33 additions & 0 deletions test/SILGen/property_wrapper_coroutine_public.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

// Makes sure the modify coroutine is not @_transparent, since it references
// private properties.

public class Store {
@Published public var state: Any
init() {}
}

@propertyWrapper public struct Published<Value> {
public init(wrappedValue: Value) {}
public var wrappedValue: Value {
get {}
set {}
}
public static subscript<EnclosingSelf>(
_enclosingInstance object: EnclosingSelf,
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Published<Value>>)
-> Value where EnclosingSelf : AnyObject {
get {}
set {}
}
public struct Publisher {}
public var projectedValue: Publisher {
mutating get {}
}
}

// CHECK-LABEL: sil [ossa] @$s33property_wrapper_coroutine_public5StoreC5stateypvM : $@yield_once @convention(method) (@guaranteed Store) -> @yields @inout Any {
// 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) -> ())
// CHECK: keypath $ReferenceWritableKeyPath<Store, Published<Any>>, (root $Store; stored_property #Store._state : $Published<Any>)