Skip to content

Commit 3de9790

Browse files
committed
[NFC] Avoid passing a TypeLoc to AccessorDecl::create
1 parent 78a2460 commit 3de9790

File tree

7 files changed

+20
-27
lines changed

7 files changed

+20
-27
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6410,7 +6410,7 @@ class AccessorDecl final : public FuncDecl {
64106410
bool throws, SourceLoc throwsLoc,
64116411
GenericParamList *genericParams,
64126412
ParameterList *parameterList,
6413-
TypeLoc fnRetType, DeclContext *parent,
6413+
Type fnRetType, DeclContext *parent,
64146414
ClangNode clangNode = ClangNode());
64156415

64166416
SourceLoc getAccessorKeywordLoc() const { return AccessorKeywordLoc; }

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7249,15 +7249,15 @@ AccessorDecl *AccessorDecl::create(ASTContext &ctx,
72497249
bool throws, SourceLoc throwsLoc,
72507250
GenericParamList *genericParams,
72517251
ParameterList * bodyParams,
7252-
TypeLoc fnRetType,
7252+
Type fnRetType,
72537253
DeclContext *parent,
72547254
ClangNode clangNode) {
72557255
auto *D = AccessorDecl::createImpl(
72567256
ctx, declLoc, accessorKeywordLoc, accessorKind, storage,
72577257
staticLoc, staticSpelling, throws, throwsLoc,
72587258
genericParams, parent, clangNode);
72597259
D->setParameters(bodyParams);
7260-
D->getBodyResultTypeLoc() = fnRetType;
7260+
D->getBodyResultTypeLoc() = TypeLoc::withoutLoc(fnRetType);
72617261
return D;
72627262
}
72637263

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ static FuncDecl *createFuncOrAccessor(ASTContext &ctx, SourceLoc funcLoc,
163163
bool throws,
164164
DeclContext *dc,
165165
ClangNode clangNode) {
166-
TypeLoc resultTypeLoc = resultTy ? TypeLoc::withoutLoc(resultTy) : TypeLoc();
167166
if (accessorInfo) {
168167
return AccessorDecl::create(ctx, funcLoc,
169168
/*accessorKeywordLoc*/ SourceLoc(),
@@ -175,8 +174,9 @@ static FuncDecl *createFuncOrAccessor(ASTContext &ctx, SourceLoc funcLoc,
175174
/*ThrowsLoc=*/SourceLoc(),
176175
/*GenericParams=*/nullptr,
177176
bodyParams,
178-
resultTypeLoc, dc, clangNode);
177+
resultTy, dc, clangNode);
179178
} else {
179+
TypeLoc resultTypeLoc = resultTy ? TypeLoc::withoutLoc(resultTy) : TypeLoc();
180180
return FuncDecl::create(ctx, /*StaticLoc=*/SourceLoc(),
181181
StaticSpellingKind::None,
182182
funcLoc, name, nameLoc,
@@ -611,7 +611,7 @@ static void makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
611611
/*Throws=*/false,
612612
/*ThrowsLoc=*/SourceLoc(),
613613
/*GenericParams=*/nullptr, params,
614-
TypeLoc::withoutLoc(rawTy), enumDecl);
614+
rawTy, enumDecl);
615615
getterDecl->setImplicit();
616616
getterDecl->setIsObjC(false);
617617
getterDecl->setIsDynamic(false);
@@ -687,7 +687,7 @@ static AccessorDecl *makeStructRawValueGetter(
687687
/*Throws=*/false,
688688
/*ThrowsLoc=*/SourceLoc(),
689689
/*GenericParams=*/nullptr, params,
690-
TypeLoc::withoutLoc(computedType), structDecl);
690+
computedType, structDecl);
691691
getterDecl->setImplicit();
692692
getterDecl->setIsObjC(false);
693693
getterDecl->setIsDynamic(false);
@@ -717,7 +717,7 @@ static AccessorDecl *makeFieldGetterDecl(ClangImporter::Implementation &Impl,
717717
/*Throws=*/false,
718718
/*ThrowsLoc=*/SourceLoc(),
719719
/*GenericParams=*/nullptr, params,
720-
TypeLoc::withoutLoc(getterType), importedDecl, clangNode);
720+
getterType, importedDecl, clangNode);
721721
getterDecl->setAccess(AccessLevel::Public);
722722
getterDecl->setIsObjC(false);
723723
getterDecl->setIsDynamic(false);
@@ -750,7 +750,7 @@ static AccessorDecl *makeFieldSetterDecl(ClangImporter::Implementation &Impl,
750750
/*Throws=*/false,
751751
/*ThrowsLoc=*/SourceLoc(),
752752
/*GenericParams=*/nullptr, params,
753-
TypeLoc::withoutLoc(voidTy), importedDecl, clangNode);
753+
voidTy, importedDecl, clangNode);
754754
setterDecl->setIsObjC(false);
755755
setterDecl->setIsDynamic(false);
756756
setterDecl->setSelfAccessKind(SelfAccessKind::Mutating);
@@ -1684,8 +1684,7 @@ buildSubscriptGetterDecl(ClangImporter::Implementation &Impl,
16841684
/*Throws=*/false,
16851685
/*ThrowsLoc=*/SourceLoc(),
16861686
/*GenericParams=*/nullptr,
1687-
params,
1688-
TypeLoc::withoutLoc(elementTy), dc,
1687+
params, elementTy, dc,
16891688
getter->getClangNode());
16901689

16911690
thunk->setAccess(getOverridableAccessLevel(dc));
@@ -1737,7 +1736,7 @@ buildSubscriptSetterDecl(ClangImporter::Implementation &Impl,
17371736
/*ThrowsLoc=*/SourceLoc(),
17381737
/*GenericParams=*/nullptr,
17391738
valueIndicesPL,
1740-
TypeLoc::withoutLoc(TupleType::getEmpty(C)), dc,
1739+
TupleType::getEmpty(C), dc,
17411740
setter->getClangNode());
17421741

17431742
thunk->setAccess(getOverridableAccessLevel(dc));
@@ -1922,7 +1921,7 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
19221921
/*ThrowsLoc=*/SourceLoc(),
19231922
/*GenericParams=*/nullptr,
19241923
params,
1925-
TypeLoc::withoutLoc(stringTy), swiftDecl);
1924+
stringTy, swiftDecl);
19261925
getterDecl->setIsObjC(false);
19271926
getterDecl->setIsDynamic(false);
19281927
getterDecl->setIsTransparent(false);
@@ -8557,8 +8556,7 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
85578556
/*Throws=*/false,
85588557
/*ThrowsLoc=*/SourceLoc(),
85598558
/*GenericParams=*/nullptr,
8560-
params,
8561-
TypeLoc::withoutLoc(type), dc);
8559+
params, type, dc);
85628560
func->setStatic(isStatic);
85638561
func->setAccess(getOverridableAccessLevel(dc));
85648562
func->setIsObjC(false);

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5234,9 +5234,6 @@ static AccessorDecl *createAccessorFunc(SourceLoc DeclLoc,
52345234
EndLoc);
52355235
}
52365236

5237-
// The typechecker will always fill this in.
5238-
TypeLoc ReturnType;
5239-
52405237
// Start the function.
52415238
auto *D = AccessorDecl::create(P->Context,
52425239
/*FIXME FuncLoc=*/DeclLoc,
@@ -5247,7 +5244,7 @@ static AccessorDecl *createAccessorFunc(SourceLoc DeclLoc,
52475244
(GenericParams
52485245
? GenericParams->clone(P->CurDeclContext)
52495246
: nullptr),
5250-
ValueArg, ReturnType,
5247+
ValueArg, Type(),
52515248
P->CurDeclContext);
52525249

52535250
return D;

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
899899
/*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
900900
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
901901
/*GenericParams=*/nullptr, params,
902-
TypeLoc::withoutLoc(intType), parentDC);
902+
intType, parentDC);
903903
getterDecl->setImplicit();
904904
getterDecl->setBodySynthesizer(&deriveBodyHashable_hashValue);
905905
getterDecl->setIsTransparent(false);

lib/Sema/DerivedConformances.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,14 @@ DerivedConformance::declareDerivedPropertyGetter(VarDecl *property,
430430
auto &C = property->getASTContext();
431431
auto parentDC = property->getDeclContext();
432432
ParameterList *params = ParameterList::createEmpty(C);
433-
434-
Type propertyInterfaceType = property->getInterfaceType();
435433

436434
auto getterDecl = AccessorDecl::create(C,
437435
/*FuncLoc=*/SourceLoc(), /*AccessorKeywordLoc=*/SourceLoc(),
438436
AccessorKind::Get, property,
439437
/*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
440438
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
441439
/*GenericParams=*/nullptr, params,
442-
TypeLoc::withoutLoc(propertyInterfaceType), parentDC);
440+
property->getInterfaceType(), parentDC);
443441
getterDecl->setImplicit();
444442
getterDecl->setIsTransparent(false);
445443

lib/Sema/TypeCheckStorage.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ static AccessorDecl *createGetterPrototype(AbstractStorageDecl *storage,
18811881
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
18821882
genericParams,
18831883
getterParams,
1884-
TypeLoc(),
1884+
Type(),
18851885
storage->getDeclContext());
18861886

18871887
// If we're stealing the 'self' from a lazy initializer, set it now.
@@ -1930,7 +1930,7 @@ static AccessorDecl *createSetterPrototype(AbstractStorageDecl *storage,
19301930
/*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
19311931
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
19321932
genericParams, params,
1933-
TypeLoc(),
1933+
Type(),
19341934
storage->getDeclContext());
19351935

19361936
if (isMutating)
@@ -2032,7 +2032,7 @@ createCoroutineAccessorPrototype(AbstractStorageDecl *storage,
20322032
auto *params = buildIndexForwardingParamList(storage, {}, ctx);
20332033

20342034
// Coroutine accessors always return ().
2035-
Type retTy = TupleType::getEmpty(ctx);
2035+
const Type retTy = TupleType::getEmpty(ctx);
20362036

20372037
GenericParamList *genericParams = createAccessorGenericParams(storage);
20382038

@@ -2041,7 +2041,7 @@ createCoroutineAccessorPrototype(AbstractStorageDecl *storage,
20412041
kind, storage,
20422042
/*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
20432043
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
2044-
genericParams, params, TypeLoc::withoutLoc(retTy), dc);
2044+
genericParams, params, retTy, dc);
20452045

20462046
if (isMutating)
20472047
accessor->setSelfAccessKind(SelfAccessKind::Mutating);

0 commit comments

Comments
 (0)