Skip to content

Commit e632c5e

Browse files
committed
-Add package-cmo check to bypassResilienceInPackage method.
-Fix SILDeclRef getLinkageLimit() for GlobalAccessor to return Limit::None if bypassResilienceInPackage is enabled.
1 parent 2d81d0f commit e632c5e

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

lib/AST/Decl.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,7 +3060,7 @@ bool AbstractStorageDecl::isResilient(ModuleDecl *M,
30603060
case ResilienceExpansion::Maximal:
30613061
if (M == getModuleContext())
30623062
return false;
3063-
// Non-resilient if bypass optimization in package is enabled
3063+
// Access non-resiliently if package optimization is enabled
30643064
if (bypassResilienceInPackage(M))
30653065
return false;
30663066
return isResilient();
@@ -4271,13 +4271,23 @@ bool ValueDecl::hasOpenAccess(const DeclContext *useDC) const {
42714271
}
42724272

42734273
bool ValueDecl::bypassResilienceInPackage(ModuleDecl *accessingModule) const {
4274-
// Client needs to opt in to bypass resilience checks at the use site.
4275-
// Client and the loaded module both need to be in the same package.
4276-
// The loaded module needs to be built from source and opt in to allow
4277-
// non-resilient access.
4278-
return getASTContext().LangOpts.EnableBypassResilienceInPackage &&
4279-
getModuleContext()->inSamePackage(accessingModule) &&
4280-
getModuleContext()->allowNonResilientAccess();
4274+
auto declModule = getModuleContext();
4275+
if (declModule->inSamePackage(accessingModule) &&
4276+
declModule->allowNonResilientAccess()) {
4277+
// If the defining module is built with package-cmo,
4278+
// allow direct access from the use site that belongs
4279+
// to accessingModule (client module).
4280+
if (declModule->isResilient() &&
4281+
declModule->serializePackageEnabled())
4282+
return true;
4283+
4284+
// If not, check if the client can still opt in to
4285+
// have a direct access to this decl from the use
4286+
// site with a flag.
4287+
// FIXME: serialize this flag to Module and get it via accessingModule.
4288+
return getASTContext().LangOpts.EnableBypassResilienceInPackage;
4289+
}
4290+
return false;
42814291
}
42824292

42834293
/// Given the formal access level for using \p VD, compute the scope where
@@ -5134,7 +5144,7 @@ bool NominalTypeDecl::isResilient(ModuleDecl *M,
51345144
// non-resiliently in a maximal context.
51355145
if (M == getModuleContext())
51365146
return false;
5137-
// Non-resilient if bypass optimization in package is enabled
5147+
// Access non-resiliently if package optimization is enabled
51385148
if (bypassResilienceInPackage(M))
51395149
return false;
51405150

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,12 @@ static LinkageLimit getLinkageLimit(SILDeclRef constant) {
460460
case Kind::EnumElement:
461461
return Limit::OnDemand;
462462

463-
case Kind::GlobalAccessor:
464-
return cast<VarDecl>(d)->isResilient() ? Limit::NeverPublic : Limit::None;
463+
case Kind::GlobalAccessor: {
464+
auto varDecl = cast<VarDecl>(d);
465+
return varDecl->isResilient() &&
466+
!varDecl->getModuleContext()->allowNonResilientAccess() ?
467+
Limit::NeverPublic : Limit::None;
468+
}
465469

466470
case Kind::DefaultArgGenerator:
467471
// If the default argument is to be serialized, only use non-ABI public

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,29 +160,23 @@ bool checkResilience(DeclType *D, ModuleDecl *accessingModule,
160160
ResilienceExpansion expansion,
161161
bool isSerializedForPackage) {
162162
auto declModule = D->getModuleContext();
163-
// Explicitly bypassed for debugging with `bypass-resilience-checks`
163+
164+
// For DEBUGGING: this check looks up
165+
// `bypass-resilience-checks`, which is
166+
// an old flag used for debugging, and
167+
// has nothing to do with optimizations.
164168
if (declModule->getBypassResilience())
165169
return false;
166170

167-
// Check whether the function or a decl referenced
168-
// by the function was serialized with package-cmo
169-
// optimization.
170-
// If enabled, resilience expansion for the function
171-
// is maximal (see SILFunction::getResilienceExpansion()).
171+
// If the SIL function containing the decl D is
172+
// [serialized_for_package], package-cmo had been
173+
// enabled in its defining module, so direct access
174+
// from a client module should be allowed.
172175
if (accessingModule != declModule &&
173-
expansion == ResilienceExpansion::Maximal) {
174-
// If the function is [serialized_for_package],
175-
// package-cmo had been enabled in its defining
176-
// module, so direct access should be allowed.
177-
if (isSerializedForPackage)
178-
return false;
179-
// If not, check whether the referenced decl was
180-
// serialized with package-cmo.
181-
if (declModule->isResilient() &&
182-
declModule->serializePackageEnabled() &&
183-
declModule->inSamePackage(accessingModule))
176+
expansion == ResilienceExpansion::Maximal &&
177+
isSerializedForPackage)
184178
return false;
185-
}
179+
186180
return D->isResilient(accessingModule, expansion);
187181
}
188182

0 commit comments

Comments
 (0)