Skip to content

Commit 31c07c9

Browse files
authored
Merge pull request #74689 from eeckstein/refactor-dynamic-self-check
SwiftCompilerSources: refactor `Function.mayBindDynamicSelf`
2 parents b68c55c + c61733f commit 31c07c9

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,12 @@ extension Function {
643643
return nil
644644
}
645645

646+
/// True if this function has a dynamic-self metadata argument and any instruction is type dependent on it.
646647
var mayBindDynamicSelf: Bool {
647-
self.bridged.mayBindDynamicSelf()
648+
guard let dynamicSelf = self.dynamicSelfMetadata else {
649+
return false
650+
}
651+
return dynamicSelf.uses.contains { $0.isTypeDependent }
648652
}
649653
}
650654

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ extension Function {
278278

279279
public var selfArgument: FunctionArgument { arguments[selfArgumentIndex] }
280280

281+
public var dynamicSelfMetadata: FunctionArgument? {
282+
if bridged.hasDynamicSelfMetadata() {
283+
return arguments.last!
284+
}
285+
return nil
286+
}
287+
281288
public var argumentTypes: ArgumentTypeArray { ArgumentTypeArray(function: self) }
282289

283290
public var resultType: Type { bridged.getSILResultType().type }

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ struct BridgedFunction {
622622
BRIDGED_INLINE bool isGeneric() const;
623623
BRIDGED_INLINE bool hasSemanticsAttr(BridgedStringRef attrName) const;
624624
BRIDGED_INLINE bool hasUnsafeNonEscapableResult() const;
625-
bool mayBindDynamicSelf() const;
625+
BRIDGED_INLINE bool hasDynamicSelfMetadata() const;
626626
BRIDGED_INLINE EffectsKind getEffectAttribute() const;
627627
BRIDGED_INLINE PerformanceConstraints getPerformanceConstraints() const;
628628
BRIDGED_INLINE InlineStrategy getInlineStrategy() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ bool BridgedFunction::hasUnsafeNonEscapableResult() const {
687687
return getFunction()->hasUnsafeNonEscapableResult();
688688
}
689689

690+
bool BridgedFunction::hasDynamicSelfMetadata() const {
691+
return getFunction()->hasDynamicSelfMetadata();
692+
}
693+
690694
BridgedFunction::EffectsKind BridgedFunction::getEffectAttribute() const {
691695
return (EffectsKind)getFunction()->getEffectsKind();
692696
}

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,9 +1591,6 @@ SwiftPassInvocation::~SwiftPassInvocation() {}
15911591
//===----------------------------------------------------------------------===//
15921592
// SIL Bridging
15931593
//===----------------------------------------------------------------------===//
1594-
bool BridgedFunction::mayBindDynamicSelf() const {
1595-
return swift::mayBindDynamicSelf(getFunction());
1596-
}
15971594

15981595
bool BridgedFunction::isTrapNoReturn() const {
15991596
return swift::isTrapNoReturnFunction(getFunction());

0 commit comments

Comments
 (0)