Skip to content

Commit 5b8eaee

Browse files
committed
Update SILBridgedFunction APIs with SerializedKind
1 parent d16dce6 commit 5b8eaee

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyLoad.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private func transitivelyErase(load: LoadInst, _ context: SimplifyContext) {
281281

282282
private extension Value {
283283
func canBeCopied(into function: Function, _ context: SimplifyContext) -> Bool {
284-
if !function.isSerialized {
284+
if !function.isAnySerialized {
285285
return true
286286
}
287287

@@ -297,7 +297,7 @@ private extension Value {
297297

298298
while let value = worklist.pop() {
299299
if let fri = value as? FunctionRefInst {
300-
if !fri.referencedFunction.hasValidLinkageForFragileRef {
300+
if !fri.referencedFunction.hasValidLinkageForFragileRef(function.serializedKind) {
301301
return false
302302
}
303303
}

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,33 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
136136
}
137137
public var isSerialized: Bool { bridged.isSerialized() }
138138

139-
public var hasValidLinkageForFragileRef: Bool { bridged.hasValidLinkageForFragileRef() }
139+
public var isAnySerialized: Bool { bridged.isAnySerialized() }
140+
141+
public enum SerializedKind {
142+
case notSerialized, serialized, serializedForPackage
143+
}
144+
145+
public var serializedKind: SerializedKind {
146+
switch bridged.getSerializedKind() {
147+
case .IsNotSerialized: return .notSerialized
148+
case .IsSerialized: return .serialized
149+
case .IsSerializedForPackage: return .serializedForPackage
150+
default: fatalError()
151+
}
152+
}
153+
154+
private func serializedKindBridged(_ arg: SerializedKind) -> BridgedFunction.SerializedKind {
155+
switch arg {
156+
case .notSerialized: return .IsNotSerialized
157+
case .serialized: return .IsSerialized
158+
case .serializedForPackage: return .IsSerializedForPackage
159+
default: fatalError()
160+
}
161+
}
162+
163+
public func hasValidLinkageForFragileRef(_ kind: SerializedKind) -> Bool {
164+
bridged.hasValidLinkageForFragileRef(serializedKindBridged(kind))
165+
}
140166

141167
public enum ThunkKind {
142168
case noThunk, thunk, reabstractionThunk, signatureOptimizedThunk

include/swift/SIL/SILBridging.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@ struct BridgedFunction {
574574
IsSignatureOptimizedThunk
575575
};
576576

577+
enum class SerializedKind {
578+
IsNotSerialized,
579+
IsSerialized,
580+
IsSerializedForPackage
581+
};
582+
577583
enum class Linkage {
578584
Public,
579585
PublicNonABI,
@@ -621,7 +627,9 @@ struct BridgedFunction {
621627
BRIDGED_INLINE PerformanceConstraints getPerformanceConstraints() const;
622628
BRIDGED_INLINE InlineStrategy getInlineStrategy() const;
623629
BRIDGED_INLINE bool isSerialized() const;
624-
BRIDGED_INLINE bool hasValidLinkageForFragileRef() const;
630+
BRIDGED_INLINE bool isAnySerialized() const;
631+
BRIDGED_INLINE SerializedKind getSerializedKind() const;
632+
BRIDGED_INLINE bool hasValidLinkageForFragileRef(SerializedKind) const;
625633
BRIDGED_INLINE ThunkKind isThunk() const;
626634
BRIDGED_INLINE void setThunk(ThunkKind) const;
627635
BRIDGED_INLINE bool needsStackProtection() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,16 @@ bool BridgedFunction::isSerialized() const {
717717
return getFunction()->isSerialized();
718718
}
719719

720-
bool BridgedFunction::hasValidLinkageForFragileRef() const {
721-
return getFunction()->hasValidLinkageForFragileRef(swift::SerializedKind_t::IsSerialized);
720+
bool BridgedFunction::isAnySerialized() const {
721+
return getFunction()->isAnySerialized();
722+
}
723+
724+
BridgedFunction::SerializedKind BridgedFunction::getSerializedKind() const {
725+
return (SerializedKind)getFunction()->getSerializedKind();
726+
}
727+
728+
bool BridgedFunction::hasValidLinkageForFragileRef(SerializedKind kind) const {
729+
return getFunction()->hasValidLinkageForFragileRef(swift::SerializedKind_t(kind));
722730
}
723731

724732
bool BridgedFunction::needsStackProtection() const {

lib/Serialization/SerializeSIL.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,7 +2948,11 @@ void SILSerializer::writeSILMoveOnlyDeinit(const SILMoveOnlyDeinit &deinit) {
29482948
return;
29492949

29502950
SILFunction *impl = deinit.getImplementation();
2951-
if (!ShouldSerializeAll && !impl->hasValidLinkageForFragileRef(IsSerialized))
2951+
if (!ShouldSerializeAll &&
2952+
// Package CMO for MoveOnlyDeinit is not supported so
2953+
// pass the IsSerialized argument to keep the behavior
2954+
// consistent with or without the optimization.
2955+
!impl->hasValidLinkageForFragileRef(IsSerialized))
29522956
return;
29532957

29542958
// Use the mangled name of the class as a key to distinguish between classes
@@ -3100,7 +3104,11 @@ writeSILDefaultWitnessTable(const SILDefaultWitnessTable &wt) {
31003104
SILAbbrCodes[DefaultWitnessTableNoEntryLayout::Code]);
31013105
continue;
31023106
}
3103-
writeSILWitnessTableEntry(entry, IsNotSerialized);
3107+
3108+
// Default witness table is not serialized. The IsSerialized
3109+
// argument is passed here to call hasValidLinkageForFragileRef
3110+
// to keep the behavior consistent with or without any optimizations.
3111+
writeSILWitnessTableEntry(entry, IsSerialized);
31043112
}
31053113
}
31063114

0 commit comments

Comments
 (0)