Skip to content

Commit 9a10088

Browse files
[AST] Serialize bit async let info on AnyPattern
1 parent c1e2c7d commit 9a10088

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

include/swift/AST/Pattern.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class alignas(8) Pattern : public ASTAllocated<Pattern> {
7979
IsLet : 1
8080
);
8181

82+
SWIFT_INLINE_BITFIELD(AnyPattern, Pattern, 1,
83+
/// True if this is an "async let _" pattern.
84+
IsAsyncLet : 1);
85+
8286
} Bits;
8387

8488
Pattern(PatternKind kind) {
@@ -369,14 +373,12 @@ class NamedPattern : public Pattern {
369373
/// bind a name to it. This is spelled "_".
370374
class AnyPattern : public Pattern {
371375
SourceLoc Loc;
372-
/// Flag representing if this is an "async let _: Type" pattern since
373-
/// `async let _` is a subPattern of a \c TypedPattern represented
374-
/// as \c AnyPattern
375-
bool IsAsyncLet;
376376

377377
public:
378378
explicit AnyPattern(SourceLoc Loc, bool IsAsyncLet = false)
379-
: Pattern(PatternKind::Any), Loc(Loc), IsAsyncLet(IsAsyncLet) {}
379+
: Pattern(PatternKind::Any), Loc(Loc) {
380+
Bits.AnyPattern.IsAsyncLet = static_cast<uint64_t>(IsAsyncLet);
381+
}
380382

381383
static AnyPattern *createImplicit(ASTContext &Context) {
382384
auto *AP = new (Context) AnyPattern(SourceLoc());
@@ -387,7 +389,15 @@ class AnyPattern : public Pattern {
387389
SourceLoc getLoc() const { return Loc; }
388390
SourceRange getSourceRange() const { return Loc; }
389391

390-
bool isAsyncLet() const { return IsAsyncLet; }
392+
/// True if this is an "async let _ pattern since `async let _` could be a
393+
/// subPattern of a \c TypedPattern represented as \c AnyPattern e.g.
394+
/// "async let _: Type = <expr>" or simply just an \c AnyPattern in
395+
/// "async let _ = <expr>" case.
396+
bool isAsyncLet() const { return bool(Bits.AnyPattern.IsAsyncLet); }
397+
398+
void setIsAsyncLet() {
399+
Bits.AnyPattern.IsAsyncLet = static_cast<uint64_t>(true);
400+
}
391401

392402
static bool classof(const Pattern *P) {
393403
return P->getKind() == PatternKind::Any;

lib/Serialization/Deserialization.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,13 @@ Expected<Pattern *> ModuleFile::readPattern(DeclContext *owningDC) {
347347
}
348348
case decls_block::ANY_PATTERN: {
349349
TypeID typeID;
350+
bool isAsyncLet;
350351

351-
AnyPatternLayout::readRecord(scratch, typeID);
352+
AnyPatternLayout::readRecord(scratch, typeID, isAsyncLet);
352353
auto result = AnyPattern::createImplicit(getContext());
354+
if (isAsyncLet) {
355+
result->setIsAsyncLet();
356+
}
353357
recordPatternType(result, getType(typeID));
354358
restoreOffset.reset();
355359
return result;

lib/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,8 @@ namespace decls_block {
16081608

16091609
using AnyPatternLayout = BCRecordLayout<
16101610
ANY_PATTERN,
1611-
TypeIDField // type
1611+
TypeIDField, // type
1612+
BCFixed<1> // isAsyncLet
16121613
// FIXME: is the type necessary?
16131614
>;
16141615

lib/Serialization/Serialization.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3091,8 +3091,10 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
30913091
}
30923092
case PatternKind::Any: {
30933093
unsigned abbrCode = S.DeclTypeAbbrCodes[AnyPatternLayout::Code];
3094+
auto anyPattern = cast<AnyPattern>(pattern);
30943095
AnyPatternLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
3095-
S.addTypeRef(getPatternType()));
3096+
S.addTypeRef(getPatternType()),
3097+
anyPattern->isAsyncLet());
30963098
break;
30973099
}
30983100
case PatternKind::Typed: {

0 commit comments

Comments
 (0)