Skip to content

SIL: Private setters need at least hidden visibility for key paths in more cases. #38525

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
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
8 changes: 4 additions & 4 deletions lib/SIL/IR/SILDeclRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,12 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
auto effectiveAccess = d->getEffectiveAccess();

// Private setter implementations for an internal storage declaration should
// be internal as well, so that a dynamically-writable
// keypath can be formed from other files.
// be at least internal as well, so that a dynamically-writable
// keypath can be formed from other files in the same module.
if (auto accessor = dyn_cast<AccessorDecl>(d)) {
if (accessor->isSetter()
&& accessor->getStorage()->getEffectiveAccess() == AccessLevel::Internal)
effectiveAccess = AccessLevel::Internal;
&& accessor->getStorage()->getEffectiveAccess() >= AccessLevel::Internal)
effectiveAccess = std::max(effectiveAccess, AccessLevel::Internal);
}

switch (effectiveAccess) {
Expand Down
27 changes: 27 additions & 0 deletions test/SILGen/accessors_testing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %target-swift-emit-silgen -parse-as-library -module-name accessors %s | %FileCheck %s
// RUN: %target-swift-emit-silgen -parse-as-library -enable-testing -module-name accessors %s | %FileCheck %s

// rdar://78523318: Ensure that private(set) accessors for internal or more
// visible properties have hidden linkage, because other code inside the module
// needs to reference the setter to form a key path.

public struct Foo {
// CHECK-LABEL: sil hidden [ossa] @$s9accessors3FooV6internSivs
private(set) internal var intern: Int {
get { return 0 }
set {}
}
// CHECK-LABEL: sil hidden [ossa] @$s9accessors3FooV3pubSivs
private(set) public var pub: Int {
get { return 0 }
set {}
}

public mutating func exercise() {
_ = intern
_ = pub
intern = 0
pub = 0
}
}