[SILGen] Serialize and give PublicNonABI linkage to property wrapper

generator functions for parameters of public functions.
This commit is contained in:
Holly Borla
2021-02-25 09:13:59 -08:00
parent 99e066683c
commit bea89c6a95
2 changed files with 46 additions and 6 deletions

View File

@@ -248,8 +248,15 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
return forDefinition ? linkage : addExternalToLinkage(linkage);
};
// Function-local declarations have private linkage, unless serialized.
ValueDecl *d = getDecl();
// Property wrapper generators of public functions have PublicNonABI linkage
if (isPropertyWrapperBackingInitializer() && isa<ParamDecl>(d)) {
if (isSerialized())
return maybeAddExternal(SILLinkage::PublicNonABI);
}
// Function-local declarations have private linkage, unless serialized.
DeclContext *moduleContext = d->getDeclContext();
while (!moduleContext->isModuleScopeContext()) {
if (moduleContext->isLocalContext()) {
@@ -488,9 +495,16 @@ IsSerialized_t SILDeclRef::isSerialized() const {
auto *d = getDecl();
// Default argument generators are serialized if the containing
// declaration is public.
if (isDefaultArgGenerator()) {
// Default and property wrapper argument generators are serialized if the
// containing declaration is public.
if (isDefaultArgGenerator() || (isPropertyWrapperBackingInitializer() &&
isa<ParamDecl>(d))) {
if (isPropertyWrapperBackingInitializer()) {
if (auto *func = dyn_cast_or_null<ValueDecl>(d->getDeclContext()->getAsDecl())) {
d = func;
}
}
// Ask the AST if we're inside an @inlinable context.
if (d->getDeclContext()->getResilienceExpansion()
== ResilienceExpansion::Minimal) {

View File

@@ -30,10 +30,10 @@ public func testSimpleWrapperParameter(@Wrapper value: Int) {
_ = $value
// property wrapper backing initializer of value #1 in testSimpleWrapperParameter(value:)
// CHECK: sil private [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
// property wrapper init from projected value of value #1 in testSimpleWrapperParameter(value:)
// CHECK: sil private [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tFACL_SivpfW : $@convention(thin) (Projection<Int>) -> Wrapper<Int>
// getter of $value #1 in testSimpleWrapperParameter(value:)
// CHECK: sil private [ossa] @$s26property_wrapper_parameter26testSimpleWrapperParameter5valueyAA0F0VySiG_tF6$valueL_AA10ProjectionVySiGvg : $@convention(thin) (Wrapper<Int>) -> Projection<Int>
@@ -184,3 +184,29 @@ func testImplicitPropertyWrapper(projection: ProjectionWrapper<Int>) {
// getter of value #1 in closure #2 in implicit closure #2 in testImplicitPropertyWrapper(projection:)
// CHECK: sil private [ossa] @$s26property_wrapper_parameter27testImplicitPropertyWrapper10projectionyAA010ProjectionG0VySiG_tFSi_AFtAFcfu0_Si_AFtAFcfU0_5valueL_Sivg : $@convention(thin) () -> Int
}
@propertyWrapper
public struct PublicWrapper<T> {
public var wrappedValue: T
public init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}
public var projectedValue: PublicWrapper<T> {
return self
}
public init(projectedValue: PublicWrapper<T>) {
self.wrappedValue = projectedValue.wrappedValue
}
}
// CHECK-LABEL: sil [ossa] @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tF : $@convention(thin) (@guaranteed PublicWrapper<String>) -> ()
public func publicFunc(@PublicWrapper value: String) {
// property wrapper backing initializer of value #1 in publicFunc(value:)
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfP : $@convention(thin) (@owned String) -> @owned PublicWrapper<String>
// property wrapper init from projected value of value #1 in publicFunc(value:)
// CHECK: sil non_abi [serialized] [ossa] @$s26property_wrapper_parameter10publicFunc5valueyAA13PublicWrapperVySSG_tFACL_SSvpfW : $@convention(thin) (@owned PublicWrapper<String>) -> @owned PublicWrapper<String>
}