@@ -153,13 +153,28 @@ static bool isArchetypeValidInFunction(ArchetypeType *A, const SILFunction *F) {
153153
154154namespace {
155155
156- // / When resilience is bypassed, direct access is legal, but the decls are still
157- // / resilient.
156+ // / When resilience is bypassed for debugging or package serialization is enabled,
157+ // / direct access is legal, but the decls are still resilient.
158158template <typename DeclType>
159159bool checkResilience (DeclType *D, ModuleDecl *M,
160160 ResilienceExpansion expansion) {
161- return !D->getModuleContext ()->getBypassResilience () &&
162- D->isResilient (M, expansion);
161+ auto refDeclModule = D->getModuleContext ();
162+ // Explicitly bypassed for debugging with `bypass-resilience-checks`
163+ if (refDeclModule->getBypassResilience ())
164+ return false ;
165+
166+ // If package serialization is enabled with `experimental-package-cmo`,
167+ // decls can be serialized in a resiliently built module. In such case,
168+ // a direct access should be allowed.
169+ auto packageSerialized = expansion == ResilienceExpansion::Minimal &&
170+ refDeclModule->isResilient () &&
171+ refDeclModule->allowNonResilientAccess () &&
172+ refDeclModule->serializePackageEnabled () &&
173+ refDeclModule->inSamePackage (M);
174+ if (packageSerialized)
175+ return false ;
176+
177+ return D->isResilient (M, expansion);
163178}
164179
165180bool checkTypeABIAccessible (SILFunction const &F, SILType ty) {
0 commit comments