Skip to content

Commit 55210f6

Browse files
committed
Sema: Introduce TVO_CanBindToPack type variable flag
1 parent da8ae1d commit 55210f6

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

include/swift/AST/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
384384
NumProtocols : 16
385385
);
386386

387-
SWIFT_INLINE_BITFIELD_FULL(TypeVariableType, TypeBase, 5+32,
387+
SWIFT_INLINE_BITFIELD_FULL(TypeVariableType, TypeBase, 6+32,
388388
/// Type variable options.
389-
Options : 5,
389+
Options : 6,
390390
: NumPadBits,
391391
/// The unique number assigned to this type variable.
392392
ID : 32

include/swift/Sema/ConstraintSystem.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ enum TypeVariableOptions {
330330
/// Whether a more specific deduction for this type variable implies a
331331
/// better solution to the constraint system.
332332
TVO_PrefersSubtypeBinding = 0x10,
333+
334+
/// Whether the type variable can be bound to a pack type or not.
335+
TVO_CanBindToPack = 0x20,
333336
};
334337

335338
/// The implementation object for a type variable used within the
@@ -387,18 +390,21 @@ class TypeVariableType::Implementation {
387390
&& "Truncation");
388391
}
389392

390-
/// Whether this type variable can bind to an lvalue type.
393+
/// Whether this type variable can bind to an LValueType.
391394
bool canBindToLValue() const { return getRawOptions() & TVO_CanBindToLValue; }
392395

393-
/// Whether this type variable can bind to an inout type.
396+
/// Whether this type variable can bind to an InOutType.
394397
bool canBindToInOut() const { return getRawOptions() & TVO_CanBindToInOut; }
395398

396-
/// Whether this type variable can bind to an inout type.
399+
/// Whether this type variable can bind to a noescape FunctionType.
397400
bool canBindToNoEscape() const { return getRawOptions() & TVO_CanBindToNoEscape; }
398401

399-
/// Whether this type variable can bind to a hole.
402+
/// Whether this type variable can bind to a PlaceholderType.
400403
bool canBindToHole() const { return getRawOptions() & TVO_CanBindToHole; }
401404

405+
/// Whether this type variable can bind to a PackType.
406+
bool canBindToPack() const { return getRawOptions() & TVO_CanBindToPack; }
407+
402408
/// Whether this type variable prefers a subtype binding over a supertype
403409
/// binding.
404410
bool prefersSubtypeBinding() const {
@@ -638,6 +644,7 @@ class TypeVariableType::Implementation {
638644
ENTRY(TVO_CanBindToNoEscape, "noescape");
639645
ENTRY(TVO_CanBindToHole, "hole");
640646
ENTRY(TVO_PrefersSubtypeBinding, "");
647+
ENTRY(TVO_CanBindToPack, "pack");
641648
}
642649
#undef ENTRY
643650
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,12 @@ TypeVariableType *ConstraintSystem::openGenericParameter(
17351735
auto *paramLocator = getConstraintLocator(
17361736
locator.withPathElement(LocatorPathElt::GenericParameter(parameter)));
17371737

1738-
auto typeVar = createTypeVariable(paramLocator, TVO_PrefersSubtypeBinding |
1739-
TVO_CanBindToHole);
1738+
unsigned options = (TVO_PrefersSubtypeBinding |
1739+
TVO_CanBindToHole);
1740+
if (parameter->isParameterPack())
1741+
options |= TVO_CanBindToPack;
1742+
1743+
auto typeVar = createTypeVariable(paramLocator, options);
17401744
auto result = replacements.insert(std::make_pair(
17411745
cast<GenericTypeParamType>(parameter->getCanonicalType()), typeVar));
17421746

0 commit comments

Comments
 (0)