Skip to content

Commit 4da65bb

Browse files
committed
eliminate TypeBase::getRelabeledType()
We used to build the type for a parameter types and then relabeling them from the DeclName. Now we build the ParameterList and use that to construct the DeclName. Since we get the parameter list type from the same ParameterList, it is always properly labeled. NFC.
1 parent fe3250e commit 4da65bb

File tree

4 files changed

+2
-43
lines changed

4 files changed

+2
-43
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {
672672
/// the result would be the (parenthesized) type ((int, int)).
673673
Type getUnlabeledType(ASTContext &Context);
674674

675-
/// Relabel the elements of the given type with the given new
676-
/// (top-level) labels.
677-
Type getRelabeledType(ASTContext &Context, ArrayRef<Identifier> labels);
678-
679675
/// \brief Retrieve the type without any default arguments.
680676
Type getWithoutDefaultArgs(const ASTContext &Context);
681677

lib/AST/Type.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -765,38 +765,6 @@ Type TypeBase::getUnlabeledType(ASTContext &Context) {
765765
/*defaultArgs=*/true);
766766
}
767767

768-
Type TypeBase::getRelabeledType(ASTContext &ctx,
769-
ArrayRef<Identifier> labels) {
770-
if (auto tupleTy = dyn_cast<TupleType>(this)) {
771-
assert(labels.size() == tupleTy->getNumElements() &&
772-
"Wrong number of labels");
773-
SmallVector<TupleTypeElt, 4> elements;
774-
unsigned i = 0;
775-
bool anyChanged = false;
776-
for (const auto &elt : tupleTy->getElements()) {
777-
if (elt.getName() != labels[i])
778-
anyChanged = true;
779-
780-
elements.push_back(TupleTypeElt(elt.getType(), labels[i],
781-
elt.getDefaultArgKind(), elt.isVararg()));
782-
++i;
783-
}
784-
785-
if (!anyChanged)
786-
return this;
787-
788-
return TupleType::get(elements, ctx);
789-
}
790-
791-
// If there is no label, the type is unchanged.
792-
if (labels[0].empty())
793-
return this;
794-
795-
// Create a one-element tuple to capture the label.
796-
TupleTypeElt elt(this, labels[0]);
797-
return TupleType::get(elt, ctx);
798-
}
799-
800768
Type TypeBase::getWithoutDefaultArgs(const ASTContext &Context) {
801769
return getStrippedType(Context, Type(this), /*labels=*/false,
802770
/*defaultArgs=*/true);

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,10 +1356,6 @@ void swift::configureConstructorType(ConstructorDecl *ctor,
13561356
resultType = OptionalType::get(ctor->getFailability(), resultType);
13571357
}
13581358

1359-
// Use the argument names in the argument type.
1360-
argType = argType->getRelabeledType(ctor->getASTContext(),
1361-
ctor->getFullName().getArgumentNames());
1362-
13631359
auto extInfo = AnyFunctionType::ExtInfo().withThrows(throws);
13641360

13651361
GenericParamList *outerGenericParams =

lib/Sema/TypeCheckPattern.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,6 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
15821582
///
15831583
bool TypeChecker::coerceParameterListToType(ParameterList *P, DeclContext *DC,
15841584
Type paramListType) {
1585-
TypeResolutionOptions options;
1586-
15871585
bool hadError = paramListType->is<ErrorType>();
15881586

15891587
// Sometimes a scalar type gets applied to a single-argument parameter list.
@@ -1592,7 +1590,8 @@ bool TypeChecker::coerceParameterListToType(ParameterList *P, DeclContext *DC,
15921590

15931591
// Check that the type, if explicitly spelled, is ok.
15941592
if (param.type.getTypeRepr()) {
1595-
hadError |= validateParameterType(param, DC, options, nullptr, *this);
1593+
hadError |= validateParameterType(param, DC, TypeResolutionOptions(),
1594+
nullptr, *this);
15961595

15971596
// Now that we've type checked the explicit argument type, see if it
15981597
// agrees with the contextual type.

0 commit comments

Comments
 (0)