Skip to content

Commit c4aa820

Browse files
committed
ASTDemangler: Support PackType, SILPackType, and PackExpansionType
Also stub out the corresponding entry points in the runtime's MetadataBuilder and the Remote Mirrors TypeRefBuilder.
1 parent 795e64e commit c4aa820

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ class ASTBuilder {
111111

112112
Type createTupleType(ArrayRef<Type> eltTypes, StringRef labels);
113113

114+
Type createPackType(ArrayRef<Type> eltTypes);
115+
116+
Type createSILPackType(ArrayRef<Type> eltTypes, bool isElementAddress);
117+
118+
Type createPackExpansionType(Type patternType, Type countType);
119+
114120
Type createFunctionType(
115121
ArrayRef<Demangle::FunctionParam<Type>> params,
116122
Type output, FunctionTypeFlags flags,

include/swift/Demangling/TypeDecoder.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,46 @@ class TypeDecoder {
10721072
return decodeMangledType(Node->getChild(0), depth + 1,
10731073
/*forRequirement=*/false);
10741074

1075+
case NodeKind::Pack:
1076+
case NodeKind::SILPackDirect:
1077+
case NodeKind::SILPackIndirect: {
1078+
llvm::SmallVector<BuiltType, 8> elements;
1079+
1080+
for (auto &element : *Node) {
1081+
// Decode the element type.
1082+
auto elementType =
1083+
decodeMangledType(element, depth + 1, /*forRequirement=*/false);
1084+
if (elementType.isError())
1085+
return elementType;
1086+
1087+
elements.push_back(elementType.getType());
1088+
}
1089+
1090+
switch (Node->getKind()) {
1091+
case NodeKind::Pack:
1092+
return Builder.createPackType(elements);
1093+
case NodeKind::SILPackDirect:
1094+
return Builder.createSILPackType(elements, /*isElementAddress=*/false);
1095+
case NodeKind::SILPackIndirect:
1096+
return Builder.createSILPackType(elements, /*isElementAddress=*/true);
1097+
default:
1098+
llvm_unreachable("Bad kind");
1099+
}
1100+
}
1101+
1102+
case NodeKind::PackExpansion: {
1103+
if (Node->getNumChildren() < 2)
1104+
return MAKE_NODE_TYPE_ERROR(Node,
1105+
"fewer children (%zu) than required (2)",
1106+
Node->getNumChildren());
1107+
1108+
auto patternType = decodeMangledType(Node->getChild(0), depth + 1);
1109+
auto countType = decodeMangledType(Node->getChild(1), depth + 1);
1110+
1111+
return Builder.createPackExpansionType(patternType.getType(),
1112+
countType.getType());
1113+
}
1114+
10751115
case NodeKind::DependentGenericType: {
10761116
if (Node->getNumChildren() < 2)
10771117
return MAKE_NODE_TYPE_ERROR(Node,

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,23 @@ class TypeRefBuilder {
689689
return TupleTypeRef::create(*this, elements, std::move(labels));
690690
}
691691

692+
const TypeRef *createPackType(llvm::ArrayRef<const TypeRef *> elements) {
693+
// FIXME: Remote mirrors support for variadic generics.
694+
return nullptr;
695+
}
696+
697+
const TypeRef *createSILPackType(llvm::ArrayRef<const TypeRef *> elements,
698+
bool isElementAddress) {
699+
// FIXME: Remote mirrors support for variadic generics.
700+
return nullptr;
701+
}
702+
703+
const TypeRef *createPackExpansionType(const TypeRef *patternType,
704+
const TypeRef *countType) {
705+
// FIXME: Remote mirrors support for variadic generics.
706+
return nullptr;
707+
}
708+
692709
const FunctionTypeRef *createFunctionType(
693710
llvm::ArrayRef<remote::FunctionParam<const TypeRef *>> params,
694711
const TypeRef *result, FunctionTypeFlags flags,

lib/AST/ASTDemangler.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,25 @@ Type ASTBuilder::createTupleType(ArrayRef<Type> eltTypes, StringRef labels) {
344344
return TupleType::get(elements, Ctx);
345345
}
346346

347+
Type ASTBuilder::createPackType(ArrayRef<Type> eltTypes) {
348+
return PackType::get(Ctx, eltTypes);
349+
}
350+
351+
Type ASTBuilder::createSILPackType(ArrayRef<Type> eltTypes,
352+
bool isElementAddress) {
353+
auto extInfo = SILPackType::ExtInfo(isElementAddress);
354+
355+
SmallVector<CanType, 4> elements;
356+
for (auto eltType : eltTypes)
357+
elements.push_back(eltType->getCanonicalType());
358+
359+
return SILPackType::get(Ctx, extInfo, elements);
360+
}
361+
362+
Type ASTBuilder::createPackExpansionType(Type patternType, Type countType) {
363+
return PackExpansionType::get(patternType, countType);
364+
}
365+
347366
Type ASTBuilder::createFunctionType(
348367
ArrayRef<Demangle::FunctionParam<Type>> params,
349368
Type output, FunctionTypeFlags flags,

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,24 @@ class DecodedMetadataBuilder {
17611761
.Value;
17621762
}
17631763

1764+
TypeLookupErrorOr<BuiltType>
1765+
createPackType(llvm::ArrayRef<BuiltType> elements) const {
1766+
// FIXME: Runtime support for variadic generics.
1767+
return BuiltType();
1768+
}
1769+
1770+
TypeLookupErrorOr<BuiltType>
1771+
createSILPackType(llvm::ArrayRef<BuiltType> elements, bool isElementAddress) const {
1772+
// FIXME: Runtime support for variadic generics.
1773+
return BuiltType();
1774+
}
1775+
1776+
TypeLookupErrorOr<BuiltType>
1777+
createPackExpansionType(BuiltType patternType, BuiltType countType) const {
1778+
// FIXME: Runtime support for variadic generics.
1779+
return BuiltType();
1780+
}
1781+
17641782
TypeLookupErrorOr<BuiltType> createDependentMemberType(StringRef name,
17651783
BuiltType base) const {
17661784
// Should not have unresolved dependent member types here.

0 commit comments

Comments
 (0)