Skip to content

Commit b5e61cc

Browse files
committed
[SIL] Serialize the markedAsUsed bit in SILFunction
We were dropping this bit during serialization, so we don't know whether the function was originally marked as "used".
1 parent dd7890e commit b5e61cc

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -734,17 +734,17 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
734734
GenericSignatureID genericSigID;
735735
unsigned rawLinkage, isTransparent, serializedKind, isThunk,
736736
isWithoutActuallyEscapingThunk, specialPurpose, inlineStrategy,
737-
optimizationMode, perfConstr, subclassScope, hasCReferences, effect,
738-
numAttrs, hasQualifiedOwnership, isWeakImported,
737+
optimizationMode, perfConstr, subclassScope, hasCReferences,
738+
markedAsUsed, effect, numAttrs, hasQualifiedOwnership, isWeakImported,
739739
LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass,
740740
isDistributed, isRuntimeAccessible, forceEnableLexicalLifetimes,
741741
onlyReferencedByDebugInfo;
742742
ArrayRef<uint64_t> SemanticsIDs;
743743
SILFunctionLayout::readRecord(
744744
scratch, rawLinkage, isTransparent, serializedKind, isThunk,
745745
isWithoutActuallyEscapingThunk, specialPurpose, inlineStrategy,
746-
optimizationMode, perfConstr, subclassScope, hasCReferences, effect,
747-
numAttrs, hasQualifiedOwnership, isWeakImported,
746+
optimizationMode, perfConstr, subclassScope, hasCReferences, markedAsUsed,
747+
effect, numAttrs, hasQualifiedOwnership, isWeakImported,
748748
LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass,
749749
isDistributed, isRuntimeAccessible, forceEnableLexicalLifetimes,
750750
onlyReferencedByDebugInfo, funcTyID, replacedFunctionID,
@@ -917,6 +917,7 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
917917
fn->setIsAlwaysWeakImported(isWeakImported);
918918
fn->setClassSubclassScope(SubclassScope(subclassScope));
919919
fn->setHasCReferences(bool(hasCReferences));
920+
fn->setMarkedAsUsed(bool(markedAsUsed));
920921

921922
llvm::VersionTuple available;
922923
DECODE_VER_TUPLE(available);
@@ -3967,17 +3968,17 @@ bool SILDeserializer::hasSILFunction(StringRef Name,
39673968
GenericSignatureID genericSigID;
39683969
unsigned rawLinkage, isTransparent, serializedKind, isThunk,
39693970
isWithoutActuallyEscapingThunk, isGlobal, inlineStrategy,
3970-
optimizationMode, perfConstr, subclassScope, hasCReferences, effect,
3971-
numSpecAttrs, hasQualifiedOwnership, isWeakImported,
3971+
optimizationMode, perfConstr, subclassScope, hasCReferences, markedAsUsed,
3972+
effect, numSpecAttrs, hasQualifiedOwnership, isWeakImported,
39723973
LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass,
39733974
isDistributed, isRuntimeAccessible, forceEnableLexicalLifetimes,
39743975
onlyReferencedByDebugInfo;
39753976
ArrayRef<uint64_t> SemanticsIDs;
39763977
SILFunctionLayout::readRecord(
39773978
scratch, rawLinkage, isTransparent, serializedKind, isThunk,
39783979
isWithoutActuallyEscapingThunk, isGlobal, inlineStrategy,
3979-
optimizationMode, perfConstr, subclassScope, hasCReferences, effect,
3980-
numSpecAttrs, hasQualifiedOwnership, isWeakImported,
3980+
optimizationMode, perfConstr, subclassScope, hasCReferences, markedAsUsed,
3981+
effect, numSpecAttrs, hasQualifiedOwnership, isWeakImported,
39813982
LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass,
39823983
isDistributed, isRuntimeAccessible, forceEnableLexicalLifetimes,
39833984
onlyReferencedByDebugInfo, funcTyID, replacedFunctionID,

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 956; // nonisolated(nonsending) isolation was moved
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 957; // SILFunction markedAsUsed
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

lib/Serialization/SILFormat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ namespace sil_block {
374374
BCFixed<3>, // perfConstraints
375375
BCFixed<2>, // classSubclassScope
376376
BCFixed<1>, // hasCReferences
377+
BCFixed<1>, // markedAsUsed
377378
BCFixed<3>, // side effect info.
378379
BCVBR<8>, // number of specialize attributes
379380
BCFixed<1>, // has qualified ownership

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
561561
(unsigned)F.getSpecialPurpose(), (unsigned)F.getInlineStrategy(),
562562
(unsigned)F.getOptimizationMode(), (unsigned)F.getPerfConstraints(),
563563
(unsigned)F.getClassSubclassScope(), (unsigned)F.hasCReferences(),
564-
(unsigned)F.getEffectsKind(), (unsigned)numAttrs,
565-
(unsigned)F.hasOwnership(), F.isAlwaysWeakImported(),
564+
(unsigned)F.markedAsUsed(), (unsigned)F.getEffectsKind(),
565+
(unsigned)numAttrs, (unsigned)F.hasOwnership(), F.isAlwaysWeakImported(),
566566
LIST_VER_TUPLE_PIECES(available), (unsigned)F.isDynamicallyReplaceable(),
567567
(unsigned)F.isExactSelfClass(), (unsigned)F.isDistributed(),
568568
(unsigned)F.isRuntimeAccessible(),

test/embedded/modules-used2.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func foo() {
3030
import MyModule
3131

3232
// CHECK-SIL: // main()
33-
// CHECK-SIL-NEXT: sil @$e8MyModule4mains5Int32VyF : $@convention(thin) () -> Int32 {
33+
// CHECK-SIL-NEXT: sil [used] @$e8MyModule4mains5Int32VyF : $@convention(thin) () -> Int32 {
3434
// CHECK-SIL: // main
35-
// CHECK-SIL-NEXT: sil [thunk] @main : $@convention(c) () -> Int32
35+
// CHECK-SIL-NEXT: sil [thunk] [used] @main : $@convention(c) () -> Int32
3636
// CHECK-SIL: // foo()
37-
// CHECK-SIL-NEXT: sil @$e8MyModule3fooyyF : $@convention(thin) () -> () {
37+
// CHECK-SIL-NEXT: sil [used] @$e8MyModule3fooyyF : $@convention(thin) () -> () {
3838

3939
// CHECK: main in a submodule

0 commit comments

Comments
 (0)