Skip to content

Commit 70b413d

Browse files
committed
RemoteInspection: Support for parameter packs
1 parent 024dbd0 commit 70b413d

File tree

9 files changed

+827
-15
lines changed

9 files changed

+827
-15
lines changed

include/swift/RemoteInspection/TypeRef.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,65 @@ class TupleTypeRef final : public TypeRef {
416416
}
417417
};
418418

419+
class PackTypeRef final : public TypeRef {
420+
protected:
421+
std::vector<const TypeRef *> Elements;
422+
423+
static TypeRefID Profile(const std::vector<const TypeRef *> &Elements) {
424+
TypeRefID ID;
425+
for (auto Element : Elements)
426+
ID.addPointer(Element);
427+
return ID;
428+
}
429+
430+
public:
431+
PackTypeRef(std::vector<const TypeRef *> Elements)
432+
: TypeRef(TypeRefKind::Pack), Elements(std::move(Elements)) {}
433+
434+
template <typename Allocator>
435+
static const PackTypeRef *create(Allocator &A,
436+
std::vector<const TypeRef *> Elements) {
437+
FIND_OR_CREATE_TYPEREF(A, PackTypeRef, Elements);
438+
}
439+
440+
const std::vector<const TypeRef *> &getElements() const { return Elements; };
441+
442+
static bool classof(const TypeRef *TR) {
443+
return TR->getKind() == TypeRefKind::Pack;
444+
}
445+
};
446+
447+
class PackExpansionTypeRef final : public TypeRef {
448+
protected:
449+
const TypeRef *Pattern;
450+
const TypeRef *Count;
451+
452+
static TypeRefID Profile(const TypeRef *Pattern, const TypeRef *Count) {
453+
TypeRefID ID;
454+
ID.addPointer(Pattern);
455+
ID.addPointer(Count);
456+
return ID;
457+
}
458+
459+
public:
460+
PackExpansionTypeRef( const TypeRef *Pattern, const TypeRef *Count)
461+
: TypeRef(TypeRefKind::PackExpansion), Pattern(Pattern), Count(Count) {}
462+
463+
template <typename Allocator>
464+
static const PackExpansionTypeRef *create(Allocator &A,
465+
const TypeRef *Pattern, const TypeRef *Count) {
466+
FIND_OR_CREATE_TYPEREF(A, PackExpansionTypeRef, Pattern, Count);
467+
}
468+
469+
const TypeRef *getPattern() const { return Pattern; }
470+
471+
const TypeRef *getCount() const { return Count; }
472+
473+
static bool classof(const TypeRef *TR) {
474+
return TR->getKind() == TypeRefKind::PackExpansion;
475+
}
476+
};
477+
419478
class OpaqueArchetypeTypeRef final : public TypeRef {
420479
std::string ID;
421480
std::string Description;

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,15 @@ class TypeRefBuilder {
414414

415415
std::vector<std::unique_ptr<const GenericSignatureRef>> SignatureRefPool;
416416

417+
/// This builder doesn't perform "on the fly" substitutions, so we preserve
418+
/// all pack expansions. We still need an active expansion stack though,
419+
/// for the dummy implementation of these methods:
420+
/// - beginPackExpansion()
421+
/// - advancePackExpansion()
422+
/// - createExpandedPackElement()
423+
/// - endPackExpansion()
424+
std::vector<const TypeRef *> ActivePackExpansions;
425+
417426
TypeConverter TC;
418427

419428
#define TYPEREF(Id, Parent) \
@@ -1133,8 +1142,7 @@ class TypeRefBuilder {
11331142
}
11341143

11351144
const TypeRef *createPackType(llvm::ArrayRef<const TypeRef *> elements) {
1136-
// FIXME: Remote mirrors support for variadic generics.
1137-
return nullptr;
1145+
return PackTypeRef::create(*this, elements);
11381146
}
11391147

11401148
const TypeRef *createSILPackType(llvm::ArrayRef<const TypeRef *> elements,
@@ -1144,21 +1152,22 @@ class TypeRefBuilder {
11441152
}
11451153

11461154
size_t beginPackExpansion(const TypeRef *countType) {
1147-
// FIXME: Remote mirrors support for variadic generics.
1148-
return 0;
1155+
ActivePackExpansions.push_back(countType);
1156+
return 1;
11491157
}
11501158

11511159
void advancePackExpansion(size_t index) {
1152-
// FIXME: Remote mirrors support for variadic generics.
1160+
assert(index == 0);
11531161
}
11541162

11551163
const TypeRef *createExpandedPackElement(const TypeRef *patternType) {
1156-
// FIXME: Remote mirrors support for variadic generics.
1157-
return nullptr;
1164+
assert(!ActivePackExpansions.empty());
1165+
auto countType = ActivePackExpansions.back();
1166+
return PackExpansionTypeRef::create(*this, patternType, countType);
11581167
}
11591168

11601169
void endPackExpansion() {
1161-
// FIXME: Remote mirrors support for variadic generics.
1170+
ActivePackExpansions.pop_back();
11621171
}
11631172

11641173
const FunctionTypeRef *createFunctionType(

include/swift/RemoteInspection/TypeRefs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ TYPEREF(SILBox, TypeRef)
3939
TYPEREF(SILBoxTypeWithLayout, TypeRef)
4040
TYPEREF(Integer, TypeRef)
4141
TYPEREF(BuiltinFixedArray, TypeRef)
42+
TYPEREF(Pack, TypeRef)
43+
TYPEREF(PackExpansion, TypeRef)
4244

4345
#undef TYPEREF

stdlib/public/RemoteInspection/TypeLowering.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,15 @@ class HasFixedSize
17441744
return true;
17451745
}
17461746

1747+
bool visitPackTypeRef(const PackTypeRef *P) {
1748+
return false;
1749+
}
1750+
1751+
bool visitPackExpansionTypeRef(const PackExpansionTypeRef *PE) {
1752+
DEBUG_LOG(fprintf(stderr, "Cannot have pack expansion type here: "); PE->dump());
1753+
return false;
1754+
}
1755+
17471756
bool visitFunctionTypeRef(const FunctionTypeRef *F) {
17481757
return true;
17491758
}
@@ -1879,6 +1888,20 @@ class HasSingletonMetatype
18791888
return result;
18801889
}
18811890

1891+
MetatypeRepresentation visitPackTypeRef(const PackTypeRef *P) {
1892+
auto result = MetatypeRepresentation::Thin;
1893+
for (auto Element : P->getElements())
1894+
result = combineRepresentations(result, visit(Element));
1895+
return result;
1896+
}
1897+
1898+
MetatypeRepresentation visitPackExpansionTypeRef(const PackExpansionTypeRef *PE) {
1899+
auto result = MetatypeRepresentation::Thin;
1900+
result = combineRepresentations(result, visit(PE->getPattern()));
1901+
result = combineRepresentations(result, visit(PE->getCount()));
1902+
return result;
1903+
}
1904+
18821905
MetatypeRepresentation visitFunctionTypeRef(const FunctionTypeRef *F) {
18831906
auto result = visit(F->getResult());
18841907
for (const auto &Param : F->getParameters())
@@ -2421,6 +2444,16 @@ class LowerType
24212444
return builder.build();
24222445
}
24232446

2447+
const TypeInfo *visitPackTypeRef(const PackTypeRef *P) {
2448+
DEBUG_LOG(fprintf(stderr, "Cannot have pack type here: "); P->dump());
2449+
return nullptr;
2450+
}
2451+
2452+
const TypeInfo *visitPackExpansionTypeRef(const PackExpansionTypeRef *PE) {
2453+
DEBUG_LOG(fprintf(stderr, "Cannot have pack expansion type here: "); PE->dump());
2454+
return nullptr;
2455+
}
2456+
24242457
const TypeInfo *visitFunctionTypeRef(const FunctionTypeRef *F) {
24252458
switch (F->getFlags().getConvention()) {
24262459
case FunctionMetadataConvention::Swift:

0 commit comments

Comments
 (0)