Skip to content

Commit 4152f34

Browse files
committed
Update canBeSerializedIntoCaller / SILVerifier / test
1 parent 0125985 commit 4152f34

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

lib/SIL/IR/SILFunction.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -930,28 +930,24 @@ bool SILFunction::hasName(const char *Name) const {
930930

931931
bool SILFunction::canBeSerializedIntoCaller(
932932
std::optional<SerializedKind_t> callerSerializedKind) const {
933-
// If Package-CMO is enabled, we serialize package, public,
934-
// and @usableFromInline decls as [serialized_for_package].
935-
// They must not, however, leak into @inlinable functions
936-
// outside of their defining module. The following contains
937-
// the rule of inlinability of a callee (e.g. serialized
938-
// in a library module with Package-CMO) into a caller (e.g.
939-
// an @inlinable function in a client module).
940-
941933
switch (getSerializedKind()) {
942-
// If this callee is not serialized, caller must also
943-
// be _not_ serialized for this callee to be inlined
944-
// into the caller.
934+
// If this callee is not serialized, it can't be inlined
935+
// into the caller unless Package-CMO is enabled; if so,
936+
// the callee should have package or more visibility and
937+
// the caller must also be _not_ serialized for this callee
938+
// to be inlined.
945939
case IsNotSerialized:
946-
return false;
947-
// pcmo TODO: should we return the following instead?
948-
// return callerSerializedKind.has_value() &&
949-
// callerSerializedKind.value() == IsNotSerialized &&
950-
// getModule().getSwiftModule()->serializePackageEnabled() &&
951-
// getModule().getSwiftModule()->isResilient() &&
952-
// hasPublicOrPackageVisibility(getLinkage(), true);
953-
// If this callee is serialized_for_package, the caller
954-
// must be either not serialized or serialized_for_package
940+
return callerSerializedKind.has_value() &&
941+
callerSerializedKind.value() == IsNotSerialized &&
942+
getModule().getSwiftModule()->serializePackageEnabled() &&
943+
getModule().getSwiftModule()->isResilient() &&
944+
hasPublicOrPackageVisibility(getLinkage(), true);
945+
// If Package-CMO is enabled, we serialize package, public,
946+
// and @usableFromInline decls as [serialized_for_package].
947+
// They must not, however, leak into @inlinable functions
948+
// outside of their defining module that are [serialized].
949+
// If this callee is [serialized_for_package], the caller
950+
// must be either non-serialized or [serialized_for_package]
955951
// for this callee to be inlined into the caller.
956952
case IsSerializedForPackage:
957953
return callerSerializedKind.has_value() &&

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
24492449

24502450
// A direct reference to a non-public or shared but not fragile function
24512451
// from a fragile function is an error.
2452-
if (F.isSerialized()) {
2452+
if (!F.isNotSerialized()) {
24532453
require((SingleFunction && RefF->isExternalDeclaration()) ||
24542454
RefF->hasValidLinkageForFragileRef(F.getSerializedKind()),
24552455
"function_ref inside fragile function cannot "
@@ -7037,7 +7037,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
70377037
SILModule &mod = F->getModule();
70387038
bool embedded = mod.getASTContext().LangOpts.hasFeature(Feature::Embedded);
70397039

7040-
require(!F->isSerialized() || !mod.isSerialized() || mod.isParsedAsSerializedSIL(),
7040+
require(F->isNotSerialized() || !mod.isSerialized() || mod.isParsedAsSerializedSIL(),
70417041
"cannot have a serialized function after the module has been serialized");
70427042

70437043
switch (F->getLinkage()) {
@@ -7058,7 +7058,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
70587058
case SILLinkage::Private:
70597059
require(F->isDefinition() || F->hasForeignBody(),
70607060
"internal/private function must have a body");
7061-
require(!F->isSerialized() || embedded,
7061+
require(F->isNotSerialized() || embedded,
70627062
"internal/private function cannot be serialized or serializable");
70637063
break;
70647064
case SILLinkage::PublicExternal:
@@ -7406,7 +7406,7 @@ void SILWitnessTable::verify(const SILModule &M) const {
74067406
if (F) {
74077407
// If a SILWitnessTable is going to be serialized, it must only
74087408
// reference public or serializable functions.
7409-
if (isSerialized()) { // pcmo TODO: change to !isNotSerialized()
7409+
if (!isNotSerialized()) {
74107410
assert(F->hasValidLinkageForFragileRef(getSerializedKind()) &&
74117411
"Fragile witness tables should not reference "
74127412
"less visible functions.");

test/SILOptimizer/package-cmo-resilient-mode.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,22 @@ import Lib
110110
// CHECK-MAIN-COMMON-NEXT: [[FNL_PKG_LOAD:%.*]] = load [[FNL_PKG_ACCESS]] : $*Int
111111
// CHECK-MAIN-COMMON-NEXT: store [[FNL_PKG_LOAD]] to {{.*}} : $*Int
112112

113-
// CHECK-MAIN-RES-DAG: sil public_external [serialized_for_package] @$s3Lib8PubKlassCyACSicfC : $@convention(method) (Int, @thick PubKlass.Type) -> @owned PubKlass {
113+
// CHECK-MAIN-RES-DAG: sil public_external @$s3Lib8PubKlassCyACSicfC : $@convention(method) (Int, @thick PubKlass.Type) -> @owned PubKlass {
114114
// CHECK-MAIN-NONRES-DAG: sil public_external @$s3Lib8PubKlassCyACSicfC : $@convention(method) (Int, @thick PubKlass.Type) -> @owned PubKlass {
115115

116-
// CHECK-MAIN-RES-DAG: sil package_external [serialized_for_package] @$s3Lib8PkgKlassCyACSicfC : $@convention(method) (Int, @thick PkgKlass.Type) -> @owned PkgKlass {
116+
// CHECK-MAIN-RES-DAG: sil package_external @$s3Lib8PkgKlassCyACSicfC : $@convention(method) (Int, @thick PkgKlass.Type) -> @owned PkgKlass {
117117
// CHECK-MAIN-NONRES-DAG: sil package_external @$s3Lib8PkgKlassCyACSicfC : $@convention(method) (Int, @thick PkgKlass.Type) -> @owned PkgKlass {
118118

119-
// CHECK-MAIN-RES-DAG: sil public_external [serialized_for_package] @$s3Lib13FinalPubKlassCyACSicfC : $@convention(method) (Int, @thick FinalPubKlass.Type) -> @owned FinalPubKlass {
119+
// CHECK-MAIN-RES-DAG: sil public_external @$s3Lib13FinalPubKlassCyACSicfC : $@convention(method) (Int, @thick FinalPubKlass.Type) -> @owned FinalPubKlass {
120120
// CHECK-MAIN-NONRES-DAG: sil public_external @$s3Lib13FinalPubKlassCyACSicfC : $@convention(method) (Int, @thick FinalPubKlass.Type) -> @owned FinalPubKlass {
121121

122-
// CHECK-MAIN-RES-DAG: sil public_external [serialized_for_package] @$s3Lib8PubKlassC4dataSivs : $@convention(method) (Int, @guaranteed PubKlass) -> () {
122+
// CHECK-MAIN-RES-DAG: sil public_external @$s3Lib8PubKlassC4dataSivs : $@convention(method) (Int, @guaranteed PubKlass) -> () {
123123
// CHECK-MAIN-NONRES-DAG: sil public_external [transparent] @$s3Lib8PubKlassC4dataSivs : $@convention(method) (Int, @guaranteed PubKlass) -> () {
124124

125-
// CHECK-MAIN-RES-DAG: sil package_external [serialized_for_package] @$s3Lib13FinalPkgKlassCyACSicfC : $@convention(method) (Int, @thick FinalPkgKlass.Type) -> @owned FinalPkgKlass {
125+
// CHECK-MAIN-RES-DAG: sil package_external @$s3Lib13FinalPkgKlassCyACSicfC : $@convention(method) (Int, @thick FinalPkgKlass.Type) -> @owned FinalPkgKlass {
126126
// CHECK-MAIN-NONRES-DAG: sil package_external @$s3Lib13FinalPkgKlassCyACSicfC : $@convention(method) (Int, @thick FinalPkgKlass.Type) -> @owned FinalPkgKlass {
127127

128-
// CHECK-MAIN-RES-DAG: sil package_external [serialized_for_package] @$s3Lib8PkgKlassC4dataSivs : $@convention(method) (Int, @guaranteed PkgKlass) -> () {
128+
// CHECK-MAIN-RES-DAG: sil package_external @$s3Lib8PkgKlassC4dataSivs : $@convention(method) (Int, @guaranteed PkgKlass) -> () {
129129
// CHECK-MAIN-NONRES-DAG: sil package_external [transparent] @$s3Lib8PkgKlassC4dataSivs : $@convention(method) (Int, @guaranteed PkgKlass) -> () {
130130

131131
// CHECK-MAIN-COMMON: sil_vtable PubKlass {

0 commit comments

Comments
 (0)