Skip to content

Commit b3f70c9

Browse files
committed
Implement Pack Locators
1 parent d4b8f1d commit b3f70c9

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,32 @@ class LocatorPathElt::NamedTupleElement final
641641
}
642642
};
643643

644+
class LocatorPathElt::PackType : public StoredPointerElement<TypeBase> {
645+
public:
646+
PackType(Type type)
647+
: StoredPointerElement(PathElementKind::PackType, type.getPointer()) {
648+
assert(type->getDesugaredType()->is<swift::PackType>());
649+
}
650+
651+
Type getType() const { return getStoredPointer(); }
652+
653+
static bool classof(const LocatorPathElt *elt) {
654+
return elt->getKind() == PathElementKind::PackType;
655+
}
656+
};
657+
658+
class LocatorPathElt::PackElement final : public StoredIntegerElement<1> {
659+
public:
660+
PackElement(unsigned index)
661+
: StoredIntegerElement(ConstraintLocator::PackElement, index) {}
662+
663+
unsigned getIndex() const { return getValue<0>(); }
664+
665+
static bool classof(const LocatorPathElt *elt) {
666+
return elt->getKind() == ConstraintLocator::PackElement;
667+
}
668+
};
669+
644670
class LocatorPathElt::KeyPathComponent final : public StoredIntegerElement<1> {
645671
public:
646672
KeyPathComponent(unsigned index)
@@ -758,6 +784,10 @@ class LocatorPathElt::GenericParameter final : public StoredPointerElement<Gener
758784
GenericTypeParamType *getType() const {
759785
return getStoredPointer();
760786
}
787+
788+
bool isTypeSequence() const {
789+
return getType()->isTypeSequence();
790+
}
761791

762792
static bool classof(const LocatorPathElt *elt) {
763793
return elt->getKind() == PathElementKind::GenericParameter;

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ ABSTRACT_LOCATOR_PATH_ELT(AnyTupleElement)
183183
/// A tuple element referenced by name.
184184
CUSTOM_LOCATOR_PATH_ELT(NamedTupleElement)
185185

186+
/// Pack types <T, U, V, ...>
187+
CUSTOM_LOCATOR_PATH_ELT(PackType)
188+
189+
/// An element of a pack type - the T in <T, U, V, ...>
190+
CUSTOM_LOCATOR_PATH_ELT(PackElement)
191+
186192
/// An unresolved member.
187193
SIMPLE_LOCATOR_PATH_ELT(UnresolvedMember)
188194

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4071,6 +4071,8 @@ class ConstraintSystem {
40714071
/// parameter types and dependent member types with fresh type variables.
40724072
///
40734073
/// \param type The type to open.
4074+
/// \param replacements The mapping from generic type parameters to their
4075+
/// corresponding opened type variables.
40744076
///
40754077
/// \returns The opened type, or \c type if there are no archetypes in it.
40764078
Type openType(Type type, OpenedTypeMap &replacements);
@@ -4484,6 +4486,11 @@ class ConstraintSystem {
44844486
SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
44854487
ConstraintLocatorBuilder locator);
44864488

4489+
TypeMatchResult
4490+
matchPackTypes(PackType *pack1, PackType *pack2,
4491+
ConstraintKind kind, TypeMatchOptions flags,
4492+
ConstraintLocatorBuilder locator);
4493+
44874494
/// Subroutine of \c matchTypes(), which matches up two tuple types.
44884495
///
44894496
/// \returns the result of performing the tuple-to-tuple conversion.

lib/Sema/ConstraintLocator.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
9494
case ConstraintLocator::ImplicitConversion:
9595
case ConstraintLocator::ImplicitDynamicMemberSubscript:
9696
case ConstraintLocator::ClosureBodyElement:
97+
case ConstraintLocator::PackType:
98+
case ConstraintLocator::PackElement:
9799
return 0;
98100

99101
case ConstraintLocator::FunctionArgument:
@@ -561,11 +563,22 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
561563
out << "implicit dynamic member subscript";
562564
break;
563565

564-
case ConstraintLocator::ImplicitConversion:
566+
case ConstraintLocator::ImplicitConversion: {
565567
auto convElt = elt.castTo<LocatorPathElt::ImplicitConversion>();
566568
out << "implicit conversion " << getName(convElt.getConversionKind());
567569
break;
568570
}
571+
572+
case ConstraintLocator::PackType:
573+
out << "pack type";
574+
break;
575+
576+
case PackElement: {
577+
auto packElt = elt.castTo<LocatorPathElt::PackElement>();
578+
out << "pack element #" << llvm::utostr(packElt.getIndex());
579+
break;
580+
}
581+
}
569582
}
570583
out << ']';
571584
}

0 commit comments

Comments
 (0)