Skip to content

Add a package serialization bit to Module for SIL verifier in Package CMO mode. #72937

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 3 commits into from
Apr 22, 2024

Conversation

elsh
Copy link
Contributor

@elsh elsh commented Apr 9, 2024

During Package CMO, SIL cloning happens during which
SILOptions::EnableSerializePackage info is lost.

SILVerifier needs this info to determine whether resilience
can be bypassed for decls serialized in a resiliently
built module when Package CMO optimization enabled.

This PR adds SerializePackageEnabled bit to Module format
and uses that in SILVerifier.

Resolves rdar://126157356

@elsh
Copy link
Contributor Author

elsh commented Apr 9, 2024

@swift-ci smoke test

// built); this means package serialization was enabled and direct
// access should be allowed.
auto serializedInResilientMode =
expansion == ResilienceExpansion::Minimal && isSerialized;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resilience expansion of a ‘serialized’ function is always minimal. (See getResilienceExpansion() in SILFunction.h)

by adding this condition (‘isSerialized()‘) we will by pass the check even in regular resilient mode (no package cmo enabled). I don’t think this is desirable.

Can you restrict this bypass to only when the current module is in the same package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to check for that as well as whether module was built resiliently when serialized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of:

auto serializedInResilientModule = M->isResilient() &&
                                     isSerialized &&
                                     D->getModuleContext()->inSamePackage(M);

I think we want to test the scenario where the Decl D is in a module that allows non resilient access from within the package boundary and we are accessing it from within the package boundary via a binary .swiftmodule (build from source). There is two cases:

  • within the same module (M == D, module was compiled from source and allows resilient access)
  • the function was deserialized and is now in a different module (M != D, D allows non-resilience access, M and D are in the same package and M has bypass resilience and enabled)

I think that would make the check something like:

auto accessingModule = M;
bool byPassResilienceCheck =
  (D->getModuleContext()->allowNonResilientAccess() && D == M) || // Same module case
  (F.getASTContext().LangOpts.EnableBypassResilienceInPackage && // Different modules case
   D->getModuleContext()->inSamePackage(M) &&                  
   D->getModuleContext()->allowNonResilientAccess());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to add SerializePackageEnabled bit to Module; the SILOpts.EnableSerializePackage info gets lost during SIL cloning stage of Package CMO, so it needed to be serialized to the binary module. It's added to this SILVerifier check function along with others we discussed.

@elsh elsh force-pushed the elsh/pkg-sil-verify branch from b51b1fa to 03ab389 Compare April 10, 2024 05:21
@elsh
Copy link
Contributor Author

elsh commented Apr 10, 2024

@swift-ci smoke test

SILOptions::EnableSerializePackage info is lost.

SILVerifier needs this info to determine whether resilience
can be bypassed for decls serialized in a resiliently
built module when Package CMO optimization enabled.

This PR adds SerializePackageEnabled bit to Module format
and uses that in SILVerifier.

Resolves rdar://126157356
@elsh elsh force-pushed the elsh/pkg-sil-verify branch from 03ab389 to fbb3382 Compare April 18, 2024 05:46
@elsh elsh requested review from artemcm, hborla and xedin as code owners April 18, 2024 05:46
@elsh
Copy link
Contributor Author

elsh commented Apr 18, 2024

@swift-ci smoke test

@elsh elsh changed the title Package CMO needs SIL verifier to allow direct access to decl in serialized SIL in resilient mode. Add a package optimization bit to Module for SIL verifier in Package CMO mode. Apr 18, 2024
@elsh elsh changed the title Add a package optimization bit to Module for SIL verifier in Package CMO mode. Add a package serialization bit to Module for SIL verifier in Package CMO mode. Apr 18, 2024
@elsh
Copy link
Contributor Author

elsh commented Apr 18, 2024

@swift-ci smoke test

@elsh elsh merged commit 3f04710 into main Apr 22, 2024
@elsh elsh deleted the elsh/pkg-sil-verify branch April 22, 2024 19:44
Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants