Skip to content

Commit 5885421

Browse files
committed
Bridge getSwiftMutableSpanDecl() and isBuiltinType()
1 parent cc72edb commit 5885421

File tree

8 files changed

+25
-0
lines changed

8 files changed

+25
-0
lines changed

SwiftCompilerSources/Sources/AST/Type.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ extension TypeProperties {
186186
public var hasLocalArchetype: Bool { rawType.bridged.hasLocalArchetype() }
187187
public var isEscapable: Bool { rawType.bridged.isEscapable() }
188188
public var isNoEscape: Bool { rawType.bridged.isNoEscape() }
189+
public var isBuiltinType: Bool { rawType.bridged.isBuiltinType() }
189190

190191
public var representationOfMetatype: AST.`Type`.MetatypeRepresentation {
191192
rawType.bridged.getRepresentationOfMetatype().representation

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ struct FunctionPassContext : MutatingContext {
324324
_bridged.getSwiftArrayDecl().getAs(NominalTypeDecl.self)
325325
}
326326

327+
var swiftMutableSpan: NominalTypeDecl {
328+
_bridged.getSwiftMutableSpanDecl().getAs(NominalTypeDecl.self)
329+
}
330+
327331
func loadFunction(name: StaticString, loadCalleesRecursively: Bool) -> Function? {
328332
return name.withUTF8Buffer { (nameBuffer: UnsafeBufferPointer<UInt8>) in
329333
let nameStr = BridgedStringRef(data: nameBuffer.baseAddress, count: nameBuffer.count)

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,6 +3100,7 @@ struct BridgedASTType {
31003100
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getBuiltinVectorElementType() const;
31013101
BRIDGED_INLINE bool isBuiltinFixedWidthInteger(SwiftInt width) const;
31023102
BRIDGED_INLINE bool isOptional() const;
3103+
BRIDGED_INLINE bool isBuiltinType() const;
31033104
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getNominalOrBoundGenericNominal() const;
31043105
BRIDGED_INLINE TraitResult canBeClass() const;
31053106
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getAnyNominal() const;

include/swift/AST/ASTBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,10 @@ bool BridgedASTType::isUnownedStorageType() const {
531531
return unbridged()->is<swift::UnownedStorageType>();
532532
}
533533

534+
bool BridgedASTType::isBuiltinType() const {
535+
return unbridged()->isBuiltinType();
536+
}
537+
534538
OptionalBridgedDeclObj BridgedASTType::getNominalOrBoundGenericNominal() const {
535539
return {unbridged()->getNominalOrBoundGenericNominal()};
536540
}

include/swift/AST/KnownStdlibTypes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,6 @@ KNOWN_STDLIB_TYPE_DECL(InlineArray, NominalTypeDecl, 2)
103103

104104
KNOWN_STDLIB_TYPE_DECL(SwiftSetting, NominalTypeDecl, 0)
105105

106+
KNOWN_STDLIB_TYPE_DECL(MutableSpan, NominalTypeDecl, 1)
107+
106108
#undef KNOWN_STDLIB_TYPE_DECL

include/swift/AST/Types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
10541054
bool is##NAME();
10551055
#include "swift/AST/KnownStdlibTypes.def"
10561056

1057+
/// Check if this type is from the Builtin module.
1058+
bool isBuiltinType();
1059+
10571060
/// Check if this type is equal to Builtin.IntN.
10581061
bool isBuiltinIntegerType(unsigned bitWidth);
10591062

@@ -8143,6 +8146,10 @@ inline GenericTypeDecl *TypeBase::getAnyGeneric() {
81438146
return getCanonicalType().getAnyGeneric();
81448147
}
81458148

8149+
inline bool TypeBase::isBuiltinType() {
8150+
return isa<BuiltinType>(getCanonicalType());
8151+
}
8152+
81468153
inline bool TypeBase::isBuiltinIntegerType(unsigned n) {
81478154
if (auto intTy = dyn_cast<BuiltinIntegerType>(getCanonicalType()))
81488155
return intTy->getWidth().isFixedWidth()

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ struct BridgedPassContext {
215215
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDomTree getDomTree() const;
216216
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedPostDomTree getPostDomTree() const;
217217
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj getSwiftArrayDecl() const;
218+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj getSwiftMutableSpanDecl() const;
218219

219220
// AST
220221

include/swift/SILOptimizer/OptimizerBridgingImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ BridgedDeclObj BridgedPassContext::getSwiftArrayDecl() const {
215215
return {mod->getASTContext().getArrayDecl()};
216216
}
217217

218+
BridgedDeclObj BridgedPassContext::getSwiftMutableSpanDecl() const {
219+
swift::SILModule *mod = invocation->getPassManager()->getModule();
220+
return {mod->getASTContext().getMutableSpanDecl()};
221+
}
222+
218223
// AST
219224

220225
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE

0 commit comments

Comments
 (0)