From fd07578b299dc5e446b297a27c90796e96a0e216 Mon Sep 17 00:00:00 2001 From: Ellie Shin Date: Fri, 31 May 2024 13:22:03 -0700 Subject: [PATCH 1/2] Package CMO fixes. * Do not use [serialized_for_package] for witness method before Package CMO. * Update v-table and witness-table and their entry serialization. -- Allow non-serialized but visible entries in a serialized table so they can be optimized by other SIL opt passes. * Only serialize MethodInst if it has the right visibility. Resolves rdar://129089105&129088935 --- lib/SIL/IR/SILWitnessTable.cpp | 4 +- .../IPO/CrossModuleOptimization.cpp | 105 +++++-- .../package_bypass_resilience_class.swift | 289 ++++++++++++------ .../package-cmo-resilient-mode.swift | 16 +- .../package-cmo-skip-internal.swift | 104 +++++++ 5 files changed, 380 insertions(+), 138 deletions(-) create mode 100644 test/SILOptimizer/package-cmo-skip-internal.swift diff --git a/lib/SIL/IR/SILWitnessTable.cpp b/lib/SIL/IR/SILWitnessTable.cpp index f933e92490f11..e9bb35b940e17 100644 --- a/lib/SIL/IR/SILWitnessTable.cpp +++ b/lib/SIL/IR/SILWitnessTable.cpp @@ -184,9 +184,7 @@ SerializedKind_t SILWitnessTable::conformanceSerializedKind( auto *nominal = conformance->getDeclContext()->getSelfNominalTypeDecl(); if (nominal->getEffectiveAccess() >= accessLevelToCheck) - return optInPackage && - conformance->getDeclContext()->getParentModule()->isResilient() ? - IsSerializedForPackage : IsSerialized; + return IsSerialized; return IsNotSerialized; } diff --git a/lib/SILOptimizer/IPO/CrossModuleOptimization.cpp b/lib/SILOptimizer/IPO/CrossModuleOptimization.cpp index 3156d25ed7e65..83ff5f674bfd7 100644 --- a/lib/SILOptimizer/IPO/CrossModuleOptimization.cpp +++ b/lib/SILOptimizer/IPO/CrossModuleOptimization.cpp @@ -67,12 +67,14 @@ class CrossModuleOptimization { bool everything; typedef llvm::DenseMap FunctionFlags; + FunctionFlags canSerializeFlags; public: CrossModuleOptimization(SILModule &M, bool conservative, bool everything) : M(M), conservative(conservative), everything(everything) { } - void serializeFunctionsInModule(ArrayRef functions); + void trySerializeFunctions(ArrayRef functions); + void serializeFunctionsInModule(SILPassManager *manager); void serializeTablesInModule(); private: @@ -251,12 +253,8 @@ static bool isReferenceSerializeCandidate(SILGlobalVariable *G, } /// Select functions in the module which should be serialized. -void CrossModuleOptimization::serializeFunctionsInModule( +void CrossModuleOptimization::trySerializeFunctions( ArrayRef functions) { - FunctionFlags canSerializeFlags; - - // The passed functions are already ordered bottom-up so the most - // nested referenced function is checked first. for (SILFunction *F : functions) { if (isSerializeCandidate(F, M.getOptions()) || everything) { if (canSerializeFunction(F, canSerializeFlags, /*maxDepth*/ 64)) { @@ -266,31 +264,81 @@ void CrossModuleOptimization::serializeFunctionsInModule( } } +void CrossModuleOptimization::serializeFunctionsInModule(SILPassManager *manager) { + // Reorder SIL funtions in the module bottom up so we can serialize + // the most nested referenced functions first and avoid unnecessary + // recursive checks. + BasicCalleeAnalysis *BCA = manager->getAnalysis(); + BottomUpFunctionOrder BottomUpOrder(M, BCA); + auto bottomUpFunctions = BottomUpOrder.getFunctions(); + trySerializeFunctions(bottomUpFunctions); +} + void CrossModuleOptimization::serializeTablesInModule() { if (!M.getSwiftModule()->serializePackageEnabled()) return; for (const auto &vt : M.getVTables()) { - if (vt->isNotSerialized() && + if (vt->getSerializedKind() != getRightSerializedKind(M) && vt->getClass()->getEffectiveAccess() >= AccessLevel::Package) { - vt->setSerializedKind(getRightSerializedKind(M)); + // This checks if a vtable entry is not serialized and attempts to + // serialize (and its references) if they have the right visibility. + // This should not be necessary but is added to ensure all applicable + // symbols are serialized. Whether serialized or not is cached so + // this check shouldn't be expensive. + auto unserializedClassMethodRange = llvm::make_filter_range(vt->getEntries(), [&](auto &entry) { + return entry.getImplementation()->getSerializedKind() != getRightSerializedKind(M); + }); + std::vector classMethodsToSerialize; + llvm::transform(unserializedClassMethodRange, + std::back_inserter(classMethodsToSerialize), + [&](auto entry) { + return entry.getImplementation(); + }); + trySerializeFunctions(classMethodsToSerialize); + + bool containsInternal = llvm::any_of(classMethodsToSerialize, [&](auto &method) { + // If the entry is internal, vtable should not be serialized. + // However, if the entry is not serialized but has the right + // visibility, it can still be referenced, thus the vtable + // should serialized. + return !method->hasValidLinkageForFragileRef(getRightSerializedKind(M)); + }); + if (!containsInternal) + vt->setSerializedKind(getRightSerializedKind(M)); } } + // Witness thunks are not serialized, so serialize them here. for (auto &wt : M.getWitnessTables()) { - if (wt.isNotSerialized() && + if (wt.getSerializedKind() != getRightSerializedKind(M) && hasPublicOrPackageVisibility(wt.getLinkage(), /*includePackage*/ true)) { - for (auto &entry : wt.getEntries()) { - // Witness thunks are not serialized, so serialize them here. - if (entry.getKind() == SILWitnessTable::Method && - entry.getMethodWitness().Witness->isNotSerialized() && - isSerializeCandidate(entry.getMethodWitness().Witness, - M.getOptions())) { - entry.getMethodWitness().Witness->setSerializedKind(getRightSerializedKind(M)); - } - } - // Then serialize the witness table itself. - wt.setSerializedKind(getRightSerializedKind(M)); + // This checks if a wtable entry is not serialized and attempts to + // serialize (and its references) if they have the right visibility. + // This should not be necessary but is added to ensure all applicable + // symbols are serialized. Whether serialized or not is cached so + // this check shouldn't be expensive. + auto unserializedWTMethodRange = llvm::make_filter_range(wt.getEntries(), [&](auto &entry) { + return entry.getKind() == SILWitnessTable::Method && + entry.getMethodWitness().Witness->getSerializedKind() != getRightSerializedKind(M); + }); + std::vector wtMethodsToSerialize; + llvm::transform(unserializedWTMethodRange, + std::back_inserter(wtMethodsToSerialize), + [&](auto entry) { + return entry.getMethodWitness().Witness; + }); + trySerializeFunctions(wtMethodsToSerialize); + + bool containsInternal = llvm::any_of(wtMethodsToSerialize, [&](auto &method) { + // If the entry is internal, wtable should not be serialized. + // However, if the entry is not serialized but has the right + // visibility, it can still be referenced, thus the vtable + // should serialized. + return !method->hasValidLinkageForFragileRef(getRightSerializedKind(M)); + }); + if (!containsInternal) + wt.setSerializedKind(getRightSerializedKind(M)); } } } @@ -441,7 +489,13 @@ bool CrossModuleOptimization::canSerializeInstruction( return canUse; } if (auto *MI = dyn_cast(inst)) { - return !MI->getMember().isForeign; + // If a class_method or witness_method is internal, it can't + // be serialized. + auto member = MI->getMember(); + auto methodAccessScope = member.getDecl()->getFormalAccessScope(nullptr, + /*treatUsableFromInlineAsPublic*/ true); + return methodAccessScope.isPublicOrPackage() && + !member.isForeign; } if (auto *REAI = dyn_cast(inst)) { // In conservative mode, we don't support class field accesses of non-public @@ -855,14 +909,7 @@ class CrossModuleOptimizationPass: public SILModuleTransform { } CrossModuleOptimization CMO(M, conservative, everything); - - // Reorder SIL funtions in the module bottom up so we can serialize - // the most nested referenced functions first and avoid unnecessary - // recursive checks. - BasicCalleeAnalysis *BCA = PM->getAnalysis(); - BottomUpFunctionOrder BottomUpOrder(M, BCA); - auto BottomUpFunctions = BottomUpOrder.getFunctions(); - CMO.serializeFunctionsInModule(BottomUpFunctions); + CMO.serializeFunctionsInModule(PM); // Serialize SIL v-tables and witness-tables if package-cmo is enabled. CMO.serializeTablesInModule(); diff --git a/test/IRGen/package_bypass_resilience_class.swift b/test/IRGen/package_bypass_resilience_class.swift index 3319148afd666..16f1776f81c06 100644 --- a/test/IRGen/package_bypass_resilience_class.swift +++ b/test/IRGen/package_bypass_resilience_class.swift @@ -1,6 +1,7 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t +/// Build with -experimental-allow-non-resilient-access // RUN: %target-build-swift %t/Core.swift \ // RUN: -module-name=Core -package-name Pkg \ // RUN: -Xfrontend -experimental-allow-non-resilient-access \ @@ -9,142 +10,234 @@ // RUN: -emit-tbd -emit-tbd-path %t/libCore.tbd \ // RUN: -Xfrontend -tbd-install_name=libCore.dylib -Xfrontend -validate-tbd-against-ir=all -// RUN: %FileCheck %s --check-prefix=CHECK-IR < %t/Core.ir -// RUN: %FileCheck %s --check-prefix=CHECK-TBD < %t/libCore.tbd +/// Build without -experimental-allow-non-resilient-access +// RUN: %target-build-swift %t/Core.swift \ +// RUN: -module-name=Core -package-name Pkg \ +// RUN: -enable-library-evolution -O -wmo \ +// RUN: -emit-ir -o %t/CoreRes.ir \ +// RUN: -emit-tbd -emit-tbd-path %t/libCoreRes.tbd \ +// RUN: -Xfrontend -tbd-install_name=libCoreRes.dylib -Xfrontend -validate-tbd-against-ir=all + +// RUN: %FileCheck %s --check-prefixes=CHECK-COMMON,CHECK-OPT < %t/Core.ir +// RUN: %FileCheck %s --check-prefixes=CHECK-TBD-COMMON,CHECK-TBD-OPT < %t/libCore.tbd +// RUN: %FileCheck %s --check-prefixes=CHECK-COMMON,CHECK-RES < %t/CoreRes.ir +// RUN: %FileCheck %s --check-prefixes=CHECK-TBD-COMMON,CHECK-TBD-RES < %t/libCoreRes.tbd //--- Core.swift -final public class Pub {} +// CHECK-RES-NOT: s4Core8UFIKlassC6varUfiSSSgvpfi +// CHECK-RES-NOT: s4Core3FooC02myB0AA3PubCSgvpfi -package class Foo { - package var myFoo: Pub? -} +final public class Pub { + // type metadata accessor for Core.Pub + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc %swift.metadata_response @"$s4Core3PubCMa"({{i32|i64}} %0) -final package class Bar { - package var myBar: Pub? + // method lookup function for Core.Pub + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3PubCMu"(ptr %0, ptr %1) + + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3PubCfd"(ptr readnone returned swiftself %0) + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3PubCfD"(ptr swiftself %0) } -// key path getter for Core.Foo.myFoo -// CHECK-IR-DAG: define linkonce_odr hidden swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvpACTK" +package class Foo { + // key path getter for Core.Foo.myFoo + // CHECK-COMMON-DAG: define linkonce_odr hidden swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvpACTK" -// key path setter for Core.Foo.myFoo -// CHECK-IR-DAG: define linkonce_odr hidden swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvpACTk" + // key path setter for Core.Foo.myFoo + // CHECK-COMMON-DAG: define linkonce_odr hidden swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvpACTk" -// variable initialization expression of Core.Foo.myFoo -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvpfi"() #0 { + // variable initialization expression of Core.Foo.myFoo + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvpfi"() #0 { -// Core.Foo.myFoo.getter -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvg"(ptr swiftself %0) + // Core.Foo.myFoo.getter + // CHECK-RES-DAG: define hidden {{.*}}swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvg"(ptr swiftself %0) + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvg"(ptr swiftself %0) -// merged Core.Foo.myFoo.getter -// CHECK-IR-DAG: define internal swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvgTm"(ptr swiftself %0) + // merged Core.Foo.myFoo.getter + // CHECK-COMMON-DAG: define internal swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvgTm"(ptr swiftself %0) -// Core.Foo.myFoo.setter -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvs"({{i32|i64}} %0, ptr swiftself %1) #1 { + // Core.Foo.myFoo.setter + // CHECK-RES-DAG: define hidden {{.*}}swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvs"({{i32|i64}} %0, ptr swiftself %1) #1 { + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvs"({{i32|i64}} %0, ptr swiftself %1) #1 { -// merged Core.Foo.myFoo.setter -// CHECK-IR-DAG: define internal swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvsTm"({{i32|i64}} %0, ptr swiftself %1) + // merged Core.Foo.myFoo.setter + // CHECK-COMMON-DAG: define internal swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvsTm"({{i32|i64}} %0, ptr swiftself %1) -// Core.Foo.myFoo.modify -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc { ptr, ptr } @"$s4Core3FooC02myB0AA3PubCSgvM" + // Core.Foo.myFoo.modify + // CHECK-RES-DAG: define hidden {{.*}}swiftcc { ptr, ptr } @"$s4Core3FooC02myB0AA3PubCSgvM" + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc { ptr, ptr } @"$s4Core3FooC02myB0AA3PubCSgvM" -// Core.Foo.myFoo.modify -// CHECK-IR-DAG: define internal swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvM.resume.0" + // Core.Foo.myFoo.modify + // CHECK-COMMON-DAG: define internal swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvM.resume.0" -// type metadata accessor for Core.Foo -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc %swift.metadata_response @"$s4Core3FooCMa" + // type metadata accessor for Core.Foo + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc %swift.metadata_response @"$s4Core3FooCMa" -// method lookup function for Core.Foo -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3FooCMu"(ptr %0, ptr %1) + // method lookup function for Core.Foo + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3FooCMu"(ptr %0, ptr %1) -// dispatch thunk of Core.Foo.myFoo.getter -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvgTj"(ptr swiftself %0) + // dispatch thunk of Core.Foo.myFoo.getter + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3FooC02myB0AA3PubCSgvgTj"(ptr swiftself %0) -// dispatch thunk of Core.Foo.myFoo.setter -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvsTj"({{i32|i64}} %0, ptr swiftself %1) + // dispatch thunk of Core.Foo.myFoo.setter + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3FooC02myB0AA3PubCSgvsTj"({{i32|i64}} %0, ptr swiftself %1) -// dispatch thunk of Core.Foo.myFoo.modify -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc { ptr, ptr } @"$s4Core3FooC02myB0AA3PubCSgvMTj" + // dispatch thunk of Core.Foo.myFoo.modify + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc { ptr, ptr } @"$s4Core3FooC02myB0AA3PubCSgvMTj" + + // Core.Foo.deinit + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3FooCfd"(ptr readonly returned swiftself %0) + + // Core.Foo.__deallocating_deinit + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3FooCfD"(ptr swiftself %0) -// Core.Foo.deinit -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3FooCfd"(ptr readonly returned swiftself %0) + package var myFoo: Pub? +} + +final package class Bar { + + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3BarC02myB0AA3PubCSgvpfi"() + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3BarC02myB0AA3PubCSgvg"(ptr swiftself %0) + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3BarC02myB0AA3PubCSgvs"({{i32|i64}} %0, ptr swiftself %1) + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc { ptr, ptr } @"$s4Core3BarC02myB0AA3PubCSgvM" + // CHECK-COMMON-DAG: define internal swiftcc void @"$s4Core3BarC02myB0AA3PubCSgvM.resume.0" + + // type metadata accessor for Core.Bar + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc %swift.metadata_response @"$s4Core3BarCMa"({{i32|i64}} %0) + + // method lookup function for Core.Bar + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3BarCMu"(ptr %0, ptr %1) + + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3BarCfd"(ptr readonly returned swiftself %0) + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3BarCfD"(ptr swiftself %0) + + package var myBar: Pub? +} -// Core.Foo.__deallocating_deinit -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3FooCfD"(ptr swiftself %0) +@usableFromInline +class UFIKlass { + var varNonUfi: String? + // variable initialization expression of Core.UFIKlass.varUfi + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc {{.*}} @"$s4Core8UFIKlassC6varUfiSSSgvpfi"() -// Core.Bar.myBar -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3BarC02myB0AA3PubCSgvpfi"() -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc {{i32|i64}} @"$s4Core3BarC02myB0AA3PubCSgvg"(ptr swiftself %0) -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3BarC02myB0AA3PubCSgvs"({{i32|i64}} %0, ptr swiftself %1) -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc { ptr, ptr } @"$s4Core3BarC02myB0AA3PubCSgvM" -// CHECK-IR-DAG: define internal swiftcc void @"$s4Core3BarC02myB0AA3PubCSgvM.resume.0" + // key path getter for Core.UFIKlass.varUfi + // CHECK-COMMON-DAG: define linkonce_odr hidden swiftcc void @"$s4Core8UFIKlassC6varUfiSSSgvpACTK" -// Core.Bar -// type metadata accessor for Core.Bar -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc %swift.metadata_response @"$s4Core3BarCMa"({{i32|i64}} %0) + // key path setter for Core.UFIKlass.varUfi + // CHECK-COMMON-DAG: define linkonce_odr hidden swiftcc void @"$s4Core8UFIKlassC6varUfiSSSgvpACTk" + + // dispatch thunk of Core.UFIKlass.varUfi.getter + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc {{.*}} @"$s4Core8UFIKlassC6varUfiSSSgvgTj" -// method lookup function for Core.Bar -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3BarCMu"(ptr %0, ptr %1) + // dispatch thunk of Core.UFIKlass.varUfi.setter + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core8UFIKlassC6varUfiSSSgvsTj" -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3BarCfd"(ptr readonly returned swiftself %0) -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3BarCfD"(ptr swiftself %0) + // dispatch thunk of Core.UFIKlass.varUfi.modify + // CHECK-COMMON-DAG: define {{(dllexport |protected )?}}swiftcc { ptr, ptr } @"$s4Core8UFIKlassC6varUfiSSSgvMTj" -// Core.Pub -// type metadata accessor for Core.Pub -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc %swift.metadata_response @"$s4Core3PubCMa"({{i32|i64}} %0) + // Core.UFIKlass.varUfi.getter + // CHECK-RES-DAG: define hidden {{.*}}swiftcc {{.*}} @"$s4Core8UFIKlassC6varUfiSSSgvg" + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc {{.*}} @"$s4Core8UFIKlassC6varUfiSSSgvg" -// method lookup function for Core.Pub -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3PubCMu"(ptr %0, ptr %1) + // Core.UFIKlass.varUfi.setter + // CHECK-RES-DAG: define hidden {{.*}}swiftcc void @"$s4Core8UFIKlassC6varUfiSSSgvs" + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core8UFIKlassC6varUfiSSSgvs" -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc ptr @"$s4Core3PubCfd"(ptr readnone returned swiftself %0) -// CHECK-IR-DAG: define {{(dllexport |protected )?}}swiftcc void @"$s4Core3PubCfD"(ptr swiftself %0) + // Core.UFIKlass.varUfi.modify + // CHECK-RES-DAG: define hidden {{.*}}swiftcc { ptr, ptr } @"$s4Core8UFIKlassC6varUfiSSSgvM" + // CHECK-OPT-DAG: define {{(dllexport |protected )?}}swiftcc { ptr, ptr } @"$s4Core8UFIKlassC6varUfiSSSgvM" + @usableFromInline + var varUfi: String? +} +class InternalKlass { + var varInternal: String? +} + +/// TBD +/// +/// Core.Foo // property descriptor for Core.Foo.myFoo -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvpMV +// CHECK-TBD-COMMON-DAG: s4Core3FooC02myB0AA3PubCSgvpMV // method descriptor for Core.Foo.myFoo.getter -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvgTq +// CHECK-TBD-COMMON-DAG: s4Core3FooC02myB0AA3PubCSgvgTq // method descriptor for Core.Foo.myFoo.setter -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvsTq +// CHECK-TBD-COMMON-DAG: s4Core3FooC02myB0AA3PubCSgvsTq // method descriptor for Core.Foo.myFoo.modify -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvMTq +// CHECK-TBD-COMMON-DAG: s4Core3FooC02myB0AA3PubCSgvMTq +// type metadata accessor for Core.Foo +// CHECK-TBD-COMMON-DAG: s4Core3FooCMa +// nominal type descriptor for Core.Foo +// CHECK-TBD-COMMON-DAG: s4Core3FooCMn + // dispatch thunk of Core.Foo.myFoo.getter -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvgTj +// CHECK-TBD-COMMON-DAG: s4Core3FooC02myB0AA3PubCSgvgTj // dispatch thunk of Core.Foo.myFoo.setter -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvsTj +// CHECK-TBD-COMMON-DAG: s4Core3FooC02myB0AA3PubCSgvsTj // dispatch thunk of Core.Foo.myFoo.modify -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvMTj -// type metadata accessor for Core.Foo -// CHECK-TBD-DAG: s4Core3FooCMa +// CHECK-TBD-COMMON-DAG: s4Core3FooC02myB0AA3PubCSgvMTj // method lookup function for Core.Foo -// CHECK-TBD-DAG: s4Core3FooCMu -// nominal type descriptor for Core.Foo -// CHECK-TBD-DAG: s4Core3FooCMn +// CHECK-TBD-COMMON-DAG: s4Core3FooCMu // class metadata base offset for Core.Foo -// CHECK-TBD-DAG: s4Core3FooCMo - -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvpfi -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvg -// CHECK-TBD-DAG: s4Core3FooC02myB0AA3PubCSgvs -// CHECK-TBD-DAG: s4Core3FooCfd -// CHECK-TBD-DAG: s4Core3FooCfD - -// CHECK-TBD-DAG: s4Core3BarC02myB0AA3PubCSgvpMV -// CHECK-TBD-DAG: s4Core3BarC02myB0AA3PubCSgvpfi -// CHECK-TBD-DAG: s4Core3BarC02myB0AA3PubCSgvg -// CHECK-TBD-DAG: s4Core3BarC02myB0AA3PubCSgvs -// CHECK-TBD-DAG: s4Core3BarC02myB0AA3PubCSgvM -// CHECK-TBD-DAG: s4Core3BarCMa -// CHECK-TBD-DAG: s4Core3BarCMu -// CHECK-TBD-DAG: s4Core3BarCMn -// CHECK-TBD-DAG: s4Core3BarCMo -// CHECK-TBD-DAG: s4Core3BarCfd -// CHECK-TBD-DAG: s4Core3BarCfD - -// CHECK-TBD-DAG: s4Core3PubCMa -// CHECK-TBD-DAG: s4Core3PubCMu -// CHECK-TBD-DAG: s4Core3PubCMn -// CHECK-TBD-DAG: s4Core3PubCMo -// CHECK-TBD-DAG: s4Core3PubCfd -// CHECK-TBD-DAG: s4Core3PubCfD +// CHECK-TBD-COMMON-DAG: s4Core3FooCMo + +// CHECK-TBD-OPT-DAG: s4Core3FooC02myB0AA3PubCSgvpfi +// CHECK-TBD-OPT-DAG: s4Core3FooC02myB0AA3PubCSgvg +// CHECK-TBD-OPT-DAG: s4Core3FooC02myB0AA3PubCSgvs +// CHECK-TBD-COMMON-DAG: s4Core3FooCfd +// CHECK-TBD-COMMON-DAG: s4Core3FooCfD + +/// Core.UFIKlass +// property descriptor for Core.UFIKlass.varUfi +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassC6varUfiSSSgvpMV +// method descriptor for Core.UFIKlass.varUfi.getter +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassC6varUfiSSSgvgTq +// method descriptor for Core.UFIKlass.varUfi.setter +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassC6varUfiSSSgvsTq +// method descriptor for Core.UFIKlass.varUfi.modify +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassC6varUfiSSSgvMTq +// type metadata accessor for Core.UFIKlass +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassCMa +// nominal type descriptor for Core.UFIKlass +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassCMn + +// dispatch thunk of Core.UFIKlass.varUfi.getter +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassC6varUfiSSSgvgTj +// dispatch thunk of Core.UFIKlass.varUfi.setter +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassC6varUfiSSSgvsTj +// dispatch thunk of Core.UFIKlass.varUfi.modify +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassC6varUfiSSSgvMTj +// method lookup function for Core.UFIKlass +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassCMu +// class metadata base offset for Core.UFIKlass +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassCMo + +// CHECK-TBD-OPT-DAG: s4Core8UFIKlassC6varUfiSSSgvpfi +// CHECK-TBD-OPT-DAG: s4Core8UFIKlassC9varNonUfiSSSgvpfi +// CHECK-TBD-OPT-DAG: s4Core8UFIKlassC6varUfiSSSgvg +// CHECK-TBD-OPT-DAG: s4Core8UFIKlassC6varUfiSSSgvs +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassCfd +// CHECK-TBD-COMMON-DAG: s4Core8UFIKlassCfD + +/// Core.Bar is a final class so no dispatch thunks for its methods +// CHECK-TBD-OPT-DAG: s4Core3BarC02myB0AA3PubCSgvpfi +// CHECK-TBD-OPT-DAG: s4Core3BarC02myB0AA3PubCSgvg +// CHECK-TBD-OPT-DAG: s4Core3BarC02myB0AA3PubCSgvs +// CHECK-TBD-OPT-DAG: s4Core3BarC02myB0AA3PubCSgvM +// CHECK-TBD-COMMON-DAG: s4Core3BarC02myB0AA3PubCSgvpMV +// CHECK-TBD-COMMON-DAG: s4Core3BarCMa +// CHECK-TBD-COMMON-DAG: s4Core3BarCMn +// CHECK-TBD-COMMON-DAG: s4Core3BarCfd +// CHECK-TBD-COMMON-DAG: s4Core3BarCfD +// CHECK-TBD-COMMON-DAG: s4Core3BarCMu +// CHECK-TBD-COMMON-DAG: s4Core3BarCMo + +/// Core.Pub is a final empty class +// CHECK-TBD-COMMON-DAG: s4Core3PubCMa +// CHECK-TBD-COMMON-DAG: s4Core3PubCMn +// CHECK-TBD-COMMON-DAG: s4Core3PubCfd +// CHECK-TBD-COMMON-DAG: s4Core3PubCfD +// CHECK-TBD-COMMON-DAG: s4Core3PubCMu +// CHECK-TBD-COMMON-DAG: s4Core3PubCMo diff --git a/test/SILOptimizer/package-cmo-resilient-mode.swift b/test/SILOptimizer/package-cmo-resilient-mode.swift index 8c013576e145b..d0224967f07b8 100644 --- a/test/SILOptimizer/package-cmo-resilient-mode.swift +++ b/test/SILOptimizer/package-cmo-resilient-mode.swift @@ -427,9 +427,9 @@ public protocol PubProto { } public class PubKlass: PubProto { - // CHECK-RES-DAG: sil shared [transparent] [serialized_for_package] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivgTW : $@convention(witness_method: PubProto) (@in_guaranteed PubKlass) -> Int { - // CHECK-RES-DAG: sil shared [transparent] [serialized_for_package] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivMTW : $@yield_once @convention(witness_method: PubProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout Int for { - // CHECK-RES-DAG: sil shared [transparent] [serialized_for_package] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivsTW : $@convention(witness_method: PubProto) (Int, @inout PubKlass) -> () { + // CHECK-RES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivgTW : $@convention(witness_method: PubProto) (@in_guaranteed PubKlass) -> Int { + // CHECK-RES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivMTW : $@yield_once @convention(witness_method: PubProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout Int for { + // CHECK-RES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivsTW : $@convention(witness_method: PubProto) (Int, @inout PubKlass) -> () { // CHECK-NONRES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivgTW : $@convention(witness_method: PubProto) (@in_guaranteed PubKlass) -> Int { // CHECK-NONRES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivMTW : $@yield_once @convention(witness_method: PubProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout Int for { // CHECK-NONRES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP4dataSivsTW : $@convention(witness_method: PubProto) (Int, @inout PubKlass) -> () { @@ -454,7 +454,7 @@ public class PubKlass: PubProto { self.data = arg } public func pubfunc(_ arg: Int) -> Int { - // CHECK-RES-DAG: sil shared [transparent] [serialized_for_package] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP7pubfuncyS2iFTW : $@convention(witness_method: PubProto) (Int, @in_guaranteed PubKlass) -> Int { + // CHECK-RES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP7pubfuncyS2iFTW : $@convention(witness_method: PubProto) (Int, @in_guaranteed PubKlass) -> Int { // CHECK-RES-DAG: sil [serialized_for_package] [canonical] @$s3Lib8PubKlassC7pubfuncyS2iF : $@convention(method) (Int, @guaranteed PubKlass) -> Int { // CHECK-NONRES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PubKlassCAA0B5ProtoA2aDP7pubfuncyS2iFTW : $@convention(witness_method: PubProto) (Int, @in_guaranteed PubKlass) -> Int { // CHECK-NONRES-DAG: sil [serialized] [canonical] @$s3Lib8PubKlassC7pubfuncyS2iF : $@convention(method) (Int, @guaranteed PubKlass) -> Int { @@ -487,9 +487,9 @@ package protocol PkgProto { } package class PkgKlass: PkgProto { - // CHECK-RES-DAG: sil shared [transparent] [serialized_for_package] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivgTW : $@convention(witness_method: PkgProto) (@in_guaranteed PkgKlass) -> Int { - // CHECK-RES-DAG: sil shared [transparent] [serialized_for_package] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivsTW : $@convention(witness_method: PkgProto) (Int, @inout PkgKlass) -> () { - // CHECK-RES-DAG: sil shared [transparent] [serialized_for_package] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivMTW : $@yield_once @convention(witness_method: PkgProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout Int for { + // CHECK-RES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivgTW : $@convention(witness_method: PkgProto) (@in_guaranteed PkgKlass) -> Int { + // CHECK-RES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivsTW : $@convention(witness_method: PkgProto) (Int, @inout PkgKlass) -> () { + // CHECK-RES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivMTW : $@yield_once @convention(witness_method: PkgProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout Int for { // CHECK-NONRES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivgTW : $@convention(witness_method: PkgProto) (@in_guaranteed PkgKlass) -> Int { // CHECK-NONRES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivsTW : $@convention(witness_method: PkgProto) (Int, @inout PkgKlass) -> () { // CHECK-NONRES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP4dataSivMTW : $@yield_once @convention(witness_method: PkgProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout Int for { @@ -519,7 +519,7 @@ package class PkgKlass: PkgProto { } package func pkgfunc(_ arg: Int) -> Int { - // CHECK-RES-DAG: sil shared [transparent] [serialized_for_package] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP7pkgfuncyS2iFTW : $@convention(witness_method: PkgProto) (Int, @in_guaranteed PkgKlass) -> Int { + // CHECK-RES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP7pkgfuncyS2iFTW : $@convention(witness_method: PkgProto) (Int, @in_guaranteed PkgKlass) -> Int { // CHECK-RES-DAG: sil package [serialized_for_package] [canonical] @$s3Lib8PkgKlassC7pkgfuncyS2iF : $@convention(method) (Int, @guaranteed PkgKlass) -> Int { // CHECK-NONRES-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib8PkgKlassCAA0B5ProtoA2aDP7pkgfuncyS2iFTW : $@convention(witness_method: PkgProto) (Int, @in_guaranteed PkgKlass) -> Int { // CHECK-NONRES-DAG: sil package [serialized] [canonical] @$s3Lib8PkgKlassC7pkgfuncyS2iF : $@convention(method) (Int, @guaranteed PkgKlass) -> Int { diff --git a/test/SILOptimizer/package-cmo-skip-internal.swift b/test/SILOptimizer/package-cmo-skip-internal.swift new file mode 100644 index 0000000000000..0568cb8b4e5a5 --- /dev/null +++ b/test/SILOptimizer/package-cmo-skip-internal.swift @@ -0,0 +1,104 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +// RUN: %target-build-swift %t/Lib.swift \ +// RUN: -module-name=Lib -package-name Pkg \ +// RUN: -parse-as-library -emit-module -emit-module-path %t/Lib.swiftmodule -I%t \ +// RUN: -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access \ +// RUN: -O -wmo -enable-library-evolution +// RUN: %target-sil-opt %t/Lib.swiftmodule -sil-verify-all -o %t/Lib.sil + +// RUN: %target-build-swift -module-name=Main -package-name Pkg -I%t -emit-sil -O %t/main.swift -o %t/Main.sil + +// RUN: %FileCheck %s --check-prefixes=CHECK < %t/Lib.sil +// RUN: %FileCheck %s --check-prefixes=CHECK-MAIN < %t/Main.sil + + +//--- main.swift + +import Lib + +/// There should be no linker error on a public function +/// that contains symbols internal to Lib module. +// CHECK-MAIN: function_ref @$s3Lib11useInternalySiAA4BaseCF : $@convention(thin) (@guaranteed Base) -> Int +let x = useInternal(Base()) + +/// Since Base is not serialized, accessing its field should go +/// through class_method. +// CHECK-MAIN: class_method %13 : $Base, #Base.baseVarPkg!getter : (Base) -> () -> Int, $@convention(method) (@guaranteed Base) -> Int +let y = usePkg(Base()) + +/// Since PubKlass is serialized, can access its field directly. +// CHECK-MAIN: struct $Int +// CHECK-MAIN-NEXT: store +let z = usePub(PubKlass()) + +// useInternal(_:) +// CHECK-MAIN: sil @$s3Lib11useInternalySiAA4BaseCF : $@convention(thin) (@guaranteed Base) -> Int + + + +//--- Lib.swift + +/// Package CMO does not serialize this function since +/// it references an internal symbol `baseVarInternal`. +/// If it were [serialized_for_pkg], it would leak into +/// client and client won't be able to find the symbol +/// `baseVarInternal` since its dispatch thunk was not +/// generated in the first place (due to it being internal). +// CHECK-NOT: s3Lib11useInternalySiAA4BaseCF +public func useInternal(_ arg: Base) -> Int { + return PubKlass().pkgVar + arg.baseVarInternal +} + +// CHECK-DAG: sil package [serialized_for_package] [canonical] @$s3Lib6usePkgySiAA4BaseCF : $@convention(thin) (@guaranteed Base) -> Int { +package func usePkg(_ arg: Base) -> Int { + return arg.baseVarPkg +} + +// CHECK-DAG: sil [serialized_for_package] [canonical] @$s3Lib6usePubySiAA0C5KlassCF : $@convention(thin) (@guaranteed PubKlass) -> Int { +public func usePub(_ arg: PubKlass) -> Int { + return arg.pubVar +} + +/// This class is not serialized since it contains +/// an internal field. +public class Base { + public init() {} + var baseVarInternal: Int { + return 0 + } + package var baseVarPkg: Int { + return 0 + } +} + +@usableFromInline +class UFIKlass: Base { + override init() {} + + var varInternal = 11 + + @usableFromInline + var varUfi = 12 + + override var baseVarInternal: Int { return 1 } + override var baseVarPkg: Int { return 2 } +} + +public class PubKlass { + public init() {} + public var pubVar: Int { + return 1 + } + package var pkgVar: Int { + return 2 + } +} + +/// PubKlass doesn't contain internal symbols so its vtable is serialized. +// CHECK-LABEL: sil_vtable [serialized_for_package] PubKlass { +// CHECK-NEXT: #PubKlass.init!allocator: (PubKlass.Type) -> () -> PubKlass : @$s3Lib8PubKlassCACycfC +// CHECK-NEXT: #PubKlass.pubVar!getter: (PubKlass) -> () -> Int : @$s3Lib8PubKlassC6pubVarSivg +// CHECK-NEXT: #PubKlass.pkgVar!getter: (PubKlass) -> () -> Int : @$s3Lib8PubKlassC6pkgVarSivg +// CHECK-NEXT: #PubKlass.deinit!deallocator: @$s3Lib8PubKlassCfD From 5a0c73c45f82b2adf6226aa28e570e04dafd089f Mon Sep 17 00:00:00 2001 From: Ellie Shin Date: Mon, 3 Jun 2024 23:16:22 -0700 Subject: [PATCH 2/2] Add isPackageCMOEnabled check for MethodInst and KeyPathInst. Update lambda in table serialization. Add more tests. --- lib/SIL/IR/Linker.cpp | 1 - .../IPO/CrossModuleOptimization.cpp | 115 +++-- .../package-cmo-serialize-tables.swift | 405 ++++++------------ .../package-cmo-skip-internal-generic.swift | 206 +++++++++ 4 files changed, 410 insertions(+), 317 deletions(-) create mode 100644 test/SILOptimizer/package-cmo-skip-internal-generic.swift diff --git a/lib/SIL/IR/Linker.cpp b/lib/SIL/IR/Linker.cpp index ecb2431a32134..827884e695e66 100644 --- a/lib/SIL/IR/Linker.cpp +++ b/lib/SIL/IR/Linker.cpp @@ -105,7 +105,6 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist( F->hasValidLinkageForFragileRef(callerSerializedKind) || hasSharedVisibility(linkage) || F->isExternForwardDeclaration()) && "called function has wrong linkage for serialized function"); - if (!F->isExternalDeclaration()) { // The function is already in the module, so no need to de-serialized it. // But check if we need to set the IsSerialized flag. diff --git a/lib/SILOptimizer/IPO/CrossModuleOptimization.cpp b/lib/SILOptimizer/IPO/CrossModuleOptimization.cpp index 83ff5f674bfd7..e055c3596c0d2 100644 --- a/lib/SILOptimizer/IPO/CrossModuleOptimization.cpp +++ b/lib/SILOptimizer/IPO/CrossModuleOptimization.cpp @@ -189,6 +189,10 @@ static bool isPackageOrPublic(AccessLevel accessLevel, SILOptions options) { return accessLevel == AccessLevel::Public; } +static bool isPackageCMOEnabled(ModuleDecl *mod) { + return mod->isResilient() && mod->serializePackageEnabled(); +} + /// Checks wither this function is [serialized_for_package] due to Package CMO /// or [serialized] with non-package CMO. The [serialized_for_package] attribute /// is used to indicate that a function is serialized because of Package CMO, which @@ -201,20 +205,21 @@ static bool isPackageOrPublic(AccessLevel accessLevel, SILOptions options) { /// is the correct behavior. static bool isSerializedWithRightKind(const SILModule &mod, SILFunction *f) { - return mod.getSwiftModule()->serializePackageEnabled() && - mod.getSwiftModule()->isResilient() ? - f->isSerializedForPackage() : f->isSerialized(); + // If Package CMO is enabled in resilient mode, return + // true if the function is [serialized] due to @inlinable + // (or similar) or [serialized_for_pkg] due to this + // optimization. + return isPackageCMOEnabled(mod.getSwiftModule()) ? f->isAnySerialized() + : f->isSerialized(); } static bool isSerializedWithRightKind(const SILModule &mod, SILGlobalVariable *g) { - return mod.getSwiftModule()->serializePackageEnabled() && - mod.getSwiftModule()->isResilient() ? - g->isSerializedForPackage() : g->isSerialized(); + return isPackageCMOEnabled(mod.getSwiftModule()) ? g->isAnySerialized() + : g->isSerialized(); } static SerializedKind_t getRightSerializedKind(const SILModule &mod) { - return mod.getSwiftModule()->serializePackageEnabled() && - mod.getSwiftModule()->isResilient() ? - IsSerializedForPackage : IsSerialized; + return isPackageCMOEnabled(mod.getSwiftModule()) ? IsSerializedForPackage + : IsSerialized; } static bool isSerializeCandidate(SILFunction *F, SILOptions options) { @@ -286,24 +291,28 @@ void CrossModuleOptimization::serializeTablesInModule() { // This should not be necessary but is added to ensure all applicable // symbols are serialized. Whether serialized or not is cached so // this check shouldn't be expensive. - auto unserializedClassMethodRange = llvm::make_filter_range(vt->getEntries(), [&](auto &entry) { - return entry.getImplementation()->getSerializedKind() != getRightSerializedKind(M); - }); + auto unserializedClassMethodRange = llvm::make_filter_range( + vt->getEntries(), [&](const SILVTableEntry &entry) { + return entry.getImplementation()->getSerializedKind() != + getRightSerializedKind(M); + }); std::vector classMethodsToSerialize; llvm::transform(unserializedClassMethodRange, std::back_inserter(classMethodsToSerialize), - [&](auto entry) { - return entry.getImplementation(); - }); + [&](const SILVTableEntry &entry) { + return entry.getImplementation(); + }); trySerializeFunctions(classMethodsToSerialize); - bool containsInternal = llvm::any_of(classMethodsToSerialize, [&](auto &method) { - // If the entry is internal, vtable should not be serialized. - // However, if the entry is not serialized but has the right - // visibility, it can still be referenced, thus the vtable - // should serialized. - return !method->hasValidLinkageForFragileRef(getRightSerializedKind(M)); - }); + bool containsInternal = + llvm::any_of(vt->getEntries(), [&](const SILVTableEntry &entry) { + // If the entry is internal, vtable should not be serialized. + // However, if the entry is not serialized but has the right + // visibility, it can still be referenced, thus the vtable + // should serialized. + return !entry.getImplementation()->hasValidLinkageForFragileRef( + getRightSerializedKind(M)); + }); if (!containsInternal) vt->setSerializedKind(getRightSerializedKind(M)); } @@ -318,25 +327,31 @@ void CrossModuleOptimization::serializeTablesInModule() { // This should not be necessary but is added to ensure all applicable // symbols are serialized. Whether serialized or not is cached so // this check shouldn't be expensive. - auto unserializedWTMethodRange = llvm::make_filter_range(wt.getEntries(), [&](auto &entry) { - return entry.getKind() == SILWitnessTable::Method && - entry.getMethodWitness().Witness->getSerializedKind() != getRightSerializedKind(M); - }); + auto unserializedWTMethodRange = llvm::make_filter_range( + wt.getEntries(), [&](const SILWitnessTable::Entry &entry) { + return entry.getKind() == SILWitnessTable::Method && + entry.getMethodWitness().Witness->getSerializedKind() != + getRightSerializedKind(M); + }); std::vector wtMethodsToSerialize; llvm::transform(unserializedWTMethodRange, std::back_inserter(wtMethodsToSerialize), - [&](auto entry) { - return entry.getMethodWitness().Witness; - }); + [&](const SILWitnessTable::Entry &entry) { + return entry.getMethodWitness().Witness; + }); trySerializeFunctions(wtMethodsToSerialize); - bool containsInternal = llvm::any_of(wtMethodsToSerialize, [&](auto &method) { - // If the entry is internal, wtable should not be serialized. - // However, if the entry is not serialized but has the right - // visibility, it can still be referenced, thus the vtable - // should serialized. - return !method->hasValidLinkageForFragileRef(getRightSerializedKind(M)); - }); + bool containsInternal = llvm::any_of( + wt.getEntries(), [&](const SILWitnessTable::Entry &entry) { + // If the entry is internal, wtable should not be serialized. + // However, if the entry is not serialized but has the right + // visibility, it can still be referenced, thus the vtable + // should serialized. + return entry.getKind() == SILWitnessTable::Method && + !entry.getMethodWitness() + .Witness->hasValidLinkageForFragileRef( + getRightSerializedKind(M)); + }); if (!containsInternal) wt.setSerializedKind(getRightSerializedKind(M)); } @@ -485,17 +500,29 @@ bool CrossModuleOptimization::canSerializeInstruction( [&](SILDeclRef method) { if (method.isForeign) canUse = false; + else if (isPackageCMOEnabled(method.getModuleContext())) { + // If the referenced keypath is internal, do not + // serialize. + auto methodScope = method.getDecl()->getFormalAccessScope( + nullptr, + /*treatUsableFromInlineAsPublic*/ true); + canUse = methodScope.isPublicOrPackage(); + } }); return canUse; } if (auto *MI = dyn_cast(inst)) { - // If a class_method or witness_method is internal, it can't - // be serialized. + // If a class_method or witness_method is internal, + // it can't be serialized. auto member = MI->getMember(); - auto methodAccessScope = member.getDecl()->getFormalAccessScope(nullptr, - /*treatUsableFromInlineAsPublic*/ true); - return methodAccessScope.isPublicOrPackage() && - !member.isForeign; + auto canUse = !member.isForeign; + if (canUse && isPackageCMOEnabled(member.getModuleContext())) { + auto methodScope = member.getDecl()->getFormalAccessScope( + nullptr, + /*treatUsableFromInlineAsPublic*/ true); + canUse = methodScope.isPublicOrPackage(); + } + return canUse; } if (auto *REAI = dyn_cast(inst)) { // In conservative mode, we don't support class field accesses of non-public @@ -737,7 +764,9 @@ void CrossModuleOptimization::serializeInstruction(SILInstruction *inst, if (canSerializeGlobal(global)) { serializeGlobal(global); } - if (!hasPublicOrPackageVisibility(global->getLinkage(), M.getSwiftModule()->serializePackageEnabled())) { + if (!hasPublicOrPackageVisibility( + global->getLinkage(), + M.getSwiftModule()->serializePackageEnabled())) { global->setLinkage(SILLinkage::Public); } return; diff --git a/test/SILOptimizer/package-cmo-serialize-tables.swift b/test/SILOptimizer/package-cmo-serialize-tables.swift index 3fc12110fb9cc..2eaeae70082d8 100644 --- a/test/SILOptimizer/package-cmo-serialize-tables.swift +++ b/test/SILOptimizer/package-cmo-serialize-tables.swift @@ -1,4 +1,4 @@ -/// This tests serializing v-table and witness-table in non-resilient mode Package-CMO. +/// This tests serializing v-table and witness-table with Package CMO in resilient mode. /// // RUN: %empty-directory(%t) // RUN: split-file %s %t @@ -7,16 +7,17 @@ // RUN: -module-name=Lib -package-name Pkg \ // RUN: -parse-as-library -emit-module -emit-module-path %t/Lib.swiftmodule -I%t \ // RUN: -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access \ -// RUN: -O -wmo +// RUN: -enable-library-evolution -wmo // RUN: %target-sil-opt %t/Lib.swiftmodule -sil-verify-all -o %t/Lib-sil-opt.sil // RUN: %FileCheck %s < %t/Lib-sil-opt.sil -// RUN: %target-build-swift -module-name=Main -package-name Pkg -I%t -emit-sil %t/main.swift -o %t/Main.sil +// RUN: %target-build-swift -module-name=Main -package-name Pkg -enable-library-evolution -I%t -emit-sil %t/main.swift -o %t/Main.sil // RUN: %FileCheck %s --check-prefix=CHECK-MAIN < %t/Main.sil // REQUIRES: swift_in_compiler + //--- main.swift import Lib @@ -30,67 +31,50 @@ runPkg([PkgStruct(rawValue: 2), PkgKlassZ(rawValue: 3)]) //--- Lib.swift public class ParentPubKlass { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib14ParentPubKlassC06parentC3VarSivg : $@convention(method) (@guaranteed ParentPubKlass) -> Int { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib14ParentPubKlassC06parentC3VarSivs : $@convention(method) (Int, @guaranteed ParentPubKlass) -> () { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib14ParentPubKlassC06parentC3VarSivM : $@yield_once @convention(method) (@guaranteed ParentPubKlass) -> @yields @inout Int { public var parentPubVar: Int - public init(_ arg: Int) { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib14ParentPubKlassCyACSicfc : $@convention(method) (Int, @owned ParentPubKlass) -> @owned ParentPubKlass { parentPubVar = arg } - public func parentPubFunc() { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib14ParentPubKlassC06parentC4FuncyyF : $@convention(method) (@guaranteed ParentPubKlass) -> () { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib14ParentPubKlassC06parentC4FuncyyF print(parentPubVar) } } public class PubKlass: ParentPubKlass { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib8PubKlassC6pubVarSSvM : $@yield_once @convention(method) (@guaranteed PubKlass) -> @yields @inout String { public var pubVar: String = "publicVar" - public init(_ arg: String) { - // CHECK-DAG: sil [serialized] [exact_self_class] [canonical] @$s3Lib8PubKlassCyACSScfC : $@convention(method) (@owned String, @thick PubKlass.Type) -> @owned PubKlass { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib8PubKlassCyACSScfc : $@convention(method) (@owned String, @owned PubKlass) -> @owned PubKlass { super.init(1) pubVar = arg } public func pubFunc() { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib8PubKlassC7pubFuncyyF : $@convention(method) (@guaranteed PubKlass) -> () { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib8PubKlassC7pubFuncyyF print(pubVar) } override public func parentPubFunc() { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib8PubKlassC06parentB4FuncyyF : $@convention(method) (@guaranteed PubKlass) -> () { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib8PubKlassC06parentB4FuncyyF print(pubVar) } } public class ParentPubKlassWithInternalMemberX { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC3VarSivM : $@yield_once @convention(method) (@guaranteed ParentPubKlassWithInternalMemberX) -> @yields @inout Int { public var parentPubVar: Int - - var parentIntVar: Int /// NOTE: internal, so not serialized - - public init(_ arg: Int) { /// NOTE: init definition doesn't have [serialized] as it contains an internal var - - // CHECK-DAG: sil [canonical] @$s3Lib33ParentPubKlassWithInternalMemberXCyACSicfc : $@convention(method) (Int, @owned ParentPubKlassWithInternalMemberX) -> @owned ParentPubKlassWithInternalMemberX { - // CHECK-DAG: sil [serialized] [exact_self_class] [canonical] @$s3Lib33ParentPubKlassWithInternalMemberXCyACSicfC - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib33ParentPubKlassWithInternalMemberXCfd : $@convention(method) (@guaranteed ParentPubKlassWithInternalMemberX) -> @owned Builtin.NativeObject { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib33ParentPubKlassWithInternalMemberXCfD : $@convention(method) (@owned ParentPubKlassWithInternalMemberX) -> () { + var parentIntVar: Int + public init(_ arg: Int) { + // CHECK-DAG: sil [serialized] [exact_self_class] [canonical] [ossa] @$s3Lib33ParentPubKlassWithInternalMemberXCyACSicfC : $@convention(method) (Int, @thick ParentPubKlassWithInternalMemberX.Type) -> @owned ParentPubKlassWithInternalMemberX { + // CHECK-DAG: sil [canonical] @$s3Lib33ParentPubKlassWithInternalMemberXCyACSicfc : $@convention(method) (Int, @owned ParentPubKlassWithInternalMemberX) -> @owned ParentPubKlassWithInternalMemberX parentPubVar = arg parentIntVar = arg } public func parentPubFuncA() { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC5FuncAyyF : $@convention(method) (@guaranteed ParentPubKlassWithInternalMemberX) -> () { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC5FuncAyyF print(parentPubVar) } public func parentPubFuncB() { - // CHECK-DAG: sil [canonical] @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC5FuncByyF : $@convention(method) (@guaranteed ParentPubKlassWithInternalMemberX) -> () { - print(parentPubVar, parentIntVar) /// NOTE: definition can't be set [serialized] since it contains an internal var + print(parentPubVar, parentIntVar) /// NOTE: parentPubFuncB() can't be serialized since it contains an internal var } func parentIntFunc() { /// NOTE: internal, so not serialized @@ -102,52 +86,41 @@ public class PubKlassX: ParentPubKlassWithInternalMemberX { public var pubVar: String = "publicVar" override public var parentPubVar: Int { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassXC06parentB3VarSivg : $@convention(method) (@guaranteed PubKlassX) -> Int { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassXC06parentB3VarSivs : $@convention(method) (Int, @guaranteed PubKlassX) -> () { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassXC06parentB3VarSivM : $@yield_once @convention(method) (@guaranteed PubKlassX) -> @yields @inout Int { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassXC06parentB3VarSivg didSet { print ("newValue") } } - public init() { /// NOTE: since it calls super.init which doesn't have [serialized], this init doesn't either. - - // CHECK-DAG: sil [canonical] @$s3Lib9PubKlassXCACycfc : $@convention(method) (@owned PubKlassX) -> @owned PubKlassX { - // CHECK-DAG: sil [serialized] [exact_self_class] [canonical] @$s3Lib9PubKlassXCyACSicfC : $@convention(method) (Int, @thick PubKlassX.Type) -> @owned PubKlassX { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassXCfD : $@convention(method) (@owned PubKlassX) -> () { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassXCfd : $@convention(method) (@guaranteed PubKlassX) -> @owned Builtin.NativeObject { + public init() { + // CHECK-DAG: sil [serialized] [exact_self_class] [canonical] [ossa] @$s3Lib9PubKlassXCACycfC : $@convention(method) (@thick PubKlassX.Type) -> @owned PubKlassX { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassXCACycfc : $@convention(method) (@owned PubKlassX) -> @owned PubKlassX { super.init(1) } override public func parentPubFuncA() { - // CHECK-DAG: sil [canonical] @$s3Lib9PubKlassXC06parentB5FuncAyyF : $@convention(method) (@guaranteed PubKlassX) -> () { - print(pubVar, parentIntVar) /// NOTE: definition can't be set [serialized] since it contains an internal var + print(pubVar, parentIntVar) /// NOTE: contains internal; not serialized } override public func parentPubFuncB() { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassXC06parentB5FuncByyF : $@convention(method) (@guaranteed PubKlassX) -> () { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassXC06parentB5FuncByyF print(pubVar) } - override func parentIntFunc() { /// NOTE: not serialized as it's internal + override func parentIntFunc() { /// NOTE: contains internal; not serialized print(pubVar) } public func pubFunc() { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassXC7pubFuncyyF : $@convention(method) (@guaranteed PubKlassX) -> () { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassXC7pubFuncyyF print(pubVar) } } public class ParentPubKlassWithInternalMemberY { var parentIntVar: Int /// NOTE: internal; not serialized - - public init(_ arg: Int) { /// NOTE: init definition does not have [serialized] as it contains an internal var - - // FIXME: init is not [serialized] but __allocating_init is; should both be not serialized? - // CHECK-DAG: sil [canonical] @$s3Lib33ParentPubKlassWithInternalMemberYCyACSicfc : $@convention(method) (Int, @owned ParentPubKlassWithInternalMemberY) -> @owned ParentPubKlassWithInternalMemberY { - // CHECK-DAG: sil [serialized] [exact_self_class] [canonical] @$s3Lib33ParentPubKlassWithInternalMemberYCyACSicfC : $@convention(method) (Int, @thick ParentPubKlassWithInternalMemberY.Type) -> @owned ParentPubKlassWithInternalMemberY { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib33ParentPubKlassWithInternalMemberYCfD : $@convention(method) (@owned ParentPubKlassWithInternalMemberY) -> () { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib33ParentPubKlassWithInternalMemberYCfd : $@convention(method) (@guaranteed ParentPubKlassWithInternalMemberY) -> @owned Builtin.NativeObject { + public init(_ arg: Int) { /// NOTE: contains internal; not serialized + // CHECK-DAG: sil [serialized] [exact_self_class] [canonical] [ossa] @$s3Lib33ParentPubKlassWithInternalMemberYCyACSicfC : $@convention(method) (Int, @thick ParentPubKlassWithInternalMemberY.Type) -> @owned ParentPubKlassWithInternalMemberY { + // CHECK-DAG: sil [canonical] @$s3Lib33ParentPubKlassWithInternalMemberYCyACSicfc : $@convention(method) (Int, @owned ParentPubKlassWithInternalMemberY) -> @owned ParentPubKlassWithInternalMemberY parentIntVar = arg } - func parentIntFunc() { /// NOTE: internal; not serialized + func parentIntFunc() { /// NOTE: contains internal; not serialized print(parentIntVar) } } @@ -158,61 +131,50 @@ public class PubKlassY: ParentPubKlassWithInternalMemberY { } package class ParentPkgKlass { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib14ParentPkgKlassC06parentC3VarSivg : $@convention(method) (@guaranteed ParentPkgKlass) -> Int { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib14ParentPkgKlassC06parentC3VarSivs : $@convention(method) (Int, @guaranteed ParentPkgKlass) -> () { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib14ParentPkgKlassC06parentC3VarSivM : $@yield_once @convention(method) (@guaranteed ParentPkgKlass) -> @yields @inout Int { package var parentPkgVar: Int - package init(_ arg: Int) { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib14ParentPkgKlassCyACSicfc : $@convention(method) (Int, @owned ParentPkgKlass) -> @owned ParentPkgKlass { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib14ParentPkgKlassCyACSicfc : $@convention(method) (Int, @owned ParentPkgKlass) -> @owned ParentPkgKlass { parentPkgVar = arg } package func parentPkgFunc() -> Int { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib14ParentPkgKlassC06parentC4FuncSiyF : $@convention(method) (@guaranteed ParentPkgKlass) -> Int { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib14ParentPkgKlassC06parentC4FuncSiyF parentPkgVar } } package class PkgKlass: ParentPkgKlass { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib8PkgKlassC6pkgVarSSvg : $@convention(method) (@guaranteed PkgKlass) -> @owned String { package var pkgVar: String = "pkgVar" - package init(_ arg: String) { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib8PkgKlassCyACSScfc : $@convention(method) (@owned String, @owned PkgKlass) -> @owned PkgKlass { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib8PkgKlassCyACSScfc super.init(1) pkgVar = arg } package func pkgFunc() { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib8PkgKlassC7pkgFuncyyF : $@convention(method) (@guaranteed PkgKlass) -> () { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib8PkgKlassC7pkgFuncyyF print(pkgVar) } override package func parentPkgFunc() -> Int { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib8PkgKlassC06parentB4FuncSiyF : $@convention(method) (@guaranteed PkgKlass) -> Int { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib8PkgKlassC06parentB4FuncSiyF pkgVar.count } } package class ParentPkgKlassWithInternalMemberX { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC3VarSivs : $@convention(method) (Int, @guaranteed ParentPkgKlassWithInternalMemberX) -> () { package var parentPkgVar: Int - var parentIntVar: Int /// NOTE: internal so not serialized package init(_ arg: Int) { - // FIXME: definition for .init is not generated at all; should it be generated (without [serialized]) like public? - // CHECK-DAG: sil package_external [exact_self_class] [canonical] @$s3Lib33ParentPkgKlassWithInternalMemberXCyACSicfC : $@convention(method) (Int, @thick ParentPkgKlassWithInternalMemberX.Type) -> @owned ParentPkgKlassWithInternalMemberX { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib33ParentPkgKlassWithInternalMemberXCfD : $@convention(method) (@owned ParentPkgKlassWithInternalMemberX) -> () { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib33ParentPkgKlassWithInternalMemberXCfd : $@convention(method) (@guaranteed ParentPkgKlassWithInternalMemberX) -> @owned Builtin.NativeObject { + // CHECK-DAG: sil package [serialized_for_package] [exact_self_class] [canonical] [ossa] @$s3Lib33ParentPkgKlassWithInternalMemberXCyACSicfC : $@convention(method) (Int, @thick ParentPkgKlassWithInternalMemberX.Type) -> @owned ParentPkgKlassWithInternalMemberX { + // CHECK-DAG: sil package_external [canonical] @$s3Lib33ParentPkgKlassWithInternalMemberXCyACSicfc : $@convention(method) (Int, @owned ParentPkgKlassWithInternalMemberX) -> @owned ParentPkgKlassWithInternalMemberX parentPkgVar = arg parentIntVar = arg } package func parentPkgFuncA() { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC5FuncAyyF : $@convention(method) (@guaranteed ParentPkgKlassWithInternalMemberX) -> () { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC5FuncAyyF print(parentPkgVar) } - package func parentPkgFuncB() { /// NOTE: not [serialized] as it contains an internal var - // CHECK-DAG: sil package_external [canonical] @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC5FuncByyF : $@convention(method) (@guaranteed ParentPkgKlassWithInternalMemberX) -> () { + package func parentPkgFuncB() { /// NOTE: contains internal; not serialized print(parentPkgVar, parentIntVar) } func parentIntFunc() { /// NOTE: internal so not serialized @@ -221,35 +183,28 @@ package class ParentPkgKlassWithInternalMemberX { } package class PkgKlassX: ParentPkgKlassWithInternalMemberX { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgKlassXC6pkgVarSSvs : $@convention(method) (@owned String, @guaranteed PkgKlassX) -> () { package var pkgVar: String = "pkgVar" - override package var parentPkgVar: Int { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgKlassXC06parentB3VarSivg : $@convention(method) (@guaranteed PkgKlassX) -> Int { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgKlassXC06parentB3VarSivs : $@convention(method) (Int, @guaranteed PkgKlassX) -> () { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgKlassXC06parentB3VarSivM : $@yield_once @convention(method) (@guaranteed PkgKlassX) -> @yields @inout Int { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassXC06parentB3VarSivg didSet { print ("newValue") } } package init() { - // FIXME: super.init is not [serialized], but this init definition should still be generated. - - /// NOTE: `__allocating_init` below is not [serialized]. - // CHECK-DAG: sil package_external [exact_self_class] [canonical] @$s3Lib9PkgKlassXCyACSicfC : $@convention(method) (Int, @thick PkgKlassX.Type) -> @owned PkgKlassX { + // CHECK-DAG: sil package [serialized_for_package] [exact_self_class] [canonical] [ossa] @$s3Lib9PkgKlassXCyACSicfC : $@convention(method) (Int, @thick PkgKlassX.Type) -> @owned PkgKlassX { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassXCyACSicfc : $@convention(method) (Int, @owned PkgKlassX) -> @owned PkgKlassX { super.init(1) } override package func parentPkgFuncA() { - // CHECK-DAG: sil package_external [canonical] @$s3Lib9PkgKlassXC06parentB5FuncAyyF : $@convention(method) (@guaranteed PkgKlassX) -> () { print(pkgVar, parentIntVar) } override package func parentPkgFuncB() { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgKlassXC06parentB5FuncByyF : $@convention(method) (@guaranteed PkgKlassX) -> () { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassXC06parentB5FuncByyF print(pkgVar) } - override func parentIntFunc() { /// NOTE: not serialized + override func parentIntFunc() { /// NOTE: contains internal; not serialized print(pkgVar) } package func pubFunc() { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgKlassXC7pubFuncyyF : $@convention(method) (@guaranteed PkgKlassX) -> () { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassXC7pubFuncyyF print(pkgVar) } } @@ -257,8 +212,8 @@ package class PkgKlassX: ParentPkgKlassWithInternalMemberX { package class ParentPkgKlassWithInternalMemberY { var parentIntVar: Int package init(_ arg: Int) { - // FIXME: only `__allocating_init` is generated. - // CHECK-DAG: sil package_external [exact_self_class] [canonical] @$s3Lib33ParentPkgKlassWithInternalMemberYCyACSicfC : $@convention(method) (Int, @thick ParentPkgKlassWithInternalMemberY.Type) -> @owned ParentPkgKlassWithInternalMemberY { + // CHECK-DAG: sil package [serialized_for_package] [exact_self_class] [canonical] [ossa] @$s3Lib33ParentPkgKlassWithInternalMemberYCyACSicfC : $@convention(method) (Int, @thick ParentPkgKlassWithInternalMemberY.Type) -> @owned ParentPkgKlassWithInternalMemberY { + // CHECK-DAG: sil package_external [canonical] @$s3Lib33ParentPkgKlassWithInternalMemberYCyACSicfc : $@convention(method) (Int, @owned ParentPkgKlassWithInternalMemberY) -> @owned ParentPkgKlassWithInternalMemberY parentIntVar = arg } func parentIntFunc() { @@ -267,11 +222,10 @@ package class ParentPkgKlassWithInternalMemberY { } package class PkgKlassY: ParentPkgKlassWithInternalMemberY { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgKlassYC6pkgVarSSvs : $@convention(method) (@owned String, @guaranteed PkgKlassY) -> () { package var pkgVar: String = "pkgVar" package init() { - // FIXME: only `__allocating_init` is generated. - // CHECK-DAG: sil package_external [exact_self_class] [canonical] @$s3Lib9PkgKlassYCACycfC : $@convention(method) (@thick PkgKlassY.Type) -> @owned PkgKlassY { + // CHECK-DAG: sil package [serialized_for_package] [exact_self_class] [canonical] [ossa] @$s3Lib9PkgKlassYCACycfC : $@convention(method) (@thick PkgKlassY.Type) -> @owned PkgKlassY { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassYCACycfc : $@convention(method) (@owned PkgKlassY) -> @owned PkgKlassY { super.init(1) } } @@ -286,59 +240,58 @@ public protocol PubProto { /// NOTE: witness thunks get `shared` linkage public class PubKlassZ: PubProto { - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP4roots6UInt16VvgZTW : $@convention(witness_method: PubProto) (@thick PubKlassZ.Type) -> UInt16 { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubKlassZC4roots6UInt16VvgZ : $@convention(method) (@thick PubKlassZ.Type) -> UInt16 { + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP4roots6UInt16VvgZTW public static let root: UInt16 = 1 << 0 - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP3envs6UInt16VvgTW : $@convention(witness_method: PubProto) (@in_guaranteed PubKlassZ) -> UInt16 { - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP3envs6UInt16VvsTW : $@convention(witness_method: PubProto) (UInt16, @inout PubKlassZ) -> () { - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP3envs6UInt16VvMTW : $@yield_once @convention(witness_method: PubProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout UInt16 for { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubKlassZC3envs6UInt16Vvg : $@convention(method) (@guaranteed PubKlassZ) -> UInt16 { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubKlassZC3envs6UInt16Vvs : $@convention(method) (UInt16, @guaranteed PubKlassZ) -> () { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubKlassZC3envs6UInt16VvM : $@yield_once @convention(method) (@guaranteed PubKlassZ) -> @yields @inout UInt16 { + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP3envs6UInt16VvgTW + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP3envs6UInt16VvsTW + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP3envs6UInt16VvMTW + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassZC3envs6UInt16Vvg + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassZC3envs6UInt16Vvs + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassZC3envs6UInt16VvM public var env: UInt16 - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubKlassZC8rawValues6UInt16Vvg : $@convention(method) (@guaranteed PubKlassZ) -> UInt16 { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassZC8rawValues6UInt16Vvg public let rawValue: UInt16 required public init(rawValue: UInt16) { - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW : $@convention(witness_method: PubProto) (UInt16, @thick PubKlassZ.Type) -> @out PubKlassZ { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassZC8rawValueACs6UInt16V_tcfc : $@convention(method) (UInt16, @owned PubKlassZ) -> @owned PubKlassZ { + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassZC8rawValueACs6UInt16V_tcfc self.rawValue = rawValue self.env = 1 << rawValue } public func pubFunc() { - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP7pubFuncyyFTW : $@convention(witness_method: PubProto) (@in_guaranteed PubKlassZ) -> () { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubKlassZC7pubFuncyyF : $@convention(method) (@guaranteed PubKlassZ) -> () { + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubKlassZCAA0B5ProtoA2aDP7pubFuncyyFTW + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubKlassZC7pubFuncyyF print(env) } } public struct PubStruct: PubProto { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubStructVAA0B5ProtoA2aDP4roots6UInt16VvgZTW : $@convention(witness_method: PubProto) (@thick PubStruct.Type) -> UInt16 { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubStructV4roots6UInt16VvgZ : $@convention(method) (@thin PubStruct.Type) -> UInt16 { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubStructV4roots6UInt16VvgZ : $@convention(method) (@thin PubStruct.Type) -> UInt16 { public static let root: UInt16 = 1 << 0 // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubStructVAA0B5ProtoA2aDP3envs6UInt16VvgTW : $@convention(witness_method: PubProto) (@in_guaranteed PubStruct) -> UInt16 { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubStructVAA0B5ProtoA2aDP3envs6UInt16VvsTW : $@convention(witness_method: PubProto) (UInt16, @inout PubStruct) -> () { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubStructVAA0B5ProtoA2aDP3envs6UInt16VvMTW : $@yield_once @convention(witness_method: PubProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout UInt16 for { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubStructV3envs6UInt16Vvg : $@convention(method) (PubStruct) -> UInt16 { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubStructV3envs6UInt16Vvs : $@convention(method) (UInt16, @inout PubStruct) -> () { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubStructV3envs6UInt16Vvg + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubStructV3envs6UInt16Vvs public var env: UInt16 - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib9PubStructV8rawValues6UInt16Vvg : $@convention(method) (PubStruct) -> UInt16 { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubStructV8rawValues6UInt16Vvg public let rawValue: UInt16 public init(rawValue: UInt16) { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubStructVAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW : $@convention(witness_method: PubProto) (UInt16, @thick PubStruct.Type) -> @out PubStruct { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubStructV8rawValueACs6UInt16V_tcfC : $@convention(method) (UInt16, @thin PubStruct.Type) -> PubStruct { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubStructV8rawValueACs6UInt16V_tcfC self.rawValue = rawValue self.env = 1 << rawValue } public func pubFunc() { - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubStructVAA0B5ProtoA2aDP7pubFuncyyFTW : $@convention(witness_method: PubProto) (@in_guaranteed PubStruct) -> () { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib9PubStructV7pubFuncyyF : $@convention(method) (PubStruct) -> () { + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PubStructVAA0B5ProtoA2aDP7pubFuncyyFTW + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib9PubStructV7pubFuncyyF print(env) } } @@ -362,20 +315,19 @@ public struct PubStructX: PubSimpleProto, InternalProto { /// NOTE: witness tabl // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib10PubStructXVAA0B11SimpleProtoA2aDP6pubVarSivgTW : $@convention(witness_method: PubSimpleProto) (@in_guaranteed PubStructX) -> Int { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib10PubStructXVAA0B11SimpleProtoA2aDP6pubVarSivsTW : $@convention(witness_method: PubSimpleProto) (Int, @inout PubStructX) -> () { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib10PubStructXVAA0B11SimpleProtoA2aDP6pubVarSivMTW : $@yield_once @convention(witness_method: PubSimpleProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout Int for { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib10PubStructXV6pubVarSivg : $@convention(method) (@guaranteed PubStructX) -> Int { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib10PubStructXV6pubVarSivs : $@convention(method) (Int, @inout PubStructX) -> () { - // CHECK-DAG: sil [transparent] [serialized] [canonical] [ossa] @$s3Lib10PubStructXV6pubVarSivM : $@yield_once @convention(method) (@inout PubStructX) -> @yields @inout Int { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib10PubStructXV6pubVarSivg + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib10PubStructXV6pubVarSivs + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib10PubStructXV6pubVarSivM public var pubVar: Int var intVar: InternalStruct /// NOTE: internal; not serialized - public init(_ arg: Int) { /// NOTE: init definition is not [serialized] as it contains an internal var - // CHECK-DAG: sil [canonical] @$s3Lib10PubStructXVyACSicfC : $@convention(method) (Int, @thin PubStructX.Type) -> @owned PubStructX { + public init(_ arg: Int) { /// NOTE: contains internal; not serialized self.intVar = InternalStruct(name: "foo") self.pubVar = arg } public func pubFunc() -> Int { - // CHECK-DAG: sil [serialized] [canonical] @$s3Lib10PubStructXV7pubFuncSiyF : $@convention(method) (@guaranteed PubStructX) -> Int { + // CHECK-DAG: sil [serialized_for_package] [canonical] [ossa] @$s3Lib10PubStructXV7pubFuncSiyF return pubVar } @@ -384,10 +336,9 @@ public struct PubStructX: PubSimpleProto, InternalProto { /// NOTE: witness tabl } } -public struct PubStructY: InternalProto { +public struct PubStructY: InternalProto { /// NOTE: conforms to internal proto; not serialized var intVar: InternalStruct public init() { - // CHECK-DAG: sil [canonical] @$s3Lib10PubStructYVACycfC : $@convention(method) (@thin PubStructY.Type) -> @owned PubStructY { self.intVar = InternalStruct(name: "foo") } func intFunc() -> InternalStruct { @@ -406,54 +357,53 @@ package protocol PkgProto { /// NOTE: witness thunks get `shared` linkage package class PkgKlassZ: PkgProto { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP4roots6UInt16VvgZTW : $@convention(witness_method: PkgProto) (@thick PkgKlassZ.Type) -> UInt16 { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgKlassZC4roots6UInt16VvgZ : $@convention(method) (@thick PkgKlassZ.Type) -> UInt16 { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassZC4roots6UInt16VvgZ package static let root: UInt16 = 1 << 0 // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP3envs6UInt16VvgTW : $@convention(witness_method: PkgProto) (@in_guaranteed PkgKlassZ) -> UInt16 { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP3envs6UInt16VvsTW : $@convention(witness_method: PkgProto) (UInt16, @inout PkgKlassZ) -> () { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgKlassZC3envs6UInt16Vvg : $@convention(method) (@guaranteed PkgKlassZ) -> UInt16 { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgKlassZC3envs6UInt16Vvs : $@convention(method) (UInt16, @guaranteed PkgKlassZ) -> () { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgKlassZC3envs6UInt16VvM : $@yield_once @convention(method) (@guaranteed PkgKlassZ) -> @yields @inout UInt16 { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassZC3envs6UInt16Vvg + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassZC3envs6UInt16Vvs + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassZC3envs6UInt16VvM package var env: UInt16 - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgKlassZC8rawValues6UInt16Vvg : $@convention(method) (@guaranteed PkgKlassZ) -> UInt16 { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassZC8rawValues6UInt16Vvg package let rawValue: UInt16 required package init(rawValue: UInt16) { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW : $@convention(witness_method: PkgProto) (UInt16, @thick PkgKlassZ.Type) -> @out PkgKlassZ { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgKlassZC8rawValueACs6UInt16V_tcfc : $@convention(method) (UInt16, @owned PkgKlassZ) -> @owned PkgKlassZ { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassZC8rawValueACs6UInt16V_tcfc : $@convention(method) (UInt16, @owned PkgKlassZ) -> @owned PkgKlassZ { self.rawValue = rawValue self.env = 1 << rawValue } package func pkgFunc() { - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP7pkgFuncyyFTW : $@convention(witness_method: PkgProto) (@in_guaranteed PkgKlassZ) -> () { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgKlassZC7pkgFuncyyF : $@convention(method) (@guaranteed PkgKlassZ) -> () { + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP7pkgFuncyyFTW + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgKlassZC7pkgFuncyyF print(env) } } package struct PkgStruct: PkgProto { /// NOTE: witness thunks get `shared` linkage // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgStructVAA0B5ProtoA2aDP4roots6UInt16VvgZTW : $@convention(witness_method: PkgProto) (@thick PkgStruct.Type) -> UInt16 { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgStructV4roots6UInt16VvgZ : $@convention(method) (@thin PkgStruct.Type) -> UInt16 { - // FIXME: PkgStruct.root.unsafeMutableAddressor -- not generated for PubStruct; should this be removed? - // CHECK-DAG: sil package_external [global_init] [canonical] @$s3Lib9PkgStructV4roots6UInt16Vvau : $@convention(thin) () -> Builtin.RawPointer { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgStructV4roots6UInt16VvgZ + // CHECK-DAG: sil package_external [global_init] [canonical] @$s3Lib9PkgStructV4roots6UInt16Vvau : $@convention(thin) () -> Builtin.RawPointer package static let root: UInt16 = 1 << 0 // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgStructVAA0B5ProtoA2aDP3envs6UInt16VvsTW : $@convention(witness_method: PkgProto) (UInt16, @inout PkgStruct) -> () { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgStructV3envs6UInt16Vvs : $@convention(method) (UInt16, @inout PkgStruct) -> () { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgStructV3envs6UInt16Vvs package var env: UInt16 - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib9PkgStructV8rawValues6UInt16Vvg : $@convention(method) (PkgStruct) -> UInt16 { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgStructV8rawValues6UInt16Vvg package let rawValue: UInt16 package init(rawValue: UInt16) { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib9PkgStructVAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW : $@convention(witness_method: PkgProto) (UInt16, @thick PkgStruct.Type) -> @out PkgStruct { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgStructV8rawValueACs6UInt16V_tcfC : $@convention(method) (UInt16, @thin PkgStruct.Type) -> PkgStruct { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgStructV8rawValueACs6UInt16V_tcfC self.rawValue = rawValue self.env = 1 << rawValue } package func pkgFunc() { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib9PkgStructV7pkgFuncyyF : $@convention(method) (PkgStruct) -> () { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib9PkgStructV7pkgFuncyyF print(env) } } @@ -468,9 +418,9 @@ package struct PkgStructX: PkgSimpleProto, InternalProto { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib10PkgStructXVAA0B11SimpleProtoA2aDP6pkgVarSivgTW : $@convention(witness_method: PkgSimpleProto) (@in_guaranteed PkgStructX) -> Int { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib10PkgStructXVAA0B11SimpleProtoA2aDP6pkgVarSivsTW : $@convention(witness_method: PkgSimpleProto) (Int, @inout PkgStructX) -> () { // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib10PkgStructXVAA0B11SimpleProtoA2aDP6pkgVarSivMTW : $@yield_once @convention(witness_method: PkgSimpleProto) @substituted <τ_0_0> (@inout τ_0_0) -> @yields @inout Int for { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib10PkgStructXV6pkgVarSivM : $@yield_once @convention(method) (@inout PkgStructX) -> @yields @inout Int { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib10PkgStructXV6pkgVarSivg : $@convention(method) (@guaranteed PkgStructX) -> Int { - // CHECK-DAG: sil package [transparent] [serialized] [canonical] [ossa] @$s3Lib10PkgStructXV6pkgVarSivs : $@convention(method) (Int, @inout PkgStructX) -> () { + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib10PkgStructXV6pkgVarSivM + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib10PkgStructXV6pkgVarSivg + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib10PkgStructXV6pkgVarSivs package var pkgVar: Int var intVar: InternalStruct package init(_ arg: Int) { @@ -478,8 +428,8 @@ package struct PkgStructX: PkgSimpleProto, InternalProto { self.pkgVar = arg } package func pkgFunc() -> Int { - // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib10PkgStructXVAA0B11SimpleProtoA2aDP7pkgFuncSiyFTW : $@convention(witness_method: PkgSimpleProto) (@in_guaranteed PkgStructX) -> Int { - // CHECK-DAG: sil package [serialized] [canonical] @$s3Lib10PkgStructXV7pkgFuncSiyF : $@convention(method) (@guaranteed PkgStructX) -> Int { + // CHECK-DAG: sil shared [transparent] [serialized] [thunk] [canonical] [ossa] @$s3Lib10PkgStructXVAA0B11SimpleProtoA2aDP7pkgFuncSiyFTW + // CHECK-DAG: sil package [serialized_for_package] [canonical] [ossa] @$s3Lib10PkgStructXV7pkgFuncSiyF return pkgVar } func intFunc() -> InternalStruct { @@ -491,7 +441,6 @@ package struct PkgStructX: PkgSimpleProto, InternalProto { package struct PkgStructY: InternalProto { var intVar: InternalStruct package init() { - // FIXME: definition for .init is not generated at all; should it be generated (without [serialized]) like public? self.intVar = InternalStruct(name: "foo") } func intFunc() -> InternalStruct { @@ -507,135 +456,45 @@ package func runPkg(_ arg: [any PkgProto]) { print(arg) } -//CHECK-LABEL: sil_vtable [serialized] ParentPubKlass { -//CHECK-NEXT: #ParentPubKlass.parentPubVar!getter: (ParentPubKlass) -> () -> Int : @$s3Lib14ParentPubKlassC06parentC3VarSivg -//CHECK-NEXT: #ParentPubKlass.parentPubVar!setter: (ParentPubKlass) -> (Int) -> () : @$s3Lib14ParentPubKlassC06parentC3VarSivs -//CHECK-NEXT: #ParentPubKlass.parentPubVar!modify: (ParentPubKlass) -> () -> () : @$s3Lib14ParentPubKlassC06parentC3VarSivM -//CHECK-NEXT: #ParentPubKlass.init!allocator: (ParentPubKlass.Type) -> (Int) -> ParentPubKlass : @$s3Lib14ParentPubKlassCyACSicfC -//CHECK-NEXT: #ParentPubKlass.parentPubFunc: (ParentPubKlass) -> () -> () : @$s3Lib14ParentPubKlassC06parentC4FuncyyF -//CHECK-NEXT: #ParentPubKlass.deinit!deallocator: @$s3Lib14ParentPubKlassCfD - -//CHECK-LABEL: sil_vtable [serialized] PubKlass { -//CHECK-NEXT: #ParentPubKlass.parentPubVar!getter: (ParentPubKlass) -> () -> Int : @$s3Lib14ParentPubKlassC06parentC3VarSivg [inherited] -//CHECK-NEXT: #ParentPubKlass.parentPubVar!setter: (ParentPubKlass) -> (Int) -> () : @$s3Lib14ParentPubKlassC06parentC3VarSivs [inherited] -//CHECK-NEXT: #ParentPubKlass.parentPubVar!modify: (ParentPubKlass) -> () -> () : @$s3Lib14ParentPubKlassC06parentC3VarSivM [inherited] -//CHECK-NEXT: #ParentPubKlass.init!allocator: (ParentPubKlass.Type) -> (Int) -> ParentPubKlass : @$s3Lib8PubKlassCyACSicfC [override] -//CHECK-NEXT: #ParentPubKlass.parentPubFunc: (ParentPubKlass) -> () -> () : @$s3Lib8PubKlassC06parentB4FuncyyF [override] -//CHECK-NEXT: #PubKlass.pubVar!getter: (PubKlass) -> () -> String : @$s3Lib8PubKlassC6pubVarSSvg -//CHECK-NEXT: #PubKlass.pubVar!setter: (PubKlass) -> (String) -> () : @$s3Lib8PubKlassC6pubVarSSvs -//CHECK-NEXT: #PubKlass.pubVar!modify: (PubKlass) -> () -> () : @$s3Lib8PubKlassC6pubVarSSvM -//CHECK-NEXT: #PubKlass.init!allocator: (PubKlass.Type) -> (String) -> PubKlass : @$s3Lib8PubKlassCyACSScfC -//CHECK-NEXT: #PubKlass.pubFunc: (PubKlass) -> () -> () : @$s3Lib8PubKlassC7pubFuncyyF -//CHECK-NEXT: #PubKlass.deinit!deallocator: @$s3Lib8PubKlassCfD - -//CHECK-LABEL: sil_vtable [serialized] ParentPubKlassWithInternalMemberX { -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubVar!getter: (ParentPubKlassWithInternalMemberX) -> () -> Int : @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC3VarSivg -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubVar!setter: (ParentPubKlassWithInternalMemberX) -> (Int) -> () : @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC3VarSivs -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubVar!modify: (ParentPubKlassWithInternalMemberX) -> () -> () : @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC3VarSivM -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.init!allocator: (ParentPubKlassWithInternalMemberX.Type) -> (Int) -> ParentPubKlassWithInternalMemberX : @$s3Lib33ParentPubKlassWithInternalMemberXCyACSicfC -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubFuncA: (ParentPubKlassWithInternalMemberX) -> () -> () : @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC5FuncAyyF -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubFuncB: (ParentPubKlassWithInternalMemberX) -> () -> () : @$s3Lib33ParentPubKlassWithInternalMemberXC06parentC5FuncByyF -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.deinit!deallocator: @$s3Lib33ParentPubKlassWithInternalMemberXCfD - -//CHECK-LABEL: sil_vtable [serialized] PubKlassX { -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubVar!getter: (ParentPubKlassWithInternalMemberX) -> () -> Int : @$s3Lib9PubKlassXC06parentB3VarSivg [override] -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubVar!setter: (ParentPubKlassWithInternalMemberX) -> (Int) -> () : @$s3Lib9PubKlassXC06parentB3VarSivs [override] -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubVar!modify: (ParentPubKlassWithInternalMemberX) -> () -> () : @$s3Lib9PubKlassXC06parentB3VarSivM [override] -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.init!allocator: (ParentPubKlassWithInternalMemberX.Type) -> (Int) -> ParentPubKlassWithInternalMemberX : @$s3Lib9PubKlassXCyACSicfC [override] -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubFuncA: (ParentPubKlassWithInternalMemberX) -> () -> () : @$s3Lib9PubKlassXC06parentB5FuncAyyF [override] -//CHECK-NEXT: #ParentPubKlassWithInternalMemberX.parentPubFuncB: (ParentPubKlassWithInternalMemberX) -> () -> () : @$s3Lib9PubKlassXC06parentB5FuncByyF [override] -//CHECK-NEXT: #PubKlassX.pubVar!getter: (PubKlassX) -> () -> String : @$s3Lib9PubKlassXC6pubVarSSvg -//CHECK-NEXT: #PubKlassX.pubVar!setter: (PubKlassX) -> (String) -> () : @$s3Lib9PubKlassXC6pubVarSSvs -//CHECK-NEXT: #PubKlassX.pubVar!modify: (PubKlassX) -> () -> () : @$s3Lib9PubKlassXC6pubVarSSvM -//CHECK-NEXT: #PubKlassX.init!allocator: (PubKlassX.Type) -> () -> PubKlassX : @$s3Lib9PubKlassXCACycfC -//CHECK-NEXT: #PubKlassX.pubFunc: (PubKlassX) -> () -> () : @$s3Lib9PubKlassXC7pubFuncyyF -//CHECK-NEXT: #PubKlassX.deinit!deallocator: @$s3Lib9PubKlassXCfD - -//CHECK-LABEL: sil_vtable [serialized] ParentPubKlassWithInternalMemberY { -//CHECK-NEXT: #ParentPubKlassWithInternalMemberY.init!allocator: (ParentPubKlassWithInternalMemberY.Type) -> (Int) -> ParentPubKlassWithInternalMemberY : @$s3Lib33ParentPubKlassWithInternalMemberYCyACSicfC -//CHECK-NEXT: #ParentPubKlassWithInternalMemberY.deinit!deallocator: @$s3Lib33ParentPubKlassWithInternalMemberYCfD - -//CHECK-LABEL: sil_vtable [serialized] PubKlassY { -//CHECK-NEXT: #ParentPubKlassWithInternalMemberY.init!allocator: (ParentPubKlassWithInternalMemberY.Type) -> (Int) -> ParentPubKlassWithInternalMemberY : @$s3Lib9PubKlassYCyACSicfC [override] -//CHECK-NEXT: #PubKlassY.pubVar!getter: (PubKlassY) -> () -> String : @$s3Lib9PubKlassYC6pubVarSSvg -//CHECK-NEXT: #PubKlassY.pubVar!setter: (PubKlassY) -> (String) -> () : @$s3Lib9PubKlassYC6pubVarSSvs -//CHECK-NEXT: #PubKlassY.pubVar!modify: (PubKlassY) -> () -> () : @$s3Lib9PubKlassYC6pubVarSSvM -//CHECK-NEXT: #PubKlassY.init!allocator: (PubKlassY.Type) -> () -> PubKlassY : @$s3Lib9PubKlassYCACycfC -//CHECK-NEXT: #PubKlassY.deinit!deallocator: @$s3Lib9PubKlassYCfD - -//CHECK-LABEL: sil_vtable [serialized] ParentPkgKlass { -//CHECK-NEXT: #ParentPkgKlass.parentPkgVar!getter: (ParentPkgKlass) -> () -> Int : @$s3Lib14ParentPkgKlassC06parentC3VarSivg -//CHECK-NEXT: #ParentPkgKlass.parentPkgVar!setter: (ParentPkgKlass) -> (Int) -> () : @$s3Lib14ParentPkgKlassC06parentC3VarSivs -//CHECK-NEXT: #ParentPkgKlass.parentPkgVar!modify: (ParentPkgKlass) -> () -> () : @$s3Lib14ParentPkgKlassC06parentC3VarSivM -//CHECK-NEXT: #ParentPkgKlass.init!allocator: (ParentPkgKlass.Type) -> (Int) -> ParentPkgKlass : @$s3Lib14ParentPkgKlassCyACSicfC -//CHECK-NEXT: #ParentPkgKlass.parentPkgFunc: (ParentPkgKlass) -> () -> Int : @$s3Lib14ParentPkgKlassC06parentC4FuncSiyF -//CHECK-NEXT: #ParentPkgKlass.deinit!deallocator: @$s3Lib14ParentPkgKlassCfD - -//CHECK-LABEL: sil_vtable [serialized] PkgKlass { -//CHECK-NEXT: #ParentPkgKlass.parentPkgVar!getter: (ParentPkgKlass) -> () -> Int : @$s3Lib14ParentPkgKlassC06parentC3VarSivg [inherited] -//CHECK-NEXT: #ParentPkgKlass.parentPkgVar!setter: (ParentPkgKlass) -> (Int) -> () : @$s3Lib14ParentPkgKlassC06parentC3VarSivs [inherited] -//CHECK-NEXT: #ParentPkgKlass.parentPkgVar!modify: (ParentPkgKlass) -> () -> () : @$s3Lib14ParentPkgKlassC06parentC3VarSivM [inherited] -//CHECK-NEXT: #ParentPkgKlass.init!allocator: (ParentPkgKlass.Type) -> (Int) -> ParentPkgKlass : @$s3Lib8PkgKlassCyACSicfC [override] -//CHECK-NEXT: #ParentPkgKlass.parentPkgFunc: (ParentPkgKlass) -> () -> Int : @$s3Lib8PkgKlassC06parentB4FuncSiyF [override] -//CHECK-NEXT: #PkgKlass.pkgVar!getter: (PkgKlass) -> () -> String : @$s3Lib8PkgKlassC6pkgVarSSvg -//CHECK-NEXT: #PkgKlass.pkgVar!setter: (PkgKlass) -> (String) -> () : @$s3Lib8PkgKlassC6pkgVarSSvs -//CHECK-NEXT: #PkgKlass.pkgVar!modify: (PkgKlass) -> () -> () : @$s3Lib8PkgKlassC6pkgVarSSvM -//CHECK-NEXT: #PkgKlass.init!allocator: (PkgKlass.Type) -> (String) -> PkgKlass : @$s3Lib8PkgKlassCyACSScfC -//CHECK-NEXT: #PkgKlass.pkgFunc: (PkgKlass) -> () -> () : @$s3Lib8PkgKlassC7pkgFuncyyF -//CHECK-NEXT: #PkgKlass.deinit!deallocator: @$s3Lib8PkgKlassCfD - -//CHECK-LABEL: sil_vtable [serialized] ParentPkgKlassWithInternalMemberX { -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgVar!getter: (ParentPkgKlassWithInternalMemberX) -> () -> Int : @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC3VarSivg -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgVar!setter: (ParentPkgKlassWithInternalMemberX) -> (Int) -> () : @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC3VarSivs -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgVar!modify: (ParentPkgKlassWithInternalMemberX) -> () -> () : @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC3VarSivM -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.init!allocator: (ParentPkgKlassWithInternalMemberX.Type) -> (Int) -> ParentPkgKlassWithInternalMemberX : @$s3Lib33ParentPkgKlassWithInternalMemberXCyACSicfC -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgFuncA: (ParentPkgKlassWithInternalMemberX) -> () -> () : @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC5FuncAyyF -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgFuncB: (ParentPkgKlassWithInternalMemberX) -> () -> () : @$s3Lib33ParentPkgKlassWithInternalMemberXC06parentC5FuncByyF -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.deinit!deallocator: @$s3Lib33ParentPkgKlassWithInternalMemberXCfD - -//CHECK-LABEL: sil_vtable [serialized] PkgKlassX { -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgVar!getter: (ParentPkgKlassWithInternalMemberX) -> () -> Int : @$s3Lib9PkgKlassXC06parentB3VarSivg [override] -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgVar!setter: (ParentPkgKlassWithInternalMemberX) -> (Int) -> () : @$s3Lib9PkgKlassXC06parentB3VarSivs [override] -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgVar!modify: (ParentPkgKlassWithInternalMemberX) -> () -> () : @$s3Lib9PkgKlassXC06parentB3VarSivM [override] -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.init!allocator: (ParentPkgKlassWithInternalMemberX.Type) -> (Int) -> ParentPkgKlassWithInternalMemberX : @$s3Lib9PkgKlassXCyACSicfC [override] -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgFuncA: (ParentPkgKlassWithInternalMemberX) -> () -> () : @$s3Lib9PkgKlassXC06parentB5FuncAyyF [override] -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberX.parentPkgFuncB: (ParentPkgKlassWithInternalMemberX) -> () -> () : @$s3Lib9PkgKlassXC06parentB5FuncByyF [override] -//CHECK-NEXT: #PkgKlassX.pkgVar!getter: (PkgKlassX) -> () -> String : @$s3Lib9PkgKlassXC6pkgVarSSvg -//CHECK-NEXT: #PkgKlassX.pkgVar!setter: (PkgKlassX) -> (String) -> () : @$s3Lib9PkgKlassXC6pkgVarSSvs -//CHECK-NEXT: #PkgKlassX.pkgVar!modify: (PkgKlassX) -> () -> () : @$s3Lib9PkgKlassXC6pkgVarSSvM -//CHECK-NEXT: #PkgKlassX.init!allocator: (PkgKlassX.Type) -> () -> PkgKlassX : @$s3Lib9PkgKlassXCACycfC -//CHECK-NEXT: #PkgKlassX.pubFunc: (PkgKlassX) -> () -> () : @$s3Lib9PkgKlassXC7pubFuncyyF -//CHECK-NEXT: #PkgKlassX.deinit!deallocator: @$s3Lib9PkgKlassXCfD - -//CHECK-LABEL: sil_vtable [serialized] ParentPkgKlassWithInternalMemberY { -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberY.init!allocator: (ParentPkgKlassWithInternalMemberY.Type) -> (Int) -> ParentPkgKlassWithInternalMemberY : @$s3Lib33ParentPkgKlassWithInternalMemberYCyACSicfC -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberY.deinit!deallocator: @$s3Lib33ParentPkgKlassWithInternalMemberYCfD - -//CHECK-LABEL: sil_vtable [serialized] PkgKlassY { -//CHECK-NEXT: #ParentPkgKlassWithInternalMemberY.init!allocator: (ParentPkgKlassWithInternalMemberY.Type) -> (Int) -> ParentPkgKlassWithInternalMemberY : @$s3Lib9PkgKlassYCyACSicfC [override] -//CHECK-NEXT: #PkgKlassY.pkgVar!getter: (PkgKlassY) -> () -> String : @$s3Lib9PkgKlassYC6pkgVarSSvg -//CHECK-NEXT: #PkgKlassY.pkgVar!setter: (PkgKlassY) -> (String) -> () : @$s3Lib9PkgKlassYC6pkgVarSSvs -//CHECK-NEXT: #PkgKlassY.pkgVar!modify: (PkgKlassY) -> () -> () : @$s3Lib9PkgKlassYC6pkgVarSSvM -//CHECK-NEXT: #PkgKlassY.init!allocator: (PkgKlassY.Type) -> () -> PkgKlassY : @$s3Lib9PkgKlassYCACycfC -//CHECK-NEXT: #PkgKlassY.deinit!deallocator: @$s3Lib9PkgKlassYCfD - -//CHECK-LABEL: sil_vtable [serialized] PubKlassZ { -//CHECK-NEXT: #PubKlassZ.env!getter: (PubKlassZ) -> () -> UInt16 : @$s3Lib9PubKlassZC3envs6UInt16Vvg -//CHECK-NEXT: #PubKlassZ.env!setter: (PubKlassZ) -> (UInt16) -> () : @$s3Lib9PubKlassZC3envs6UInt16Vvs -//CHECK-NEXT: #PubKlassZ.env!modify: (PubKlassZ) -> () -> () : @$s3Lib9PubKlassZC3envs6UInt16VvM -//CHECK-NEXT: #PubKlassZ.init!allocator: (PubKlassZ.Type) -> (UInt16) -> PubKlassZ : @$s3Lib9PubKlassZC8rawValueACs6UInt16V_tcfC -//CHECK-NEXT: #PubKlassZ.pubFunc: (PubKlassZ) -> () -> () : @$s3Lib9PubKlassZC7pubFuncyyF -//CHECK-NEXT: #PubKlassZ.deinit!deallocator: @$s3Lib9PubKlassZCfD - -//CHECK-LABEL: sil_vtable [serialized] PkgKlassZ { -//CHECK-NEXT: #PkgKlassZ.env!getter: (PkgKlassZ) -> () -> UInt16 : @$s3Lib9PkgKlassZC3envs6UInt16Vvg -//CHECK-NEXT: #PkgKlassZ.env!setter: (PkgKlassZ) -> (UInt16) -> () : @$s3Lib9PkgKlassZC3envs6UInt16Vvs -//CHECK-NEXT: #PkgKlassZ.env!modify: (PkgKlassZ) -> () -> () : @$s3Lib9PkgKlassZC3envs6UInt16VvM -//CHECK-NEXT: #PkgKlassZ.init!allocator: (PkgKlassZ.Type) -> (UInt16) -> PkgKlassZ : @$s3Lib9PkgKlassZC8rawValueACs6UInt16V_tcfC -//CHECK-NEXT: #PkgKlassZ.pkgFunc: (PkgKlassZ) -> () -> () : @$s3Lib9PkgKlassZC7pkgFuncyyF -//CHECK-NEXT: #PkgKlassZ.deinit!deallocator: @$s3Lib9PkgKlassZCfD - -//CHECK-LABEL: sil_witness_table [serialized] PubKlassZ: PubProto module Lib { + + +// CHECK-LABEL: sil_vtable [serialized_for_package] ParentPubKlass { +// CHECK-NEXT: #ParentPubKlass.parentPubVar!getter: (ParentPubKlass) -> () -> Int : @$s3Lib14ParentPubKlassC06parentC3VarSivg // ParentPubKlass.parentPubVar.getter +// CHECK-NEXT: #ParentPubKlass.parentPubVar!setter: (ParentPubKlass) -> (Int) -> () : @$s3Lib14ParentPubKlassC06parentC3VarSivs // ParentPubKlass.parentPubVar.setter +// CHECK-NEXT: #ParentPubKlass.parentPubVar!modify: (ParentPubKlass) -> () -> () : @$s3Lib14ParentPubKlassC06parentC3VarSivM // ParentPubKlass.parentPubVar.modify +// CHECK-NEXT: #ParentPubKlass.init!allocator: (ParentPubKlass.Type) -> (Int) -> ParentPubKlass : @$s3Lib14ParentPubKlassCyACSicfC // ParentPubKlass.__allocating_init(_:) +// CHECK-NEXT: #ParentPubKlass.parentPubFunc: (ParentPubKlass) -> () -> () : @$s3Lib14ParentPubKlassC06parentC4FuncyyF // ParentPubKlass.parentPubFunc() +// CHECK-NEXT: #ParentPubKlass.deinit!deallocator: @$s3Lib14ParentPubKlassCfD // ParentPubKlass.__deallocating_deinit + + +// CHECK-LABEL: sil_vtable [serialized_for_package] ParentPkgKlass { +// CHECK-NEXT: #ParentPkgKlass.parentPkgVar!getter: (ParentPkgKlass) -> () -> Int : @$s3Lib14ParentPkgKlassC06parentC3VarSivg // ParentPkgKlass.parentPkgVar.getter +// CHECK-NEXT: #ParentPkgKlass.parentPkgVar!setter: (ParentPkgKlass) -> (Int) -> () : @$s3Lib14ParentPkgKlassC06parentC3VarSivs // ParentPkgKlass.parentPkgVar.setter +// CHECK-NEXT: #ParentPkgKlass.parentPkgVar!modify: (ParentPkgKlass) -> () -> () : @$s3Lib14ParentPkgKlassC06parentC3VarSivM // ParentPkgKlass.parentPkgVar.modify +// CHECK-NEXT: #ParentPkgKlass.init!allocator: (ParentPkgKlass.Type) -> (Int) -> ParentPkgKlass : @$s3Lib14ParentPkgKlassCyACSicfC // ParentPkgKlass.__allocating_init(_:) +// CHECK-NEXT: #ParentPkgKlass.parentPkgFunc: (ParentPkgKlass) -> () -> Int : @$s3Lib14ParentPkgKlassC06parentC4FuncSiyF // ParentPkgKlass.parentPkgFunc() +// CHECK-NEXT: #ParentPkgKlass.deinit!deallocator: @$s3Lib14ParentPkgKlassCfD // ParentPkgKlass.__deallocating_deinit + + +// CHECK-LABEL: sil_vtable [serialized_for_package] PubKlassZ { +// CHECK-NEXT: #PubKlassZ.env!getter: (PubKlassZ) -> () -> UInt16 : @$s3Lib9PubKlassZC3envs6UInt16Vvg // PubKlassZ.env.getter +// CHECK-NEXT: #PubKlassZ.env!setter: (PubKlassZ) -> (UInt16) -> () : @$s3Lib9PubKlassZC3envs6UInt16Vvs // PubKlassZ.env.setter +// CHECK-NEXT: #PubKlassZ.env!modify: (PubKlassZ) -> () -> () : @$s3Lib9PubKlassZC3envs6UInt16VvM // PubKlassZ.env.modify +// CHECK-NEXT: #PubKlassZ.init!allocator: (PubKlassZ.Type) -> (UInt16) -> PubKlassZ : @$s3Lib9PubKlassZC8rawValueACs6UInt16V_tcfC // PubKlassZ.__allocating_init(rawValue:) +// CHECK-NEXT: #PubKlassZ.pubFunc: (PubKlassZ) -> () -> () : @$s3Lib9PubKlassZC7pubFuncyyF // PubKlassZ.pubFunc() +// CHECK-NEXT: #PubKlassZ.deinit!deallocator: @$s3Lib9PubKlassZCfD // PubKlassZ.__deallocating_deinit + + +// CHECK-LABEL: sil_vtable [serialized_for_package] PkgKlassZ { +// CHECK-NEXT: #PkgKlassZ.env!getter: (PkgKlassZ) -> () -> UInt16 : @$s3Lib9PkgKlassZC3envs6UInt16Vvg // PkgKlassZ.env.getter +// CHECK-NEXT: #PkgKlassZ.env!setter: (PkgKlassZ) -> (UInt16) -> () : @$s3Lib9PkgKlassZC3envs6UInt16Vvs // PkgKlassZ.env.setter +// CHECK-NEXT: #PkgKlassZ.env!modify: (PkgKlassZ) -> () -> () : @$s3Lib9PkgKlassZC3envs6UInt16VvM // PkgKlassZ.env.modify +// CHECK-NEXT: #PkgKlassZ.init!allocator: (PkgKlassZ.Type) -> (UInt16) -> PkgKlassZ : @$s3Lib9PkgKlassZC8rawValueACs6UInt16V_tcfC // PkgKlassZ.__allocating_init(rawValue:) +// CHECK-NEXT: #PkgKlassZ.pkgFunc: (PkgKlassZ) -> () -> () : @$s3Lib9PkgKlassZC7pkgFuncyyF // PkgKlassZ.pkgFunc() +// CHECK-NEXT: #PkgKlassZ.deinit!deallocator: @$s3Lib9PkgKlassZCfD // PkgKlassZ.__deallocating_deinit + + +//CHECK-LABEL: sil_witness_table [serialized_for_package] PubKlassZ: PubProto module Lib { //CHECK-NEXT: associated_type Element: PubKlassZ //CHECK-NEXT: method #PubProto.root!getter: (Self.Type) -> () -> UInt16 : @$s3Lib9PubKlassZCAA0B5ProtoA2aDP4roots6UInt16VvgZTW //CHECK-NEXT: method #PubProto.env!getter: (Self) -> () -> UInt16 : @$s3Lib9PubKlassZCAA0B5ProtoA2aDP3envs6UInt16VvgTW @@ -644,7 +503,7 @@ package func runPkg(_ arg: [any PkgProto]) { //CHECK-NEXT: method #PubProto.init!allocator: (Self.Type) -> (UInt16) -> Self : @$s3Lib9PubKlassZCAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW //CHECK-NEXT: method #PubProto.pubFunc: (Self) -> () -> () : @$s3Lib9PubKlassZCAA0B5ProtoA2aDP7pubFuncyyFTW -//CHECK-LABEL: sil_witness_table [serialized] PubStruct: PubProto module Lib { +//CHECK-LABEL: sil_witness_table [serialized_for_package] PubStruct: PubProto module Lib { //CHECK-NEXT: associated_type Element: PubStruct //CHECK-NEXT: method #PubProto.root!getter: (Self.Type) -> () -> UInt16 : @$s3Lib9PubStructVAA0B5ProtoA2aDP4roots6UInt16VvgZTW //CHECK-NEXT: method #PubProto.env!getter: (Self) -> () -> UInt16 : @$s3Lib9PubStructVAA0B5ProtoA2aDP3envs6UInt16VvgTW @@ -653,13 +512,13 @@ package func runPkg(_ arg: [any PkgProto]) { //CHECK-NEXT: method #PubProto.init!allocator: (Self.Type) -> (UInt16) -> Self : @$s3Lib9PubStructVAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW //CHECK-NEXT: method #PubProto.pubFunc: (Self) -> () -> () : @$s3Lib9PubStructVAA0B5ProtoA2aDP7pubFuncyyFTW -//CHECK-LABEL: sil_witness_table [serialized] PubStructX: PubSimpleProto module Lib { +//CHECK-LABEL: sil_witness_table [serialized_for_package] PubStructX: PubSimpleProto module Lib { //CHECK-NEXT: method #PubSimpleProto.pubVar!getter: (Self) -> () -> Int : @$s3Lib10PubStructXVAA0B11SimpleProtoA2aDP6pubVarSivgTW //CHECK-NEXT: method #PubSimpleProto.pubVar!setter: (inout Self) -> (Int) -> () : @$s3Lib10PubStructXVAA0B11SimpleProtoA2aDP6pubVarSivsTW //CHECK-NEXT: method #PubSimpleProto.pubVar!modify: (inout Self) -> () -> () : @$s3Lib10PubStructXVAA0B11SimpleProtoA2aDP6pubVarSivMTW //CHECK-NEXT: method #PubSimpleProto.pubFunc: (Self) -> () -> Int : @$s3Lib10PubStructXVAA0B11SimpleProtoA2aDP7pubFuncSiyFTW -//CHECK-LABEL: sil_witness_table package [serialized] PkgKlassZ: PkgProto module Lib { +//CHECK-LABEL: sil_witness_table package [serialized_for_package] PkgKlassZ: PkgProto module Lib { //CHECK-NEXT: associated_type Element: PkgKlassZ //CHECK-NEXT: method #PkgProto.root!getter: (Self.Type) -> () -> UInt16 : @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP4roots6UInt16VvgZTW //CHECK-NEXT: method #PkgProto.env!getter: (Self) -> () -> UInt16 : @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP3envs6UInt16VvgTW @@ -668,7 +527,7 @@ package func runPkg(_ arg: [any PkgProto]) { //CHECK-NEXT: method #PkgProto.init!allocator: (Self.Type) -> (UInt16) -> Self : @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW //CHECK-NEXT: method #PkgProto.pkgFunc: (Self) -> () -> () : @$s3Lib9PkgKlassZCAA0B5ProtoA2aDP7pkgFuncyyFTW -//CHECK-LABEL: sil_witness_table package [serialized] PkgStruct: PkgProto module Lib { +//CHECK-LABEL: sil_witness_table package [serialized_for_package] PkgStruct: PkgProto module Lib { //CHECK-NEXT: associated_type Element: PkgStruct //CHECK-NEXT: method #PkgProto.root!getter: (Self.Type) -> () -> UInt16 : @$s3Lib9PkgStructVAA0B5ProtoA2aDP4roots6UInt16VvgZTW //CHECK-NEXT: method #PkgProto.env!getter: (Self) -> () -> UInt16 : @$s3Lib9PkgStructVAA0B5ProtoA2aDP3envs6UInt16VvgTW @@ -677,7 +536,7 @@ package func runPkg(_ arg: [any PkgProto]) { //CHECK-NEXT: method #PkgProto.init!allocator: (Self.Type) -> (UInt16) -> Self : @$s3Lib9PkgStructVAA0B5ProtoA2aDP8rawValuexs6UInt16V_tcfCTW //CHECK-NEXT: method #PkgProto.pkgFunc: (Self) -> () -> () : @$s3Lib9PkgStructVAA0B5ProtoA2aDP7pkgFuncyyFTW -//CHECK-LABEL: sil_witness_table package [serialized] PkgStructX: PkgSimpleProto module Lib { +//CHECK-LABEL: sil_witness_table package [serialized_for_package] PkgStructX: PkgSimpleProto module Lib { //CHECK-NEXT: method #PkgSimpleProto.pkgVar!getter: (Self) -> () -> Int : @$s3Lib10PkgStructXVAA0B11SimpleProtoA2aDP6pkgVarSivgTW //CHECK-NEXT: method #PkgSimpleProto.pkgVar!setter: (inout Self) -> (Int) -> () : @$s3Lib10PkgStructXVAA0B11SimpleProtoA2aDP6pkgVarSivsTW //CHECK-NEXT: method #PkgSimpleProto.pkgVar!modify: (inout Self) -> () -> () : @$s3Lib10PkgStructXVAA0B11SimpleProtoA2aDP6pkgVarSivMTW diff --git a/test/SILOptimizer/package-cmo-skip-internal-generic.swift b/test/SILOptimizer/package-cmo-skip-internal-generic.swift new file mode 100644 index 0000000000000..14abeb5035e5a --- /dev/null +++ b/test/SILOptimizer/package-cmo-skip-internal-generic.swift @@ -0,0 +1,206 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +// RUN: %target-build-swift %t/Lib.swift \ +// RUN: -module-name=Lib -package-name Pkg \ +// RUN: -parse-as-library -emit-module -emit-module-path %t/Lib.swiftmodule -I%t \ +// RUN: -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access \ +// RUN: -O -wmo -enable-library-evolution +// RUN: %target-sil-opt %t/Lib.swiftmodule -sil-verify-all -o %t/Lib.sil + +// RUN: %target-build-swift -module-name=Main -package-name Pkg -I%t -emit-sil -O -wmo -Xllvm -sil-disable-pass=FunctionSignatureOpts %t/main.swift -o %t/Main.sil + +// RUN: %FileCheck %s --check-prefixes=CHECK < %t/Lib.sil +// RUN: %FileCheck %s --check-prefixes=CHECK-MAIN < %t/Main.sil + + +//--- main.swift +import Lib + +// CHECK-MAIN-NOT: s3Lib14createPubClassySixlF +// CHECK-MAIN-NOT: s3Lib19usePubStructKeypathySixlF + +func checkClasses() { + /// Inlined + print(createPubClass(0)) + + /// Not inlined as functions below contain private/internal symbols + // CHECK-MAIN-DAG: function_ref @$s3Lib20createPubClass_neverySixlF + // CHECK-MAIN-DAG: sil public_external [_semantics "optimize.sil.specialize.generic.never"] @$s3Lib20createPubClass_neverySixlF : $@convention(thin) (@in_guaranteed T) -> Int { + print(createPubClass_never(0)) + + // CHECK-MAIN-DAG: function_ref @$s3Lib14createPrvClassySixlF + // CHECK-MAIN-DAG: sil @$s3Lib14createPrvClassySixlF : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> Int + print(createPrvClass(0)) + + // CHECK-MAIN-DAG: function_ref @$s3Lib20createPrvClass_neverySixlF + // CHECK-MAIN-DAG: sil [_semantics "optimize.sil.specialize.generic.never"] @$s3Lib20createPrvClass_neverySixlF : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> Int + print(createPrvClass_never(0)) +} + +func checkNested() { + // PubContainer initializer is inlined. + // CHECK-MAIN-DAG: struct $PubContainer () + let c = PubContainer() + // CHECK-MAIN-DAG: function_ref @$s3Lib12PubContainerV9pubMemberyxxlF + // CHECK-MAIN-DAG: sil @$s3Lib12PubContainerV9pubMemberyxxlF : $@convention(method) <τ_0_0> (@in_guaranteed τ_0_0, @in_guaranteed PubContainer) -> @out τ_0_0 + print(c.pubMember(27)) +} + +func checkKeyPaths() { + /// Inlined + // CHECK-MAIN-DAG: function_ref @$s3Lib19getPubStructKeypathys7KeyPathCyAA0cD0VSiGxlF + print(usePubStructKeypath(0)) + + /// Not inlined as functions below contain private/internal symbols + // CHECK-MAIN-DAG: function_ref @$s3Lib24useInternalStructKeypathySixlF + // CHECK-MAIN-DAG: sil @$s3Lib24useInternalStructKeypathySixlF : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> Int + print(useInternalStructKeypath(0)) + + // CHECK-MAIN-DAG: function_ref @$s3Lib15useClassKeypathySixlF + // CHECK-MAIN-DAG: sil @$s3Lib15useClassKeypathySixlF : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> Int + print(useClassKeypath(0)) +} + +checkNested() +checkClasses() +checkKeyPaths() + + +//--- Lib.swift + +// createPubClass(_:) +// CHECK-DAG: sil [serialized_for_package] [canonical] @$s3Lib14createPubClassySixlF : $@convention(thin) (@in_guaranteed T) -> Int { +public func createPubClass(_ t: T) -> Int { + return getPubClass(t).foo() +} + +// CHECK-DAG: sil [serialized_for_package] [_semantics "optimize.sil.specialize.generic.never"] [canonical] @$s3Lib20createPubClass_neverySixlF : $@convention(thin) (@in_guaranteed T) -> Int { +@_semantics("optimize.sil.specialize.generic.never") +public func createPubClass_never(_ t: T) -> Int { + return getPubClass(t).foo() +} + +// CHECK-DAG: sil [serialized_for_package] [canonical] @$s3Lib11getPubClassyAA13PublicDerivedCyxGxlF : $@convention(thin) (@in_guaranteed T) -> @owned PublicDerived { +public func getPubClass(_ t : T) -> PublicDerived { + return PublicDerived(t) +} + +// Not serialized +public func createPrvClass(_ t: T) -> Int { + return getPrvClass(t).foo() +} + +// Not serialized +@_semantics("optimize.sil.specialize.generic.never") +public func createPrvClass_never(_ t: T) -> Int { + return getPrvClass(t).foo() +} + +// Not serialized +private func getPrvClass(_ t : T) -> PrivateBase { + return PrivateDerived(t) +} + +public class PublicBase { + public var t: T + public func foo() -> Int { return 27 } + public init(_ t: T) { self.t = t } +} + +public class PublicDerived : PublicBase { + override public func foo() -> Int { return 28 } +} + +private class PrivateBase { + var t: T + func foo() -> Int { return 27 } + init(_ t: T) { self.t = t } +} + +private class PrivateDerived : PrivateBase { + override func foo() -> Int { return 28 } +} + +public struct PubContainer { + private final class PrvBase {} + public init() {} + + // Not serialized; contains exported func + // but references a private class. + public func pubMember(_ t: T) -> T { + var arr = Array() + arr.append(PrvBase()) + print(arr) + exportedFunc(arr) + return t + } +} + +@_specialize(exported: true, where T == Int) +@inlinable +public func exportedFunc(_ t: T) { + print(t) +} + +public func pubFunc(_ t: T) -> Int { + return getPubClass(t).foo() +} + +@_semantics("optimize.sil.specialize.generic.never") +public func pubFuncNoSpecialize(_ t: T) -> Int { + return getPubClass(t).foo() +} + + +struct InternalStruct { + var x: Int { return 27 } + var y: Int { return 28 } +} + +public struct PubStruct { + public var x: Int { return 27 } + public var y: Int { return 28 } +} + +class Myclass { + var x: Int { return 27 } + var y: Int { return 28 } +} + +class Derived : Myclass { + override var x: Int { return 29 } + override var y: Int { return 30 } +} + + +func getInternalStructKeypath(_ t: T) -> KeyPath { + return \InternalStruct.x +} + +// CHECK-DAG: sil [canonical] @$s3Lib19getPubStructKeypathys7KeyPathCyAA0cD0VSiGxlF : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> @owned KeyPath +public func getPubStructKeypath(_ t: T) -> KeyPath { + return \PubStruct.x +} + +public func useInternalStructKeypath(_ t: T) -> Int { + let s = InternalStruct() + return s[keyPath: getInternalStructKeypath(t)] +} + +// CHECK-DAG: sil [serialized_for_package] [canonical] @$s3Lib19usePubStructKeypathySixlF : $@convention(thin) (@in_guaranteed T) -> Int { +public func usePubStructKeypath(_ t: T) -> Int { + let p = PubStruct() + return p[keyPath: getPubStructKeypath(t)] +} + +func getClassKeypath(_ t: T) -> KeyPath { + return \Myclass.x +} + + +public func useClassKeypath(_ t: T) -> Int { + let c = Derived() + return c[keyPath: getClassKeypath(t)] +} +