Skip to content

[6.0] [PackageCMO] Initial change to allow loadable types in serialized function with Package CMO #73868

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 1 addition & 5 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,7 @@ class SILFunction
return getLoweredFunctionType()->getRepresentation();
}

ResilienceExpansion getResilienceExpansion() const {
return (isSerialized()
? ResilienceExpansion::Minimal
: ResilienceExpansion::Maximal);
}
ResilienceExpansion getResilienceExpansion() const;

// Returns the type expansion context to be used inside this function.
TypeExpansionContext getTypeExpansionContext() const {
Expand Down
17 changes: 17 additions & 0 deletions lib/SIL/IR/SILFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,23 @@ bool SILFunction::isNoReturnFunction(TypeExpansionContext context) const {
.isNoReturnFunction(getModule(), context);
}

ResilienceExpansion SILFunction::getResilienceExpansion() const {
// If package serialization is enabled, we can safely
// assume that the defining .swiftmodule is built from
// source and is never used outside of its package;
// Even if the module is built resiliently, return
// maximal expansion here so aggregate types can be
// loadable in the same resilient domain (from a client
// module in the same package.
if (getModule().getSwiftModule()->serializePackageEnabled() &&
getModule().getSwiftModule()->isResilient())
return ResilienceExpansion::Maximal;

return (isSerialized()
? ResilienceExpansion::Minimal
: ResilienceExpansion::Maximal);
}

const TypeLowering &
SILFunction::getTypeLowering(AbstractionPattern orig, Type subst) {
return getModule().Types.getTypeLowering(orig, subst,
Expand Down
12 changes: 10 additions & 2 deletions lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2324,17 +2324,25 @@ namespace {
if (D->isResilient()) {
// If the type is resilient and defined in our module, make a note of
// that, since our lowering now depends on the resilience expansion.
bool sameModule = (D->getModuleContext() == &TC.M);
auto declModule = D->getModuleContext();
bool sameModule = (declModule == &TC.M);
if (sameModule)
properties.addSubobject(RecursiveProperties::forResilient());

// If the type is in a different module, or if we're using a minimal
// expansion, the type is address only and completely opaque to us.
// However, this is not true if the different module is in the same
// package and package serialization is enabled (resilience expansion
// is maximal), e.g. in case of package-cmo.
//
// Note: if the type is in a different module, the lowering does
// not depend on the resilience expansion, so we do not need to set
// the isResilient() flag above.
if (!sameModule || Expansion.getResilienceExpansion() ==
bool serializedPackage = declModule->inSamePackage(&TC.M) &&
declModule->isResilient() &&
declModule->serializePackageEnabled();
if ((!sameModule && !serializedPackage) ||
Expansion.getResilienceExpansion() ==
ResilienceExpansion::Minimal) {
properties.addSubobject(RecursiveProperties::forOpaque());
return true;
Expand Down
5 changes: 2 additions & 3 deletions lib/SILOptimizer/IPO/CrossModuleOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ bool CrossModuleOptimization::canSerializeFunction(
/// Returns true if \p inst can be serialized.
///
/// If \p inst is a function_ref, recursively visits the referenced function.
bool CrossModuleOptimization::canSerializeInstruction(SILInstruction *inst,
FunctionFlags &canSerializeFlags, int maxDepth) {

bool CrossModuleOptimization::canSerializeInstruction(
SILInstruction *inst, FunctionFlags &canSerializeFlags, int maxDepth) {
// First check if any result or operand types prevent serialization.
for (SILValue result : inst->getResults()) {
if (!canSerializeType(result->getType()))
Expand Down
Loading