Skip to content

Commit 8935acd

Browse files
committed
[NFC] AST: Remove IdentTypeRepr::create
1 parent f237fba commit 8935acd

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

include/swift/AST/TypeRepr.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,6 @@ class IdentTypeRepr : public TypeRepr {
256256
explicit IdentTypeRepr(TypeReprKind K) : TypeRepr(K) {}
257257

258258
public:
259-
/// Copies the provided array and creates a CompoundIdentTypeRepr or just
260-
/// returns the single entry in the array if it contains only one.
261-
static IdentTypeRepr *create(ASTContext &C,
262-
ArrayRef<ComponentIdentTypeRepr *> Components);
263-
264259
class ComponentRange;
265260
inline ComponentRange getComponentRange();
266261

lib/AST/CASTBridging.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,14 @@ void *TupleTypeRepr_create(void *ctx, BridgedArrayRef elements, void *lParenLoc,
497497
SourceRange{lParen, rParen});
498498
}
499499

500-
void *IdentTypeRepr_create(void *ctx, BridgedArrayRef components) {
500+
void *IdentTypeRepr_create(void *ctx, BridgedArrayRef bridgedComponents) {
501501
ASTContext &Context = *static_cast<ASTContext *>(ctx);
502-
return IdentTypeRepr::create(
503-
Context, getArrayRef<ComponentIdentTypeRepr *>(components));
502+
auto components = getArrayRef<ComponentIdentTypeRepr *>(bridgedComponents);
503+
if (components.size() == 1) {
504+
return components.front();
505+
}
506+
507+
return CompoundIdentTypeRepr::create(Context, components);
504508
}
505509

506510
void *CompositionTypeRepr_create(void *ctx, BridgedArrayRef types,

lib/AST/Expr.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ TypeExpr *TypeExpr::createForMemberDecl(DeclNameLoc ParentNameLoc,
22252225
NewComp->setValue(Decl, nullptr);
22262226
Components.push_back(NewComp);
22272227

2228-
auto *NewTypeRepr = IdentTypeRepr::create(C, Components);
2228+
auto *NewTypeRepr = CompoundIdentTypeRepr::create(C, Components);
22292229
return new (C) TypeExpr(NewTypeRepr);
22302230
}
22312231

@@ -2246,7 +2246,7 @@ TypeExpr *TypeExpr::createForMemberDecl(IdentTypeRepr *ParentTR,
22462246
NewComp->setValue(Decl, nullptr);
22472247
Components.push_back(NewComp);
22482248

2249-
auto *NewTypeRepr = IdentTypeRepr::create(C, Components);
2249+
auto *NewTypeRepr = CompoundIdentTypeRepr::create(C, Components);
22502250
return new (C) TypeExpr(NewTypeRepr);
22512251
}
22522252

@@ -2295,7 +2295,12 @@ TypeExpr *TypeExpr::createForSpecializedDecl(IdentTypeRepr *ParentTR,
22952295
genericComp->setValue(last->getBoundDecl(), last->getDeclContext());
22962296
components.push_back(genericComp);
22972297

2298-
auto *genericRepr = IdentTypeRepr::create(C, components);
2298+
TypeRepr *genericRepr = nullptr;
2299+
if (components.size() == 1) {
2300+
genericRepr = components.front();
2301+
} else {
2302+
genericRepr = CompoundIdentTypeRepr::create(C, components);
2303+
}
22992304
return new (C) TypeExpr(genericRepr);
23002305
}
23012306

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
30763076
identTypeRepr
30773077
};
30783078

3079-
auto *newTE = new (ctx) TypeExpr(IdentTypeRepr::create(ctx, components));
3079+
auto *newTE = new (ctx)
3080+
TypeExpr(CompoundIdentTypeRepr::create(ctx, components));
30803081
attr->resetTypeInformation(newTE);
30813082
return nominal;
30823083
}

lib/AST/TypeRepr.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,6 @@ void AttributedTypeRepr::printAttrs(ASTPrinter &Printer,
245245
Printer.printSimpleAttr("@_noMetadata") << " ";
246246
}
247247

248-
IdentTypeRepr *IdentTypeRepr::create(ASTContext &C,
249-
ArrayRef<ComponentIdentTypeRepr *> Components) {
250-
assert(!Components.empty());
251-
if (Components.size() == 1)
252-
return Components.front();
253-
254-
return CompoundIdentTypeRepr::create(C, Components);
255-
}
256-
257248
static void printGenericArgs(ASTPrinter &Printer, const PrintOptions &Opts,
258249
ArrayRef<TypeRepr *> Args) {
259250
if (Args.empty())

lib/Parse/ParseType.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,11 @@ Parser::parseTypeIdentifier(bool isParsingQualifiedDeclBaseType) {
752752

753753
IdentTypeRepr *ITR = nullptr;
754754
if (!ComponentsR.empty()) {
755-
ITR = IdentTypeRepr::create(Context, ComponentsR);
755+
if (ComponentsR.size() == 1) {
756+
ITR = ComponentsR.front();
757+
} else {
758+
ITR = CompoundIdentTypeRepr::create(Context, ComponentsR);
759+
}
756760
}
757761

758762
if (Status.hasCodeCompletion()) {

lib/Sema/TypeCheckPattern.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,12 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
482482
const auto options =
483483
TypeResolutionOptions(None) | TypeResolutionFlags::SilenceErrors;
484484

485-
auto *repr = IdentTypeRepr::create(Context, components);
485+
IdentTypeRepr *repr = nullptr;
486+
if (components.size() == 1) {
487+
repr = components.front();
488+
} else {
489+
repr = CompoundIdentTypeRepr::create(Context, components);
490+
}
486491

487492
// See if the repr resolves to a type.
488493
const auto ty = TypeResolution::resolveContextualType(
@@ -604,7 +609,12 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
604609

605610
// Otherwise, see whether we had an enum type as the penultimate
606611
// component, and look up an element inside it.
607-
auto *prefixRepr = IdentTypeRepr::create(Context, components);
612+
IdentTypeRepr *prefixRepr = nullptr;
613+
if (components.size() == 1) {
614+
prefixRepr = components.front();
615+
} else {
616+
prefixRepr = CompoundIdentTypeRepr::create(Context, components);
617+
}
608618

609619
// See first if the entire repr resolves to a type.
610620
const Type enumTy = TypeResolution::resolveContextualType(

0 commit comments

Comments
 (0)