Skip to content

Commit ab10dc2

Browse files
committed
SIL: add Context.getTupleType
1 parent dca75c4 commit ab10dc2

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

SwiftCompilerSources/Sources/SIL/Context.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ extension Context {
4848

4949
public func getBuiltinIntegerType(bitWidth: Int) -> Type { _bridged.getBuiltinIntegerType(bitWidth).type }
5050

51+
public func getTupleType(elements: [Type]) -> AST.`Type` {
52+
let bridgedElements = elements.map { $0.bridged }
53+
return bridgedElements.withBridgedArrayRef {
54+
AST.`Type`(bridged: _bridged.getTupleType($0))
55+
}
56+
}
57+
5158
public var swiftArrayDecl: NominalTypeDecl {
5259
_bridged.getSwiftArrayDecl().getAs(NominalTypeDecl.self)
5360
}

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,7 @@ struct BridgedContext {
14251425
SWIFT_IMPORT_UNSAFE OptionalBridgedFunction lookUpNominalDeinitFunction(BridgedDeclObj nominal) const;
14261426
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap getContextSubstitutionMap(BridgedType type) const;
14271427
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getBuiltinIntegerType(SwiftInt bitWidth) const;
1428+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType getTupleType(BridgedArrayRef elementTypes) const;
14281429
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj getSwiftArrayDecl() const;
14291430
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj getSwiftMutableSpanDecl() const;
14301431
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedValue getSILUndef(BridgedType type) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,14 @@ BridgedType BridgedContext::getBuiltinIntegerType(SwiftInt bitWidth) const {
28472847
return swift::SILType::getBuiltinIntegerType(bitWidth, context->getModule()->getASTContext());
28482848
}
28492849

2850+
BridgedASTType BridgedContext::getTupleType(BridgedArrayRef elementTypes) const {
2851+
llvm::SmallVector<swift::TupleTypeElt, 8> elements;
2852+
for (auto bridgedElmtTy : elementTypes.unbridged<BridgedASTType>()) {
2853+
elements.push_back(bridgedElmtTy.unbridged());
2854+
}
2855+
return {swift::TupleType::get(elements, context->getModule()->getASTContext())};
2856+
}
2857+
28502858
BridgedDeclObj BridgedContext::getSwiftArrayDecl() const {
28512859
return {context->getModule()->getASTContext().getArrayDecl()};
28522860
}

0 commit comments

Comments
 (0)