Skip to content

Commit 7cecf57

Browse files
committed
Add SILType::isAddressableForDeps
1 parent afb0de5 commit 7cecf57

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
9292

9393
public var isMarkedAsImmortal: Bool { bridged.isMarkedAsImmortal() }
9494

95+
/// True if a value of this type can have its address taken by a lifetime-dependent value.
96+
public func isAddressableForDeps(in function: Function) -> Bool {
97+
bridged.isAddressableForDeps(function.bridged)
98+
}
99+
95100
//===--------------------------------------------------------------------===//
96101
// Properties of lowered `SILFunctionType`s
97102
//===--------------------------------------------------------------------===//

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ struct BridgedType {
261261
BRIDGED_INLINE bool isExactSuperclassOf(BridgedType t) const;
262262
BRIDGED_INLINE bool isCalleeConsumedFunction() const;
263263
BRIDGED_INLINE bool isMarkedAsImmortal() const;
264+
BRIDGED_INLINE bool isAddressableForDeps(BridgedFunction f) const;
264265
BRIDGED_INLINE SwiftInt getCaseIdxOfEnumType(BridgedStringRef name) const;
265266
BRIDGED_INLINE SwiftInt getNumNominalFields() const;
266267
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getFieldType(SwiftInt idx, BridgedFunction f) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ bool BridgedType::isMarkedAsImmortal() const {
392392
return unbridged().isMarkedAsImmortal();
393393
}
394394

395+
bool BridgedType::isAddressableForDeps(BridgedFunction f) const {
396+
return unbridged().isAddressableForDeps();
397+
}
398+
395399
SwiftInt BridgedType::getCaseIdxOfEnumType(BridgedStringRef name) const {
396400
return unbridged().getCaseIdxOfEnumType(name.unbridged());
397401
}

include/swift/SIL/SILType.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,10 @@ class SILType {
927927

928928
bool isMarkedAsImmortal() const;
929929

930+
/// True if a value of this type can have its address taken by a
931+
/// lifetime-dependent value.
932+
bool isAddressableForDeps(const SILFunction &function) const;
933+
930934
/// Returns true if this type is an actor type. Returns false if this is any
931935
/// other type. This includes distributed actors. To check for distributed
932936
/// actors and actors, use isAnyActor().

lib/SIL/IR/SILType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,13 @@ bool SILType::isMarkedAsImmortal() const {
11481148
return false;
11491149
}
11501150

1151+
bool SILType::isAddressableForDeps(const SILFunction &function) const {
1152+
auto contextType =
1153+
hasTypeParameter() ? function.mapTypeIntoContext(*this) : *this;
1154+
auto &tl = function.getTypeLowering(contextType);
1155+
return tl.getRecursiveProperties().isAddressableForDependencies();
1156+
}
1157+
11511158
intptr_t SILType::getFieldIdxOfNominalType(StringRef fieldName) const {
11521159
auto *nominal = getNominalOrBoundGenericNominal();
11531160
if (!nominal)

0 commit comments

Comments
 (0)