Skip to content

[Serialization] Only read the underlying type of an opaque type if inlinable #64991

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 2 commits into from
Apr 7, 2023
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
12 changes: 11 additions & 1 deletion lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3886,7 +3886,17 @@ class DeclDeserializer {
opaqueDecl->setGenericSignature(genericSig);
else
opaqueDecl->setGenericSignature(GenericSignature());
if (underlyingTypeSubsID) {

auto *AFD = dyn_cast<AbstractFunctionDecl>(namingDecl);
if (MF.getResilienceStrategy() == ResilienceStrategy::Resilient &&
!MF.FileContext->getParentModule()->isMainModule() &&
AFD && AFD->getResilienceExpansion() != ResilienceExpansion::Minimal) {
// Do not try to read the underlying type information if the function
// is not inlinable in clients. This reflects the swiftinterface behavior
// in where clients are only aware of the underlying type when the body
// of the function is public.

} else if (underlyingTypeSubsID) {
auto subMapOrError = MF.getSubstitutionMapChecked(underlyingTypeSubsID);
if (!subMapOrError) {
// If the underlying type references internal details, ignore it.
Expand Down
29 changes: 29 additions & 0 deletions test/Serialization/Safety/skip-reading-internal-details.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ public struct PublicStruct {
}
}

// resultBuilder scenario
public protocol V {}

@resultBuilder
public struct VB {
public static func buildExpression<Content>(_ content: Content) -> Content where Content : V { fatalError() }
public static func buildBlock() -> V { fatalError() }
public static func buildBlock<Content>(_ content: Content) -> Content where Content : V { fatalError() }
}

public struct EV : V {
public init () {}
}

@available(SwiftStdlib 5.1, *)
public extension V {
@VB
func opaqueReferencingPrivate() -> some V {
referencedPrivateFunc(v: EV())
}

private func referencedPrivateFunc(v: some V) -> some V { return v }
}

//--- Client.swift

import Lib
Expand All @@ -94,3 +118,8 @@ var x = PublicStruct()

// Trigger a typo correction that reads all members.
x.notAMember() // expected-error {{value of type 'PublicStruct' has no member 'notAMember'}}

if #available(SwiftStdlib 5.1, *) {
let v = EV()
let _ = v.opaqueReferencingPrivate()
}