mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Swift SIL: add APIs for box types
This commit is contained in:
@@ -59,6 +59,8 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
|
||||
return bridged.isReferenceCounted(function.bridged)
|
||||
}
|
||||
|
||||
public var isBox: Bool { bridged.isBox() }
|
||||
|
||||
public var isMoveOnly: Bool { bridged.isMoveOnly() }
|
||||
|
||||
/// Return true if this type conforms to Escapable.
|
||||
@@ -125,6 +127,11 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
|
||||
return TupleElementArray(type: self)
|
||||
}
|
||||
|
||||
public func getBoxFields(in function: Function) -> BoxFieldsArray {
|
||||
precondition(isBox)
|
||||
return BoxFieldsArray(type: self, function: function)
|
||||
}
|
||||
|
||||
/// Returns nil if the nominal is a resilient type because in this case the complete list
|
||||
/// of fields is not known.
|
||||
public func getNominalFields(in function: Function) -> NominalFieldsArray? {
|
||||
@@ -267,6 +274,18 @@ public struct TupleElementArray : RandomAccessCollection, FormattedLikeArray {
|
||||
}
|
||||
}
|
||||
|
||||
public struct BoxFieldsArray : RandomAccessCollection, FormattedLikeArray {
|
||||
fileprivate let type: Type
|
||||
fileprivate let function: Function
|
||||
|
||||
public var startIndex: Int { return 0 }
|
||||
public var endIndex: Int { Int(type.bridged.getNumBoxFields()) }
|
||||
|
||||
public subscript(_ index: Int) -> Type {
|
||||
type.bridged.getBoxFieldType(index, function.bridged).type
|
||||
}
|
||||
}
|
||||
|
||||
extension Type: DiagnosticArgument {
|
||||
public func _withBridgedDiagnosticArgument(_ fn: (BridgedDiagnosticArgument) -> Void) {
|
||||
rawType._withBridgedDiagnosticArgument(fn)
|
||||
|
||||
@@ -252,6 +252,7 @@ struct BridgedType {
|
||||
BRIDGED_INLINE bool isNonTrivialOrContainsRawPointer(BridgedFunction f) const;
|
||||
BRIDGED_INLINE bool isLoadable(BridgedFunction f) const;
|
||||
BRIDGED_INLINE bool isReferenceCounted(BridgedFunction f) const;
|
||||
BRIDGED_INLINE bool isBox() const;
|
||||
BRIDGED_INLINE bool containsNoEscapeFunction() const;
|
||||
BRIDGED_INLINE bool isEmpty(BridgedFunction f) const;
|
||||
BRIDGED_INLINE bool isMoveOnly() const;
|
||||
@@ -260,6 +261,8 @@ struct BridgedType {
|
||||
BRIDGED_INLINE bool isMarkedAsImmortal() const;
|
||||
BRIDGED_INLINE bool isAddressableForDeps(BridgedFunction f) const;
|
||||
BRIDGED_INLINE SwiftInt getCaseIdxOfEnumType(BridgedStringRef name) const;
|
||||
BRIDGED_INLINE SwiftInt getNumBoxFields() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getBoxFieldType(SwiftInt idx, BridgedFunction f) const;
|
||||
BRIDGED_INLINE SwiftInt getNumNominalFields() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getFieldType(SwiftInt idx, BridgedFunction f) const;
|
||||
BRIDGED_INLINE SwiftInt getFieldIdxOfNominalType(BridgedStringRef name) const;
|
||||
|
||||
@@ -347,6 +347,10 @@ bool BridgedType::isReferenceCounted(BridgedFunction f) const {
|
||||
return unbridged().isReferenceCounted(f.getFunction());
|
||||
}
|
||||
|
||||
bool BridgedType::isBox() const {
|
||||
return unbridged().is<swift::SILBoxType>();
|
||||
}
|
||||
|
||||
bool BridgedType::containsNoEscapeFunction() const {
|
||||
return unbridged().containsNoEscapeFunction();
|
||||
}
|
||||
@@ -379,6 +383,16 @@ SwiftInt BridgedType::getCaseIdxOfEnumType(BridgedStringRef name) const {
|
||||
return unbridged().getCaseIdxOfEnumType(name.unbridged());
|
||||
}
|
||||
|
||||
SwiftInt BridgedType::getNumBoxFields() const {
|
||||
return unbridged().castTo<swift::SILBoxType>()->getLayout()->getFields().size();
|
||||
}
|
||||
|
||||
BridgedType BridgedType::getBoxFieldType(SwiftInt idx, BridgedFunction f) const {
|
||||
auto *fn = f.getFunction();
|
||||
return swift::getSILBoxFieldType(fn->getTypeExpansionContext(), unbridged().castTo<swift::SILBoxType>(),
|
||||
fn->getModule().Types, idx);
|
||||
}
|
||||
|
||||
SwiftInt BridgedType::getNumNominalFields() const {
|
||||
return unbridged().getNumNominalFields();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user