Skip to content

[ConstraintSystem] remove TupleType::isSingleUnlabeledPackExpansion in favor of constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple #67415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2494,10 +2494,6 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,

bool containsPackExpansionType() const;

/// Check whether this tuple consists of a single unlabeled element
/// of \c PackExpansionType.
bool isSingleUnlabeledPackExpansion() const;

private:
TupleType(ArrayRef<TupleTypeElt> elements, const ASTContext *CanCtx,
RecursiveTypeProperties properties)
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -6268,6 +6268,9 @@ Type isPlaceholderVar(PatternBindingDecl *PB);
/// Dump an anchor node for a constraint locator or contextual type.
void dumpAnchor(ASTNode anchor, SourceManager *SM, raw_ostream &out);

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

/// \returns null if \c type is not a single unlabeled pack expansion tuple.
Expand Down
8 changes: 0 additions & 8 deletions lib/AST/ParameterPack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,6 @@ bool CanTupleType::containsPackExpansionTypeImpl(CanTupleType tuple) {
return false;
}

bool TupleType::isSingleUnlabeledPackExpansion() const {
if (getNumElements() != 1)
return false;

const auto &elt = getElement(0);
return !elt.hasName() && elt.getType()->is<PackExpansionType>();
}

bool AnyFunctionType::containsPackExpansionType(ArrayRef<Param> params) {
for (auto param : params) {
auto paramTy = param.getPlainType();
Expand Down
7 changes: 3 additions & 4 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3858,10 +3858,9 @@ namespace {
if (auto *packRefExpr = expr->getPackRefExpr()) {
packRefExpr = cs.coerceToRValue(packRefExpr);
auto packRefType = cs.getType(packRefExpr);
if (auto *tuple = packRefType->getRValueType()->getAs<TupleType>();
tuple && tuple->isSingleUnlabeledPackExpansion()) {
auto patternType =
getPatternTypeOfSingleUnlabeledPackExpansionTuple(tuple);
if (auto patternType =
getPatternTypeOfSingleUnlabeledPackExpansionTuple(
packRefType)) {
auto *materializedPackExpr = MaterializePackExpr::create(
cs.getASTContext(), packRefExpr, packRefExpr->getLoc(),
patternType, /*implicit*/ true);
Expand Down
19 changes: 14 additions & 5 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,21 @@ bool constraints::isSingleUnlabeledPackExpansionTuple(Type type) {
}

Type constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple(Type type) {
if (!isSingleUnlabeledPackExpansionTuple(type)) {
return {};
if (isSingleUnlabeledPackExpansionTuple(type)) {
auto tuple = type->getRValueType()->castTo<TupleType>();
const auto &tupleElement = tuple->getElementType(0);
if (auto *expansion = tupleElement->getAs<PackExpansionType>()) {
return expansion->getPatternType();
}
if (auto *typeVar = tupleElement->getAs<TypeVariableType>()) {
auto *locator = typeVar->getImpl().getLocator();
if (auto expansionElement =
locator->getLastElementAs<LocatorPathElt::PackExpansionType>()) {
return expansionElement->getOpenedType()->getPatternType();
}
}
}
auto tuple = type->getRValueType()->castTo<TupleType>();
auto *expansion = tuple->getElementType(0)->castTo<PackExpansionType>();
return expansion->getPatternType();
return {};
}

static bool containsPackExpansionType(ArrayRef<AnyFunctionType::Param> params) {
Expand Down
13 changes: 7 additions & 6 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
//
//===----------------------------------------------------------------------===//

#include "TypeChecker.h"
#include "MiscDiagnostics.h"
#include "TypeCheckAvailability.h"
#include "TypeCheckConcurrency.h"
#include "TypeCheckDistributed.h"
#include "TypeCheckType.h"
#include "MiscDiagnostics.h"
#include "swift/Subsystems.h"
#include "TypeChecker.h"
#include "swift/AST/ASTPrinter.h"
#include "swift/AST/ASTScope.h"
#include "swift/AST/ASTWalker.h"
#include "swift/AST/ASTVisitor.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/ASTWalker.h"
#include "swift/AST/DiagnosticSuppression.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/Identifier.h"
#include "swift/AST/Initializer.h"
#include "swift/AST/NameLookup.h"
Expand All @@ -41,7 +40,9 @@
#include "swift/Basic/TopCollection.h"
#include "swift/Parse/Lexer.h"
#include "swift/Parse/Parser.h"
#include "swift/Sema/ConstraintSystem.h"
#include "swift/Sema/IDETypeChecking.h"
#include "swift/Subsystems.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/SmallString.h"
Expand Down Expand Up @@ -1751,7 +1752,7 @@ Stmt *PreCheckReturnStmtRequest::evaluate(Evaluator &evaluator, ReturnStmt *RS,
static bool isDiscardableType(Type type) {
// If type is `(_: repeat ...)`, it can be discardable.
if (auto *tuple = type->getAs<TupleType>()) {
if (tuple->isSingleUnlabeledPackExpansion()) {
if (constraints::isSingleUnlabeledPackExpansionTuple(tuple)) {
type = tuple->getElementType(0);
}
}
Expand Down