Skip to content

SwiftCompilerSources: refactor Function.mayBindDynamicSelf #74689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,12 @@ extension Function {
return nil
}

/// True if this function has a dynamic-self metadata argument and any instruction is type dependent on it.
var mayBindDynamicSelf: Bool {
self.bridged.mayBindDynamicSelf()
guard let dynamicSelf = self.dynamicSelfMetadata else {
return false
}
return dynamicSelf.uses.contains { $0.isTypeDependent }
}
}

Expand Down
7 changes: 7 additions & 0 deletions SwiftCompilerSources/Sources/SIL/Function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ extension Function {

public var selfArgument: FunctionArgument { arguments[selfArgumentIndex] }

public var dynamicSelfMetadata: FunctionArgument? {
if bridged.hasDynamicSelfMetadata() {
return arguments.last!
}
return nil
}

public var argumentTypes: ArgumentTypeArray { ArgumentTypeArray(function: self) }

public var resultType: Type { bridged.getSILResultType().type }
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ struct BridgedFunction {
BRIDGED_INLINE bool isGeneric() const;
BRIDGED_INLINE bool hasSemanticsAttr(BridgedStringRef attrName) const;
BRIDGED_INLINE bool hasUnsafeNonEscapableResult() const;
bool mayBindDynamicSelf() const;
BRIDGED_INLINE bool hasDynamicSelfMetadata() const;
BRIDGED_INLINE EffectsKind getEffectAttribute() const;
BRIDGED_INLINE PerformanceConstraints getPerformanceConstraints() const;
BRIDGED_INLINE InlineStrategy getInlineStrategy() const;
Expand Down
4 changes: 4 additions & 0 deletions include/swift/SIL/SILBridgingImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ bool BridgedFunction::hasUnsafeNonEscapableResult() const {
return getFunction()->hasUnsafeNonEscapableResult();
}

bool BridgedFunction::hasDynamicSelfMetadata() const {
return getFunction()->hasDynamicSelfMetadata();
}

BridgedFunction::EffectsKind BridgedFunction::getEffectAttribute() const {
return (EffectsKind)getFunction()->getEffectsKind();
}
Expand Down
3 changes: 0 additions & 3 deletions lib/SILOptimizer/PassManager/PassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,9 +1591,6 @@ SwiftPassInvocation::~SwiftPassInvocation() {}
//===----------------------------------------------------------------------===//
// SIL Bridging
//===----------------------------------------------------------------------===//
bool BridgedFunction::mayBindDynamicSelf() const {
return swift::mayBindDynamicSelf(getFunction());
}

bool BridgedFunction::isTrapNoReturn() const {
return swift::isTrapNoReturnFunction(getFunction());
Expand Down