Skip to content

Commit f74a3b4

Browse files
committed
[SIL] Added async flag to SILExtInfo.
1 parent 5d813f3 commit f74a3b4

File tree

12 files changed

+53
-26
lines changed

12 files changed

+53
-26
lines changed

include/swift/AST/ExtInfo.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,17 @@ class SILExtInfoBuilder {
495495
// If bits are added or removed, then TypeBase::SILFunctionTypeBits
496496
// and NumMaskBits must be updated, and they must match.
497497

498-
// |representation|pseudogeneric| noescape |differentiability|
499-
// | 0 .. 3 | 4 | 5 | 6 .. 7 |
498+
// |representation|pseudogeneric| noescape | async | differentiability|
499+
// | 0 .. 3 | 4 | 5 | 6 | 7 .. 8 |
500500
//
501501
enum : unsigned {
502502
RepresentationMask = 0xF << 0,
503503
PseudogenericMask = 1 << 4,
504504
NoEscapeMask = 1 << 5,
505-
DifferentiabilityMaskOffset = 6,
505+
AsyncMask = 1 << 6,
506+
DifferentiabilityMaskOffset = 7,
506507
DifferentiabilityMask = 0x3 << DifferentiabilityMaskOffset,
507-
NumMaskBits = 8
508+
NumMaskBits = 9
508509
};
509510

510511
unsigned bits; // Naturally sized for speed.
@@ -523,10 +524,11 @@ class SILExtInfoBuilder {
523524

524525
// Constructor for polymorphic type.
525526
SILExtInfoBuilder(Representation rep, bool isPseudogeneric, bool isNoEscape,
526-
DifferentiabilityKind diffKind, const clang::Type *type)
527+
bool isAsync, DifferentiabilityKind diffKind,
528+
const clang::Type *type)
527529
: SILExtInfoBuilder(
528530
((unsigned)rep) | (isPseudogeneric ? PseudogenericMask : 0) |
529-
(isNoEscape ? NoEscapeMask : 0) |
531+
(isNoEscape ? NoEscapeMask : 0) | (isAsync ? AsyncMask : 0) |
530532
(((unsigned)diffKind << DifferentiabilityMaskOffset) &
531533
DifferentiabilityMask),
532534
ClangTypeInfo(type)) {}
@@ -552,6 +554,8 @@ class SILExtInfoBuilder {
552554
// Is this function guaranteed to be no-escape by the type system?
553555
constexpr bool isNoEscape() const { return bits & NoEscapeMask; }
554556

557+
constexpr bool isAsync() const { return bits & AsyncMask; }
558+
555559
constexpr DifferentiabilityKind getDifferentiabilityKind() const {
556560
return DifferentiabilityKind((bits & DifferentiabilityMask) >>
557561
DifferentiabilityMaskOffset);
@@ -616,6 +620,10 @@ class SILExtInfoBuilder {
616620
: (bits & ~NoEscapeMask),
617621
clangTypeInfo);
618622
}
623+
SILExtInfoBuilder withAsync(bool isAsync = true) const {
624+
return SILExtInfoBuilder(isAsync ? (bits | AsyncMask) : (bits & ~AsyncMask),
625+
clangTypeInfo);
626+
}
619627
SILExtInfoBuilder
620628
withDifferentiabilityKind(DifferentiabilityKind differentiability) const {
621629
return SILExtInfoBuilder(
@@ -657,8 +665,8 @@ class SILExtInfo {
657665

658666
static SILExtInfo getThin() {
659667
return SILExtInfoBuilder(SILExtInfoBuilder::Representation::Thin, false,
660-
false, DifferentiabilityKind::NonDifferentiable,
661-
nullptr)
668+
false, false,
669+
DifferentiabilityKind::NonDifferentiable, nullptr)
662670
.build();
663671
}
664672

@@ -681,6 +689,8 @@ class SILExtInfo {
681689

682690
constexpr bool isNoEscape() const { return builder.isNoEscape(); }
683691

692+
constexpr bool isAsync() const { return builder.isAsync(); }
693+
684694
constexpr DifferentiabilityKind getDifferentiabilityKind() const {
685695
return builder.getDifferentiabilityKind();
686696
}

include/swift/AST/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
308308

309309
protected:
310310
enum { NumAFTExtInfoBits = 9 };
311-
enum { NumSILExtInfoBits = 8 };
311+
enum { NumSILExtInfoBits = 9 };
312312
union { uint64_t OpaqueBits;
313313

314314
SWIFT_INLINE_BITFIELD_BASE(TypeBase, bitmax(NumTypeKindBits,8) +
@@ -4046,7 +4046,7 @@ class SILFunctionType final
40464046
return SILCoroutineKind(Bits.SILFunctionType.CoroutineKind);
40474047
}
40484048

4049-
bool isAsync() const { return Bits.SILFunctionType.IsAsync; }
4049+
bool isAsync() const { return getExtInfo().isAsync(); }
40504050

40514051
/// Return the array of all the yields.
40524052
ArrayRef<SILYieldInfo> getYields() const {

include/swift/Demangling/TypeDecoder.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,49 +238,60 @@ class ImplFunctionTypeFlags {
238238
unsigned Rep : 3;
239239
unsigned Pseudogeneric : 1;
240240
unsigned Escaping : 1;
241+
unsigned Async : 1;
241242
unsigned DifferentiabilityKind : 2;
242243

243244
public:
244245
ImplFunctionTypeFlags()
245-
: Rep(0), Pseudogeneric(0), Escaping(0), DifferentiabilityKind(0) {}
246+
: Rep(0), Pseudogeneric(0), Escaping(0), Async(0),
247+
DifferentiabilityKind(0) {}
246248

247249
ImplFunctionTypeFlags(ImplFunctionRepresentation rep, bool pseudogeneric,
248-
bool noescape,
250+
bool noescape, bool async,
249251
ImplFunctionDifferentiabilityKind diffKind)
250252
: Rep(unsigned(rep)), Pseudogeneric(pseudogeneric), Escaping(noescape),
251-
DifferentiabilityKind(unsigned(diffKind)) {}
253+
Async(async), DifferentiabilityKind(unsigned(diffKind)) {}
252254

253255
ImplFunctionTypeFlags
254256
withRepresentation(ImplFunctionRepresentation rep) const {
255257
return ImplFunctionTypeFlags(
256-
rep, Pseudogeneric, Escaping,
258+
rep, Pseudogeneric, Escaping, Async,
259+
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
260+
}
261+
262+
ImplFunctionTypeFlags
263+
withAsync() const {
264+
return ImplFunctionTypeFlags(
265+
ImplFunctionRepresentation(Rep), Pseudogeneric, Escaping, true,
257266
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
258267
}
259268

260269
ImplFunctionTypeFlags
261270
withEscaping() const {
262271
return ImplFunctionTypeFlags(
263-
ImplFunctionRepresentation(Rep), Pseudogeneric, true,
272+
ImplFunctionRepresentation(Rep), Pseudogeneric, true, Async,
264273
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
265274
}
266275

267276
ImplFunctionTypeFlags
268277
withPseudogeneric() const {
269278
return ImplFunctionTypeFlags(
270-
ImplFunctionRepresentation(Rep), true, Escaping,
279+
ImplFunctionRepresentation(Rep), true, Escaping, Async,
271280
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
272281
}
273282

274283
ImplFunctionTypeFlags
275284
withDifferentiabilityKind(ImplFunctionDifferentiabilityKind diffKind) const {
276285
return ImplFunctionTypeFlags(ImplFunctionRepresentation(Rep), Pseudogeneric,
277-
Escaping, diffKind);
286+
Escaping, Async, diffKind);
278287
}
279288

280289
ImplFunctionRepresentation getRepresentation() const {
281290
return ImplFunctionRepresentation(Rep);
282291
}
283292

293+
bool isAsync() const { return Async; }
294+
284295
bool isEscaping() const { return Escaping; }
285296

286297
bool isPseudogeneric() const { return Pseudogeneric; }

lib/AST/ASTDemangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ Type ASTBuilder::createImplFunctionType(
530530

531531
// [TODO: Store-SIL-Clang-type]
532532
auto einfo = SILExtInfoBuilder(representation, flags.isPseudogeneric(),
533-
!flags.isEscaping(), diffKind,
533+
!flags.isEscaping(), flags.isAsync(), diffKind,
534534
/*clangFunctionType*/ nullptr)
535535
.build();
536536

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,6 +4133,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41334133
if (info.isNoEscape()) {
41344134
Printer.printSimpleAttr("@noescape") << " ";
41354135
}
4136+
if (info.isAsync()) {
4137+
Printer.printSimpleAttr("@async") << " ";
4138+
}
41364139
}
41374140

41384141
void visitAnyFunctionTypeParams(ArrayRef<AnyFunctionType::Param> Params,

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ SILGenModule::getKeyPathProjectionCoroutine(bool isReadAccess,
415415
SILFunctionType::ExtInfoBuilder(SILFunctionTypeRepresentation::Thin,
416416
/*pseudogeneric*/ false,
417417
/*non-escaping*/ false,
418+
/*async*/ false,
418419
DifferentiabilityKind::NonDifferentiable,
419420
/*clangFunctionType*/ nullptr)
420421
.build();

lib/SILOptimizer/Transforms/Outliner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ CanSILFunctionType BridgedProperty::getOutlinedFunctionType(SILModule &M) {
298298
auto ExtInfo = SILFunctionType::ExtInfoBuilder(
299299
SILFunctionType::Representation::Thin,
300300
/*pseudogeneric*/ false, /*noescape*/ false,
301-
DifferentiabilityKind::NonDifferentiable,
301+
/*async*/ false, DifferentiabilityKind::NonDifferentiable,
302302
/*clangFunctionType*/ nullptr)
303303
.build();
304304
auto FunctionType = SILFunctionType::get(
@@ -1181,6 +1181,7 @@ CanSILFunctionType ObjCMethodCall::getOutlinedFunctionType(SILModule &M) {
11811181
SILFunctionType::ExtInfoBuilder(SILFunctionType::Representation::Thin,
11821182
/*pseudogeneric*/ false,
11831183
/*noescape*/ false,
1184+
/*async*/ false,
11841185
DifferentiabilityKind::NonDifferentiable,
11851186
/*clangFunctionType*/ nullptr)
11861187
.build();

lib/SILOptimizer/UtilityPasses/BugReducerTester.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ class BugReducerTester : public SILFunctionTransform {
8686
nullptr,
8787
SILFunctionType::ExtInfoBuilder(
8888
SILFunctionType::Representation::Thin, false /*isPseudoGeneric*/,
89-
false /*noescape*/, DifferentiabilityKind::NonDifferentiable,
89+
false /*noescape*/, false /*async*/,
90+
DifferentiabilityKind::NonDifferentiable,
9091
nullptr /*clangFunctionType*/)
9192
.build(),
9293
SILCoroutineKind::None, ParameterConvention::Direct_Unowned,

lib/Sema/TypeCheckType.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,8 +2146,6 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
21462146
SILFunctionType::Representation rep;
21472147
TypeRepr *witnessMethodProtocol = nullptr;
21482148

2149-
auto isAsync = attrs.has(TAK_async);
2150-
21512149
auto coroutineKind = SILCoroutineKind::None;
21522150
if (attrs.has(TAK_yield_once)) {
21532151
coroutineKind = SILCoroutineKind::YieldOnce;
@@ -2226,7 +2224,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
22262224
// [TODO: Store-SIL-Clang-type]
22272225
auto extInfo = SILFunctionType::ExtInfoBuilder(
22282226
rep, attrs.has(TAK_pseudogeneric),
2229-
attrs.has(TAK_noescape), diffKind, nullptr)
2227+
attrs.has(TAK_noescape), attrs.has(TAK_async),
2228+
diffKind, nullptr)
22302229
.build();
22312230

22322231
ty = resolveSILFunctionType(fnRepr, options, coroutineKind, extInfo,

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5419,7 +5419,8 @@ class TypeDeserializer {
54195419

54205420
auto extInfo =
54215421
SILFunctionType::ExtInfoBuilder(*representation, pseudogeneric,
5422-
noescape, *diffKind, clangFunctionType)
5422+
noescape, async, *diffKind,
5423+
clangFunctionType)
54235424
.build();
54245425

54255426
// Process the coroutine kind.

test/SIL/Parser/async.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bb0(%int : $Builtin.Int32):
1616
return %0 : $()
1717
}
1818

19-
// CHECK: sil @async_test : $@async
19+
// CHECK: sil @async_test : $@convention(thin) @async
2020
sil @async_test : $@async () -> () {
2121
bb0:
2222
%0 = tuple ()

test/SIL/Serialization/basic.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bb0(%0 : @guaranteed $Builtin.NativeObject):
1515
return undef : $()
1616
}
1717

18-
// CHECK-LABEL: sil @async_test : $@async @convention(thin)
18+
// CHECK-LABEL: sil @async_test : $@convention(thin) @async
1919
sil @async_test : $@async () -> () {
2020
bb0:
2121
%0 = tuple ()

0 commit comments

Comments
 (0)