Skip to content

Commit fe40707

Browse files
committed
Swift SIL: add Function.isPossiblyUsedExternally and Function.isAvailableExternally
1 parent 5015555 commit fe40707

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
7474
return nil
7575
}
7676

77+
/// True, if the linkage of the function indicates that it is visible outside the current
78+
/// compilation unit and therefore not all of its uses are known.
79+
///
80+
/// For example, `public` linkage.
81+
public var isPossiblyUsedExternally: Bool {
82+
return SILFunction_isPossiblyUsedExternally(bridged) != 0
83+
}
84+
85+
/// True, if the linkage of the function indicates that it has a definition outside the
86+
/// current compilation unit.
87+
///
88+
/// For example, `public_external` linkage.
89+
public var isAvailableExternally: Bool {
90+
return SILFunction_isAvailableExternally(bridged) != 0
91+
}
92+
7793
public func hasSemanticsAttribute(_ attr: StaticString) -> Bool {
7894
attr.withUTF8Buffer { (buffer: UnsafeBufferPointer<UInt8>) in
7995
SILFunction_hasSemanticsAttr(bridged, llvm.StringRef(buffer.baseAddress!, buffer.count)) != 0

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ SwiftInt SILFunction_getNumSILArguments(BridgedFunction function);
224224
BridgedType SILFunction_getSILArgumentType(BridgedFunction function, SwiftInt idx);
225225
BridgedType SILFunction_getSILResultType(BridgedFunction function);
226226
SwiftInt SILFunction_isSwift51RuntimeAvailable(BridgedFunction function);
227+
SwiftInt SILFunction_isPossiblyUsedExternally(BridgedFunction function);
228+
SwiftInt SILFunction_isAvailableExternally(BridgedFunction function);
227229
SwiftInt SILFunction_hasSemanticsAttr(BridgedFunction function,
228230
llvm::StringRef attrName);
229231

lib/SIL/Utils/SILBridging.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ SwiftInt SILFunction_isSwift51RuntimeAvailable(BridgedFunction function) {
217217
ctxt.getSwift51Availability());
218218
}
219219

220+
SwiftInt SILFunction_isPossiblyUsedExternally(BridgedFunction function) {
221+
return castToFunction(function)->isPossiblyUsedExternally() ? 1 : 0;
222+
}
223+
224+
SwiftInt SILFunction_isAvailableExternally(BridgedFunction function) {
225+
return castToFunction(function)->isAvailableExternally() ? 1 : 0;
226+
}
227+
220228
SwiftInt SILFunction_hasSemanticsAttr(BridgedFunction function,
221229
StringRef attrName) {
222230
SILFunction *f = castToFunction(function);

0 commit comments

Comments
 (0)