Skip to content

Commit eaab395

Browse files
committed
Remove ExplicitCompletionHandlerIndex flag
Assuming that we don't typecheck a deserialized module, we don't actually need the ExplicitCompletionHandlerIndex. We used this flag to determine whether we could trust the number stored in the handler index or just take the last parameter of the function we're attached to. Since we only typecheck it before serialization, we can safely check that the completion handler location is valid before choosing whether we should trust it or not.
1 parent 9f41261 commit eaab395

File tree

6 files changed

+6
-18
lines changed

6 files changed

+6
-18
lines changed

include/swift/AST/Attr.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,14 +2172,10 @@ class CompletionHandlerAsyncAttr final : public DeclAttribute {
21722172
/// Source location of the completion handler index passed to the index
21732173
const SourceLoc CompletionHandlerIndexLoc;
21742174

2175-
/// True when the completion handler was specified explicitly
2176-
const bool ExplicitCompletionHandlerIndex;
2177-
21782175
AbstractFunctionDecl *AsyncFunctionDecl = nullptr;
21792176

21802177
CompletionHandlerAsyncAttr(DeclNameRef asyncFunctionName,
21812178
SourceLoc asyncFunctionNameLoc,
2182-
bool explicitCompletionHandlerIndex,
21832179
size_t completionHandlerIndex,
21842180
SourceLoc completionHandlerIndexLoc,
21852181
SourceLoc atLoc, SourceRange range)
@@ -2188,19 +2184,16 @@ class CompletionHandlerAsyncAttr final : public DeclAttribute {
21882184
AsyncFunctionName(asyncFunctionName),
21892185
AsyncFunctionNameLoc(asyncFunctionNameLoc),
21902186
CompletionHandlerIndex(completionHandlerIndex),
2191-
CompletionHandlerIndexLoc(completionHandlerIndexLoc),
2192-
ExplicitCompletionHandlerIndex(explicitCompletionHandlerIndex) {}
2187+
CompletionHandlerIndexLoc(completionHandlerIndexLoc) {}
21932188

21942189
CompletionHandlerAsyncAttr(AbstractFunctionDecl &asyncFunctionDecl,
2195-
bool explicitCompletionHandlerIndex,
21962190
size_t completionHandlerIndex,
21972191
SourceLoc completionHandlerIndexLoc,
21982192
SourceLoc atLoc, SourceRange range)
21992193
: DeclAttribute(DAK_CompletionHandlerAsync, atLoc, range,
22002194
/*implicit*/ false),
22012195
CompletionHandlerIndex(completionHandlerIndex),
22022196
CompletionHandlerIndexLoc(completionHandlerIndexLoc),
2203-
ExplicitCompletionHandlerIndex(explicitCompletionHandlerIndex),
22042197
AsyncFunctionDecl(&asyncFunctionDecl) {}
22052198

22062199

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ parseCompletionHandlerAsyncAttribute(Parser &P, StringRef AttrName,
16301630

16311631
return new (P.Context) CompletionHandlerAsyncAttr(
16321632
parsedAsyncName.formDeclNameRef(P.Context), nameLoc,
1633-
handlerIndexLoc.isValid(), handlerIndex, handlerIndexLoc, AtLoc,
1633+
handlerIndex, handlerIndexLoc, AtLoc,
16341634
AttrRange);
16351635
}
16361636

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5710,7 +5710,7 @@ void AttributeChecker::visitCompletionHandlerAsyncAttr(
57105710
diag::attr_completion_handler_async_handler_not_func, attr);
57115711
return;
57125712
}
5713-
size_t completionHandlerIndex = attr->ExplicitCompletionHandlerIndex
5713+
size_t completionHandlerIndex = attr->CompletionHandlerIndexLoc.isValid()
57145714
? attr->CompletionHandlerIndex
57155715
: attachedFunctionParams->size() - 1;
57165716
if (attachedFunctionParams->size() < completionHandlerIndex) {

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4554,17 +4554,14 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
45544554

45554555
case decls_block::CompletionHandlerAsync_DECL_ATTR: {
45564556
uint64_t handlerIndex;
4557-
bool explicitHandlerIndex;
45584557
uint64_t asyncFunctionDeclID;
45594558
serialization::decls_block::CompletionHandlerAsyncDeclAttrLayout::
4560-
readRecord(scratch, explicitHandlerIndex, handlerIndex,
4561-
asyncFunctionDeclID);
4559+
readRecord(scratch, handlerIndex, asyncFunctionDeclID);
45624560

45634561
auto mappedFunctionDecl =
45644562
cast<AbstractFunctionDecl>(MF.getDecl(asyncFunctionDeclID));
45654563
Attr = new (ctx) CompletionHandlerAsyncAttr(
4566-
*mappedFunctionDecl, explicitHandlerIndex, handlerIndex,
4567-
/*handlerIndexLoc*/ SourceLoc(),
4564+
*mappedFunctionDecl, handlerIndex, /*handlerIndexLoc*/ SourceLoc(),
45684565
/*atLoc*/ SourceLoc(), /*range*/ SourceRange());
45694566
break;
45704567
}

lib/Serialization/ModuleFormat.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,6 @@ namespace decls_block {
19261926

19271927
using CompletionHandlerAsyncDeclAttrLayout = BCRecordLayout<
19281928
CompletionHandlerAsync_DECL_ATTR,
1929-
BCFixed<1>, // True if explicit handler index
19301929
BCVBR<5>, // Completion handler index
19311930
DeclIDField // Mapped async function decl
19321931
>;

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,8 +2632,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
26322632
auto asyncFuncDeclID = S.addDeclRef(attr->AsyncFunctionDecl);
26332633

26342634
CompletionHandlerAsyncDeclAttrLayout::emitRecord(
2635-
S.Out, S.ScratchRecord, abbrCode,
2636-
attr->ExplicitCompletionHandlerIndex, attr->CompletionHandlerIndex,
2635+
S.Out, S.ScratchRecord, abbrCode, attr->CompletionHandlerIndex,
26372636
asyncFuncDeclID);
26382637
return;
26392638
}

0 commit comments

Comments
 (0)