Skip to content

Commit 19ab68d

Browse files
committed
[NFC] Strip UnresolvedSpecializeExpr of its TypeLoc
No caller needed the type
1 parent 5b30603 commit 19ab68d

File tree

7 files changed

+22
-40
lines changed

7 files changed

+22
-40
lines changed

include/swift/AST/Expr.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,7 +3386,7 @@ class BridgeToObjCExpr : public ImplicitConversionExpr {
33863386
/// UnresolvedSpecializeExpr - Represents an explicit specialization using
33873387
/// a type parameter list (e.g. "Vector<Int>") that has not been resolved.
33883388
class UnresolvedSpecializeExpr final : public Expr,
3389-
private llvm::TrailingObjects<UnresolvedSpecializeExpr, TypeLoc> {
3389+
private llvm::TrailingObjects<UnresolvedSpecializeExpr, TypeRepr *> {
33903390
friend TrailingObjects;
33913391

33923392
Expr *SubExpr;
@@ -3395,31 +3395,27 @@ class UnresolvedSpecializeExpr final : public Expr,
33953395

33963396
UnresolvedSpecializeExpr(Expr *SubExpr,
33973397
SourceLoc LAngleLoc,
3398-
ArrayRef<TypeLoc> UnresolvedParams,
3398+
ArrayRef<TypeRepr *> UnresolvedParams,
33993399
SourceLoc RAngleLoc)
34003400
: Expr(ExprKind::UnresolvedSpecialize, /*Implicit=*/false),
34013401
SubExpr(SubExpr), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {
34023402
Bits.UnresolvedSpecializeExpr.NumUnresolvedParams = UnresolvedParams.size();
34033403
std::uninitialized_copy(UnresolvedParams.begin(), UnresolvedParams.end(),
3404-
getTrailingObjects<TypeLoc>());
3404+
getTrailingObjects<TypeRepr *>());
34053405
}
34063406

34073407
public:
34083408
static UnresolvedSpecializeExpr *
34093409
create(ASTContext &ctx, Expr *SubExpr, SourceLoc LAngleLoc,
3410-
ArrayRef<TypeLoc> UnresolvedParams, SourceLoc RAngleLoc);
3410+
ArrayRef<TypeRepr *> UnresolvedParams, SourceLoc RAngleLoc);
34113411

34123412
Expr *getSubExpr() const { return SubExpr; }
34133413
void setSubExpr(Expr *e) { SubExpr = e; }
34143414

34153415
/// Retrieve the list of type parameters. These parameters have not yet
34163416
/// been bound to archetypes of the entity to be specialized.
3417-
ArrayRef<TypeLoc> getUnresolvedParams() const {
3418-
return {getTrailingObjects<TypeLoc>(),
3419-
Bits.UnresolvedSpecializeExpr.NumUnresolvedParams};
3420-
}
3421-
MutableArrayRef<TypeLoc> getUnresolvedParams() {
3422-
return {getTrailingObjects<TypeLoc>(),
3417+
ArrayRef<TypeRepr *> getUnresolvedParams() const {
3418+
return {getTrailingObjects<TypeRepr *>(),
34233419
Bits.UnresolvedSpecializeExpr.NumUnresolvedParams};
34243420
}
34253421

lib/AST/Expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,9 @@ ErasureExpr *ErasureExpr::create(ASTContext &ctx, Expr *subExpr, Type type,
11911191

11921192
UnresolvedSpecializeExpr *UnresolvedSpecializeExpr::create(ASTContext &ctx,
11931193
Expr *SubExpr, SourceLoc LAngleLoc,
1194-
ArrayRef<TypeLoc> UnresolvedParams,
1194+
ArrayRef<TypeRepr *> UnresolvedParams,
11951195
SourceLoc RAngleLoc) {
1196-
auto size = totalSizeToAlloc<TypeLoc>(UnresolvedParams.size());
1196+
auto size = totalSizeToAlloc<TypeRepr *>(UnresolvedParams.size());
11971197
auto mem = ctx.Allocate(size, alignof(UnresolvedSpecializeExpr));
11981198
return ::new(mem) UnresolvedSpecializeExpr(SubExpr, LAngleLoc,
11991199
UnresolvedParams, RAngleLoc);

lib/IDE/Formatting.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,9 +2295,8 @@ class FormatWalker : public ASTWalker {
22952295

22962296
SourceLoc ContextLoc = getContextLocForArgs(SM, USE);
22972297
ListAligner Aligner(SM, TargetLocation, ContextLoc, L, R);
2298-
for (auto &Arg: USE->getUnresolvedParams()) {
2299-
if (auto *T = Arg.getTypeRepr())
2300-
Aligner.updateAlignment(T->getSourceRange(), T);
2298+
for (auto *T : USE->getUnresolvedParams()) {
2299+
Aligner.updateAlignment(T->getSourceRange(), T);
23012300
}
23022301
return Aligner.getContextAndSetAlignment(CtxOverride);
23032302
}

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,13 +1161,10 @@ Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic,
11611161
if (argStat.isError())
11621162
diagnose(LAngleLoc, diag::while_parsing_as_left_angle_bracket);
11631163

1164-
SmallVector<TypeLoc, 8> locArgs;
1165-
for (auto ty : args)
1166-
locArgs.push_back(ty);
11671164
SyntaxContext->createNodeInPlace(SyntaxKind::SpecializeExpr);
11681165
Result = makeParserResult(
11691166
Result, UnresolvedSpecializeExpr::create(
1170-
Context, Result.get(), LAngleLoc, locArgs, RAngleLoc));
1167+
Context, Result.get(), LAngleLoc, args, RAngleLoc));
11711168
}
11721169

11731170
continue;
@@ -2312,10 +2309,7 @@ Expr *Parser::parseExprIdentifier() {
23122309
}
23132310

23142311
if (hasGenericArgumentList) {
2315-
SmallVector<TypeLoc, 8> locArgs;
2316-
for (auto ty : args)
2317-
locArgs.push_back(ty);
2318-
E = UnresolvedSpecializeExpr::create(Context, E, LAngleLoc, locArgs,
2312+
E = UnresolvedSpecializeExpr::create(Context, E, LAngleLoc, args,
23192313
RAngleLoc);
23202314
}
23212315
return E;

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,8 +1691,7 @@ namespace {
16911691
if (BoundGenericType *bgt
16921692
= meta->getInstanceType()->getAs<BoundGenericType>()) {
16931693
ArrayRef<Type> typeVars = bgt->getGenericArgs();
1694-
MutableArrayRef<TypeLoc> specializations =
1695-
expr->getUnresolvedParams();
1694+
auto specializations = expr->getUnresolvedParams();
16961695

16971696
// If we have too many generic arguments, complain.
16981697
if (specializations.size() > typeVars.size()) {
@@ -1715,14 +1714,15 @@ namespace {
17151714
for (size_t i = 0, size = specializations.size(); i < size; ++i) {
17161715
TypeResolutionOptions options(TypeResolverContext::InExpression);
17171716
options |= TypeResolutionFlags::AllowUnboundGenerics;
1717+
auto tyLoc = TypeLoc{specializations[i]};
17181718
if (TypeChecker::validateType(CS.getASTContext(),
1719-
specializations[i],
1719+
tyLoc,
17201720
TypeResolution::forContextual(CS.DC),
17211721
options))
17221722
return Type();
17231723

17241724
CS.addConstraint(ConstraintKind::Bind,
1725-
typeVars[i], specializations[i].getType(),
1725+
typeVars[i], tyLoc.getType(),
17261726
locator);
17271727
}
17281728

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,19 +1427,14 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
14271427

14281428
TypeExpr *PreCheckExpression::simplifyUnresolvedSpecializeExpr(
14291429
UnresolvedSpecializeExpr *us) {
1430-
SmallVector<TypeRepr *, 4> genericArgs;
1431-
for (auto &type : us->getUnresolvedParams()) {
1432-
genericArgs.push_back(type.getTypeRepr());
1433-
}
1434-
1435-
auto angleRange = SourceRange(us->getLAngleLoc(), us->getRAngleLoc());
1436-
14371430
// If this is a reference type a specialized type, form a TypeExpr.
1438-
14391431
// The base should be a TypeExpr that we already resolved.
14401432
if (auto *te = dyn_cast<TypeExpr>(us->getSubExpr())) {
14411433
if (auto *ITR = dyn_cast_or_null<IdentTypeRepr>(te->getTypeRepr())) {
1442-
return TypeExpr::createForSpecializedDecl(ITR, genericArgs, angleRange,
1434+
return TypeExpr::createForSpecializedDecl(ITR,
1435+
us->getUnresolvedParams(),
1436+
SourceRange(us->getLAngleLoc(),
1437+
us->getRAngleLoc()),
14431438
getASTContext());
14441439
}
14451440
}

lib/Sema/TypeCheckPattern.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,11 @@ struct ExprToIdentTypeRepr : public ASTVisitor<ExprToIdentTypeRepr, bool>
211211
assert(!components.empty() && "no components before generic args?!");
212212

213213
// Track the AST location of the generic arguments.
214-
SmallVector<TypeRepr*, 4> argTypeReprs;
215-
for (auto &arg : use->getUnresolvedParams())
216-
argTypeReprs.push_back(arg.getTypeRepr());
217214
auto origComponent = components.back();
218215
components.back() =
219216
GenericIdentTypeRepr::create(C, origComponent->getNameLoc(),
220-
origComponent->getNameRef(), argTypeReprs,
217+
origComponent->getNameRef(),
218+
use->getUnresolvedParams(),
221219
SourceRange(use->getLAngleLoc(),
222220
use->getRAngleLoc()));
223221

0 commit comments

Comments
 (0)