File tree Expand file tree Collapse file tree 4 files changed +42
-4
lines changed
test/Serialization/Safety Expand file tree Collapse file tree 4 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -3294,6 +3294,14 @@ class OpaqueTypeDecl final :
3294
3294
};
3295
3295
}
3296
3296
3297
+ // / Should we consider the underlying type as visible to clients outside of
3298
+ // / the module?
3299
+ // /
3300
+ // / This is used during deserialization to determine if this information
3301
+ // / can be read reliably. We should be careful to what data is accessed by
3302
+ // / this service as \c this may not be fully consistent.
3303
+ bool exportUnderylingTypeToClients () const ;
3304
+
3297
3305
// / The substitutions that map the generic parameters of the opaque type to
3298
3306
// / the unique underlying types, when that information is known.
3299
3307
llvm::Optional<SubstitutionMap> getUniqueUnderlyingTypeSubstitutions () const {
Original file line number Diff line number Diff line change @@ -9464,6 +9464,19 @@ GenericTypeParamDecl *OpaqueTypeDecl::getExplicitGenericParam(
9464
9464
return genericParamType->getDecl ();
9465
9465
}
9466
9466
9467
+ bool OpaqueTypeDecl::exportUnderylingTypeToClients () const {
9468
+ auto mod = getDeclContext ()->getParentModule ();
9469
+ if (mod->getResilienceStrategy () != ResilienceStrategy::Resilient)
9470
+ return true ;
9471
+
9472
+ ValueDecl *namingDecl = getNamingDecl ();
9473
+ if (namingDecl->getAttrs ().hasAttribute <AlwaysEmitIntoClientAttr>() ||
9474
+ namingDecl->getAttrs ().hasAttribute <InlinableAttr>())
9475
+ return true ;
9476
+
9477
+ return false ;
9478
+ }
9479
+
9467
9480
llvm::Optional<unsigned >
9468
9481
OpaqueTypeDecl::getAnonymousOpaqueParamOrdinal (TypeRepr *repr) const {
9469
9482
assert (NamingDeclAndHasOpaqueReturnTypeRepr.getInt () &&
Original file line number Diff line number Diff line change @@ -4244,14 +4244,17 @@ class DeclDeserializer {
4244
4244
else
4245
4245
opaqueDecl->setGenericSignature (GenericSignature ());
4246
4246
4247
- auto *AFD = dyn_cast<AbstractFunctionDecl>(namingDecl);
4248
- if (MF.getResilienceStrategy () == ResilienceStrategy::Resilient &&
4249
- !MF.FileContext ->getParentModule ()->isMainModule () &&
4250
- AFD && AFD->getResilienceExpansion () != ResilienceExpansion::Minimal) {
4247
+ if (!MF.FileContext ->getParentModule ()->isMainModule () &&
4248
+ !opaqueDecl->exportUnderylingTypeToClients ()) {
4251
4249
// Do not try to read the underlying type information if the function
4252
4250
// is not inlinable in clients. This reflects the swiftinterface behavior
4253
4251
// in where clients are only aware of the underlying type when the body
4254
4252
// of the function is public.
4253
+ LLVM_DEBUG (
4254
+ llvm::dbgs () << " Ignoring underlying information for opaque type of '" ;
4255
+ llvm::dbgs () << namingDecl->getName ();
4256
+ llvm::dbgs () << " '\n " ;
4257
+ );
4255
4258
4256
4259
} else if (underlyingTypeSubsID) {
4257
4260
auto subMapOrError = MF.getSubstitutionMapChecked (underlyingTypeSubsID);
Original file line number Diff line number Diff line change 68
68
// SAFE: Skipping unsafe deserialization: 'fileprivateFunc()'
69
69
// SAFE: Skipping unsafe deserialization: 'refToIOI()'
70
70
71
+ // NEEDED: Ignoring underlying information for opaque type of 'opaqueReferencingPrivate()'
72
+ // NEEDED: Ignoring underlying information for opaque type of 'opaqueReferencingPrivateVar'
73
+ // NEEDED: Ignoring underlying information for opaque type of 'subscript(_:)'
74
+
71
75
//--- HiddenLib.swift
72
76
73
77
public struct HiddenStruct {
@@ -113,6 +117,14 @@ public extension V {
113
117
}
114
118
115
119
private func referencedPrivateFunc( v: some V ) -> some V { return v }
120
+
121
+ var opaqueReferencingPrivateVar : some V {
122
+ referencedPrivateFunc ( v: EV ( ) )
123
+ }
124
+
125
+ subscript( v: some V ) -> some V {
126
+ referencedPrivateFunc ( v: v)
127
+ }
116
128
}
117
129
118
130
//--- Client.swift
@@ -127,4 +139,6 @@ x.notAMember() // expected-error {{value of type 'PublicStruct' has no member 'n
127
139
if #available( SwiftStdlib 5 . 1 , * ) {
128
140
let v = EV ( )
129
141
let _ = v. opaqueReferencingPrivate ( )
142
+ let _ = v. opaqueReferencingPrivateVar
143
+ let _ = v [ v]
130
144
}
You can’t perform that action at this time.
0 commit comments