Skip to content

Commit ff2341e

Browse files
committed
Swift AST/SIL: add Type APIs for Builtin.FixedArray
* `Type.isBuiltinFixedArray` * `Type.builtinFixedArrayElementType`
1 parent 8ab726c commit ff2341e

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public struct Type: TypeProperties, CustomStringConvertible, NoReflectionChildre
6161

6262
public var builtinVectorElementType: Type { Type(bridged: bridged.getBuiltinVectorElementType()) }
6363

64+
public var builtinFixedArrayElementType: Type { Type(bridged: bridged.getBuiltinFixedArrayElementType()) }
65+
6466
public func subst(with substitutionMap: SubstitutionMap) -> Type {
6567
return Type(bridged: bridged.subst(substitutionMap.bridged))
6668
}
@@ -81,6 +83,8 @@ public struct CanonicalType: TypeProperties, CustomStringConvertible, NoReflecti
8183

8284
public var builtinVectorElementType: CanonicalType { rawType.builtinVectorElementType.canonical }
8385

86+
public var builtinFixedArrayElementType: CanonicalType { rawType.builtinFixedArrayElementType.canonical }
87+
8488
public func subst(with substitutionMap: SubstitutionMap) -> CanonicalType {
8589
return rawType.subst(with: substitutionMap).canonical
8690
}
@@ -106,6 +110,7 @@ extension TypeProperties {
106110

107111
public var isBuiltinFloat: Bool { rawType.bridged.isBuiltinFloat() }
108112
public var isBuiltinVector: Bool { rawType.bridged.isBuiltinVector() }
113+
public var isBuiltinFixedArray: Bool { rawType.bridged.isBuiltinFixedArray() }
109114

110115
public var isClass: Bool {
111116
if let nominal = nominal, nominal is ClassDecl {

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
8282

8383
public var builtinVectorElementType: Type { canonicalType.builtinVectorElementType.silType! }
8484

85+
public func builtinFixedArrayElementType(in function: Function, maximallyAbstracted: Bool = false) -> Type {
86+
canonicalType.builtinFixedArrayElementType.loweredType(in: function, maximallyAbstracted: maximallyAbstracted)
87+
}
88+
8589
public var superClassType: Type? { canonicalType.superClassType?.silType }
8690

8791
public func isExactSuperclass(of type: Type) -> Bool {

include/swift/AST/ASTBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,7 +3102,9 @@ struct BridgedASTType {
31023102
BRIDGED_INLINE bool isBuiltinInteger() const;
31033103
BRIDGED_INLINE bool isBuiltinFloat() const;
31043104
BRIDGED_INLINE bool isBuiltinVector() const;
3105+
BRIDGED_INLINE bool isBuiltinFixedArray() const;
31053106
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getBuiltinVectorElementType() const;
3107+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getBuiltinFixedArrayElementType() const;
31063108
BRIDGED_INLINE bool isBuiltinFixedWidthInteger(SwiftInt width) const;
31073109
BRIDGED_INLINE bool isOptional() const;
31083110
BRIDGED_INLINE bool isBuiltinType() const;

include/swift/AST/ASTBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,18 @@ bool BridgedASTType::isBuiltinVector() const {
542542
return unbridged()->is<swift::BuiltinVectorType>();
543543
}
544544

545+
bool BridgedASTType::isBuiltinFixedArray() const {
546+
return unbridged()->is<swift::BuiltinFixedArrayType>();
547+
}
548+
545549
BridgedASTType BridgedASTType::getBuiltinVectorElementType() const {
546550
return {unbridged()->castTo<swift::BuiltinVectorType>()->getElementType().getPointer()};
547551
}
548552

553+
BridgedASTType BridgedASTType::getBuiltinFixedArrayElementType() const {
554+
return {unbridged()->castTo<swift::BuiltinFixedArrayType>()->getElementType().getPointer()};
555+
}
556+
549557
bool BridgedASTType::isBuiltinFixedWidthInteger(SwiftInt width) const {
550558
if (auto *intTy = unbridged()->getAs<swift::BuiltinIntegerType>())
551559
return intTy->isFixedWidth((unsigned)width);

0 commit comments

Comments
 (0)