Skip to content

Commit 60c579c

Browse files
Merge pull request #67415 from sophiapoirier/remove-TupleType-isSingleUnlabeledPackExpansion
[ConstraintSystem] remove TupleType::isSingleUnlabeledPackExpansion in favor of constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple
2 parents 530af74 + 8173c72 commit 60c579c

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,10 +2494,6 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
24942494

24952495
bool containsPackExpansionType() const;
24962496

2497-
/// Check whether this tuple consists of a single unlabeled element
2498-
/// of \c PackExpansionType.
2499-
bool isSingleUnlabeledPackExpansion() const;
2500-
25012497
private:
25022498
TupleType(ArrayRef<TupleTypeElt> elements, const ASTContext *CanCtx,
25032499
RecursiveTypeProperties properties)

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6268,6 +6268,9 @@ Type isPlaceholderVar(PatternBindingDecl *PB);
62686268
/// Dump an anchor node for a constraint locator or contextual type.
62696269
void dumpAnchor(ASTNode anchor, SourceManager *SM, raw_ostream &out);
62706270

6271+
/// Check whether the type is a tuple consisting of a single unlabeled element
6272+
/// of \c PackExpansionType or a type variable that represents a pack expansion
6273+
/// type.
62716274
bool isSingleUnlabeledPackExpansionTuple(Type type);
62726275

62736276
/// \returns null if \c type is not a single unlabeled pack expansion tuple.

lib/AST/ParameterPack.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,6 @@ bool CanTupleType::containsPackExpansionTypeImpl(CanTupleType tuple) {
276276
return false;
277277
}
278278

279-
bool TupleType::isSingleUnlabeledPackExpansion() const {
280-
if (getNumElements() != 1)
281-
return false;
282-
283-
const auto &elt = getElement(0);
284-
return !elt.hasName() && elt.getType()->is<PackExpansionType>();
285-
}
286-
287279
bool AnyFunctionType::containsPackExpansionType(ArrayRef<Param> params) {
288280
for (auto param : params) {
289281
auto paramTy = param.getPlainType();

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3858,10 +3858,9 @@ namespace {
38583858
if (auto *packRefExpr = expr->getPackRefExpr()) {
38593859
packRefExpr = cs.coerceToRValue(packRefExpr);
38603860
auto packRefType = cs.getType(packRefExpr);
3861-
if (auto *tuple = packRefType->getRValueType()->getAs<TupleType>();
3862-
tuple && tuple->isSingleUnlabeledPackExpansion()) {
3863-
auto patternType =
3864-
getPatternTypeOfSingleUnlabeledPackExpansionTuple(tuple);
3861+
if (auto patternType =
3862+
getPatternTypeOfSingleUnlabeledPackExpansionTuple(
3863+
packRefType)) {
38653864
auto *materializedPackExpr = MaterializePackExpr::create(
38663865
cs.getASTContext(), packRefExpr, packRefExpr->getLoc(),
38673866
patternType, /*implicit*/ true);

lib/Sema/CSSimplify.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,21 @@ bool constraints::isSingleUnlabeledPackExpansionTuple(Type type) {
135135
}
136136

137137
Type constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple(Type type) {
138-
if (!isSingleUnlabeledPackExpansionTuple(type)) {
139-
return {};
138+
if (isSingleUnlabeledPackExpansionTuple(type)) {
139+
auto tuple = type->getRValueType()->castTo<TupleType>();
140+
const auto &tupleElement = tuple->getElementType(0);
141+
if (auto *expansion = tupleElement->getAs<PackExpansionType>()) {
142+
return expansion->getPatternType();
143+
}
144+
if (auto *typeVar = tupleElement->getAs<TypeVariableType>()) {
145+
auto *locator = typeVar->getImpl().getLocator();
146+
if (auto expansionElement =
147+
locator->getLastElementAs<LocatorPathElt::PackExpansionType>()) {
148+
return expansionElement->getOpenedType()->getPatternType();
149+
}
150+
}
140151
}
141-
auto tuple = type->getRValueType()->castTo<TupleType>();
142-
auto *expansion = tuple->getElementType(0)->castTo<PackExpansionType>();
143-
return expansion->getPatternType();
152+
return {};
144153
}
145154

146155
static bool containsPackExpansionType(ArrayRef<AnyFunctionType::Param> params) {

lib/Sema/TypeCheckStmt.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#include "TypeChecker.h"
17+
#include "MiscDiagnostics.h"
1818
#include "TypeCheckAvailability.h"
1919
#include "TypeCheckConcurrency.h"
2020
#include "TypeCheckDistributed.h"
2121
#include "TypeCheckType.h"
22-
#include "MiscDiagnostics.h"
23-
#include "swift/Subsystems.h"
22+
#include "TypeChecker.h"
2423
#include "swift/AST/ASTPrinter.h"
2524
#include "swift/AST/ASTScope.h"
26-
#include "swift/AST/ASTWalker.h"
2725
#include "swift/AST/ASTVisitor.h"
28-
#include "swift/AST/DiagnosticsSema.h"
26+
#include "swift/AST/ASTWalker.h"
2927
#include "swift/AST/DiagnosticSuppression.h"
28+
#include "swift/AST/DiagnosticsSema.h"
3029
#include "swift/AST/Identifier.h"
3130
#include "swift/AST/Initializer.h"
3231
#include "swift/AST/NameLookup.h"
@@ -41,7 +40,9 @@
4140
#include "swift/Basic/TopCollection.h"
4241
#include "swift/Parse/Lexer.h"
4342
#include "swift/Parse/Parser.h"
43+
#include "swift/Sema/ConstraintSystem.h"
4444
#include "swift/Sema/IDETypeChecking.h"
45+
#include "swift/Subsystems.h"
4546
#include "llvm/ADT/DenseMap.h"
4647
#include "llvm/ADT/PointerUnion.h"
4748
#include "llvm/ADT/SmallString.h"
@@ -1751,7 +1752,7 @@ Stmt *PreCheckReturnStmtRequest::evaluate(Evaluator &evaluator, ReturnStmt *RS,
17511752
static bool isDiscardableType(Type type) {
17521753
// If type is `(_: repeat ...)`, it can be discardable.
17531754
if (auto *tuple = type->getAs<TupleType>()) {
1754-
if (tuple->isSingleUnlabeledPackExpansion()) {
1755+
if (constraints::isSingleUnlabeledPackExpansionTuple(tuple)) {
17551756
type = tuple->getElementType(0);
17561757
}
17571758
}

0 commit comments

Comments
 (0)