Skip to content

Commit 148ba9d

Browse files
authored
Merge pull request #33636 from nate-chandler/move-flag-to-SILExtInfo
2 parents 97609dd + f74a3b4 commit 148ba9d

34 files changed

+138
-145
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: 7 additions & 9 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) +
@@ -362,12 +362,11 @@ class alignas(1 << TypeAlignInBits) TypeBase {
362362
ID : 32
363363
);
364364

365-
SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+1+2+1+1,
365+
SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+2+1+1,
366366
ExtInfoBits : NumSILExtInfoBits,
367367
HasClangTypeInfo : 1,
368368
CalleeConvention : 3,
369369
HasErrorResult : 1,
370-
IsAsync : 1,
371370
CoroutineKind : 2,
372371
HasInvocationSubs : 1,
373372
HasPatternSubs : 1
@@ -3980,7 +3979,7 @@ class SILFunctionType final
39803979
+ 1);
39813980
}
39823981

3983-
SILFunctionType(GenericSignature genericSig, ExtInfo ext, bool isAsync,
3982+
SILFunctionType(GenericSignature genericSig, ExtInfo ext,
39843983
SILCoroutineKind coroutineKind,
39853984
ParameterConvention calleeConvention,
39863985
ArrayRef<SILParameterInfo> params,
@@ -3994,8 +3993,7 @@ class SILFunctionType final
39943993

39953994
public:
39963995
static CanSILFunctionType
3997-
get(GenericSignature genericSig, ExtInfo ext, bool isAsync,
3998-
SILCoroutineKind coroutineKind,
3996+
get(GenericSignature genericSig, ExtInfo ext, SILCoroutineKind coroutineKind,
39993997
ParameterConvention calleeConvention,
40003998
ArrayRef<SILParameterInfo> interfaceParams,
40013999
ArrayRef<SILYieldInfo> interfaceYields,
@@ -4048,7 +4046,7 @@ class SILFunctionType final
40484046
return SILCoroutineKind(Bits.SILFunctionType.CoroutineKind);
40494047
}
40504048

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

40534051
/// Return the array of all the yields.
40544052
ArrayRef<SILYieldInfo> getYields() const {
@@ -4577,14 +4575,14 @@ class SILFunctionType final
45774575

45784576
void Profile(llvm::FoldingSetNodeID &ID) {
45794577
Profile(ID, getInvocationGenericSignature(),
4580-
getExtInfo(), isAsync(), getCoroutineKind(), getCalleeConvention(),
4578+
getExtInfo(), getCoroutineKind(), getCalleeConvention(),
45814579
getParameters(), getYields(), getResults(),
45824580
getOptionalErrorResult(), getWitnessMethodConformanceOrInvalid(),
45834581
getPatternSubstitutions(), getInvocationSubstitutions());
45844582
}
45854583
static void
45864584
Profile(llvm::FoldingSetNodeID &ID, GenericSignature genericSig, ExtInfo info,
4587-
bool isAsync, SILCoroutineKind coroutineKind, ParameterConvention calleeConvention,
4585+
SILCoroutineKind coroutineKind, ParameterConvention calleeConvention,
45884586
ArrayRef<SILParameterInfo> params, ArrayRef<SILYieldInfo> yields,
45894587
ArrayRef<SILResultInfo> results, Optional<SILResultInfo> errorResult,
45904588
ProtocolConformanceRef conformance,

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/ASTContext.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,6 @@ void SILFunctionType::Profile(
32603260
llvm::FoldingSetNodeID &id,
32613261
GenericSignature genericParams,
32623262
ExtInfo info,
3263-
bool isAsync,
32643263
SILCoroutineKind coroutineKind,
32653264
ParameterConvention calleeConvention,
32663265
ArrayRef<SILParameterInfo> params,
@@ -3274,7 +3273,6 @@ void SILFunctionType::Profile(
32743273
auto infoKey = info.getFuncAttrKey();
32753274
id.AddInteger(infoKey.first);
32763275
id.AddPointer(infoKey.second);
3277-
id.AddBoolean(isAsync);
32783276
id.AddInteger(unsigned(coroutineKind));
32793277
id.AddInteger(unsigned(calleeConvention));
32803278
id.AddInteger(params.size());
@@ -3300,7 +3298,6 @@ void SILFunctionType::Profile(
33003298
SILFunctionType::SILFunctionType(
33013299
GenericSignature genericSig,
33023300
ExtInfo ext,
3303-
bool isAsync,
33043301
SILCoroutineKind coroutineKind,
33053302
ParameterConvention calleeConvention,
33063303
ArrayRef<SILParameterInfo> params,
@@ -3326,7 +3323,6 @@ SILFunctionType::SILFunctionType(
33263323
"Bits were dropped!");
33273324
static_assert(SILExtInfoBuilder::NumMaskBits == NumSILExtInfoBits,
33283325
"ExtInfo and SILFunctionTypeBitfields must agree on bit size");
3329-
Bits.SILFunctionType.IsAsync = isAsync;
33303326
Bits.SILFunctionType.CoroutineKind = unsigned(coroutineKind);
33313327
NumParameters = params.size();
33323328
if (coroutineKind == SILCoroutineKind::None) {
@@ -3470,7 +3466,7 @@ CanSILBlockStorageType SILBlockStorageType::get(CanType captureType) {
34703466

34713467
CanSILFunctionType SILFunctionType::get(
34723468
GenericSignature genericSig,
3473-
ExtInfo ext, bool isAsync, SILCoroutineKind coroutineKind,
3469+
ExtInfo ext, SILCoroutineKind coroutineKind,
34743470
ParameterConvention callee,
34753471
ArrayRef<SILParameterInfo> params,
34763472
ArrayRef<SILYieldInfo> yields,
@@ -3488,8 +3484,8 @@ CanSILFunctionType SILFunctionType::get(
34883484
invocationSubs = invocationSubs.getCanonical();
34893485

34903486
llvm::FoldingSetNodeID id;
3491-
SILFunctionType::Profile(id, genericSig, ext, isAsync, coroutineKind, callee,
3492-
params, yields, normalResults, errorResult,
3487+
SILFunctionType::Profile(id, genericSig, ext, coroutineKind, callee, params,
3488+
yields, normalResults, errorResult,
34933489
witnessMethodConformance,
34943490
patternSubs, invocationSubs);
34953491

@@ -3537,7 +3533,7 @@ CanSILFunctionType SILFunctionType::get(
35373533
}
35383534

35393535
auto fnType =
3540-
new (mem) SILFunctionType(genericSig, ext, isAsync, coroutineKind, callee,
3536+
new (mem) SILFunctionType(genericSig, ext, coroutineKind, callee,
35413537
params, yields, normalResults, errorResult,
35423538
patternSubs, invocationSubs,
35433539
ctx, properties, witnessMethodConformance);

lib/AST/ASTDemangler.cpp

Lines changed: 2 additions & 3 deletions
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

@@ -558,8 +558,7 @@ Type ASTBuilder::createImplFunctionType(
558558
auto conv = getResultConvention(errorResult->getConvention());
559559
funcErrorResult.emplace(type, conv);
560560
}
561-
return SILFunctionType::get(genericSig, einfo,
562-
/*isAsync*/ false, funcCoroutineKind,
561+
return SILFunctionType::get(genericSig, einfo, funcCoroutineKind,
563562
funcCalleeConvention, funcParams, funcYields,
564563
funcResults, funcErrorResult,
565564
SubstitutionMap(), SubstitutionMap(), Ctx);

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41514151
if (info.isNoEscape()) {
41524152
Printer.printSimpleAttr("@noescape") << " ";
41534153
}
4154+
if (info.isAsync()) {
4155+
Printer.printSimpleAttr("@async") << " ";
4156+
}
41544157
}
41554158

41564159
void visitAnyFunctionTypeParams(ArrayRef<AnyFunctionType::Param> Params,
@@ -4295,7 +4298,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
42954298

42964299
void visitSILFunctionType(SILFunctionType *T) {
42974300
printSILCoroutineKind(T->getCoroutineKind());
4298-
printSILAsyncAttr(T->isAsync());
42994301
printFunctionExtInfo(T->getASTContext(), T->getExtInfo(),
43004302
T->getWitnessMethodConformanceOrInvalid());
43014303
printCalleeConvention(T->getCalleeConvention());

lib/AST/Type.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,6 @@ case TypeKind::Id:
43784378
return SILFunctionType::get(
43794379
fnTy->getInvocationGenericSignature(),
43804380
fnTy->getExtInfo(),
4381-
fnTy->isAsync(),
43824381
fnTy->getCoroutineKind(),
43834382
fnTy->getCalleeConvention(),
43844383
transInterfaceParams,
@@ -5372,7 +5371,7 @@ SILFunctionType::withInvocationSubstitutions(SubstitutionMap subs) const {
53725371
assert(!subs || CanGenericSignature(subs.getGenericSignature())
53735372
== getInvocationGenericSignature());
53745373
return SILFunctionType::get(getInvocationGenericSignature(),
5375-
getExtInfo(), isAsync(), getCoroutineKind(),
5374+
getExtInfo(), getCoroutineKind(),
53765375
getCalleeConvention(),
53775376
getParameters(), getYields(), getResults(),
53785377
getOptionalErrorResult(),
@@ -5390,7 +5389,7 @@ SILFunctionType::withPatternSubstitutions(SubstitutionMap subs) const {
53905389
assert(!subs || CanGenericSignature(subs.getGenericSignature())
53915390
== getPatternGenericSignature());
53925391
return SILFunctionType::get(getInvocationGenericSignature(),
5393-
getExtInfo(), isAsync(), getCoroutineKind(),
5392+
getExtInfo(), getCoroutineKind(),
53945393
getCalleeConvention(),
53955394
getParameters(), getYields(), getResults(),
53965395
getOptionalErrorResult(),
@@ -5409,7 +5408,7 @@ SILFunctionType::withPatternSpecialization(CanGenericSignature sig,
54095408
assert(!subs || CanGenericSignature(subs.getGenericSignature())
54105409
== getSubstGenericSignature());
54115410
return SILFunctionType::get(sig,
5412-
getExtInfo(), isAsync(), getCoroutineKind(),
5411+
getExtInfo(), getCoroutineKind(),
54135412
getCalleeConvention(),
54145413
getParameters(), getYields(), getResults(),
54155414
getOptionalErrorResult(),

lib/IRGen/GenProto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3056,7 +3056,7 @@ GenericTypeRequirements::GenericTypeRequirements(IRGenModule &IGM,
30563056
// Construct a representative function type.
30573057
auto generics = ncGenerics.getCanonicalSignature();
30583058
auto fnType = SILFunctionType::get(generics, SILFunctionType::ExtInfo(),
3059-
/*isAsync*/ false, SILCoroutineKind::None,
3059+
SILCoroutineKind::None,
30603060
/*callee*/ ParameterConvention::Direct_Unowned,
30613061
/*params*/ {}, /*yields*/ {},
30623062
/*results*/ {}, /*error*/ None,

lib/IRGen/LoadableByAddress.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ LargeSILTypeMapper::getNewSILFunctionType(GenericEnvironment *env,
297297
auto newFnType = SILFunctionType::get(
298298
fnType->getInvocationGenericSignature(),
299299
fnType->getExtInfo(),
300-
fnType->isAsync(),
301300
fnType->getCoroutineKind(),
302301
fnType->getCalleeConvention(),
303302
newParams,
@@ -2362,7 +2361,6 @@ static bool rewriteFunctionReturn(StructLoweringState &pass) {
23622361
auto NewTy = SILFunctionType::get(
23632362
loweredTy->getSubstGenericSignature(),
23642363
loweredTy->getExtInfo(),
2365-
loweredTy->isAsync(),
23662364
loweredTy->getCoroutineKind(),
23672365
loweredTy->getCalleeConvention(),
23682366
loweredTy->getParameters(),

lib/SIL/IR/SILBuilder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ SILType SILBuilder::getPartialApplyResultType(
107107

108108
auto appliedFnType = SILFunctionType::get(nullptr,
109109
extInfo,
110-
FTI->isAsync(),
111110
FTI->getCoroutineKind(),
112111
calleeConvention,
113112
newParams,

0 commit comments

Comments
 (0)