Skip to content

Commit 363dc4e

Browse files
Merge pull request #33554 from nate-chandler/move-flag-to-SILFunctionType-from-SILFunction
[SIL] Move from SILFunction to SILFunctionType flag for async.
2 parents 40ec380 + 9b88288 commit 363dc4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+169
-147
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ TYPE_ATTR(noescape)
5353
TYPE_ATTR(escaping)
5454
TYPE_ATTR(differentiable)
5555
TYPE_ATTR(noDerivative)
56+
TYPE_ATTR(async)
5657

5758
// SIL-specific attributes
5859
TYPE_ATTR(block_storage)

include/swift/AST/Types.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,12 @@ class alignas(1 << TypeAlignInBits) TypeBase {
362362
ID : 32
363363
);
364364

365-
SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+2+1+1,
365+
SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+1+2+1+1,
366366
ExtInfoBits : NumSILExtInfoBits,
367367
HasClangTypeInfo : 1,
368368
CalleeConvention : 3,
369369
HasErrorResult : 1,
370+
IsAsync : 1,
370371
CoroutineKind : 2,
371372
HasInvocationSubs : 1,
372373
HasPatternSubs : 1
@@ -3979,7 +3980,7 @@ class SILFunctionType final
39793980
+ 1);
39803981
}
39813982

3982-
SILFunctionType(GenericSignature genericSig, ExtInfo ext,
3983+
SILFunctionType(GenericSignature genericSig, ExtInfo ext, bool isAsync,
39833984
SILCoroutineKind coroutineKind,
39843985
ParameterConvention calleeConvention,
39853986
ArrayRef<SILParameterInfo> params,
@@ -3993,7 +3994,8 @@ class SILFunctionType final
39933994

39943995
public:
39953996
static CanSILFunctionType
3996-
get(GenericSignature genericSig, ExtInfo ext, SILCoroutineKind coroutineKind,
3997+
get(GenericSignature genericSig, ExtInfo ext, bool isAsync,
3998+
SILCoroutineKind coroutineKind,
39973999
ParameterConvention calleeConvention,
39984000
ArrayRef<SILParameterInfo> interfaceParams,
39994001
ArrayRef<SILYieldInfo> interfaceYields,
@@ -4046,6 +4048,8 @@ class SILFunctionType final
40464048
return SILCoroutineKind(Bits.SILFunctionType.CoroutineKind);
40474049
}
40484050

4051+
bool isAsync() const { return Bits.SILFunctionType.IsAsync; }
4052+
40494053
/// Return the array of all the yields.
40504054
ArrayRef<SILYieldInfo> getYields() const {
40514055
return const_cast<SILFunctionType *>(this)->getMutableYields();

include/swift/SIL/SILFunction.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@ class SILFunction
274274
/// that it may have unboxed capture (i.e. @inout_aliasable parameters).
275275
unsigned IsWithoutActuallyEscapingThunk : 1;
276276

277-
/// True if this function is an async function.
278-
unsigned IsAsync : 1;
279-
280277
/// If != OptimizationMode::NotSet, the optimization mode specified with an
281278
/// function attribute.
282279
unsigned OptMode : NumOptimizationModeBits;
@@ -504,9 +501,7 @@ class SILFunction
504501
IsWithoutActuallyEscapingThunk = val;
505502
}
506503

507-
bool isAsync() const { return IsAsync; }
508-
509-
void setAsync(bool val = true) { IsAsync = val; }
504+
bool isAsync() const { return LoweredType->isAsync(); }
510505

511506
/// Returns the calling convention used by this entry point.
512507
SILFunctionTypeRepresentation getRepresentation() const {

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,7 @@ void SILFunctionType::Profile(
32833283
SILFunctionType::SILFunctionType(
32843284
GenericSignature genericSig,
32853285
ExtInfo ext,
3286+
bool isAsync,
32863287
SILCoroutineKind coroutineKind,
32873288
ParameterConvention calleeConvention,
32883289
ArrayRef<SILParameterInfo> params,
@@ -3308,6 +3309,7 @@ SILFunctionType::SILFunctionType(
33083309
"Bits were dropped!");
33093310
static_assert(SILExtInfoBuilder::NumMaskBits == NumSILExtInfoBits,
33103311
"ExtInfo and SILFunctionTypeBitfields must agree on bit size");
3312+
Bits.SILFunctionType.IsAsync = isAsync;
33113313
Bits.SILFunctionType.CoroutineKind = unsigned(coroutineKind);
33123314
NumParameters = params.size();
33133315
if (coroutineKind == SILCoroutineKind::None) {
@@ -3451,7 +3453,7 @@ CanSILBlockStorageType SILBlockStorageType::get(CanType captureType) {
34513453

34523454
CanSILFunctionType SILFunctionType::get(
34533455
GenericSignature genericSig,
3454-
ExtInfo ext, SILCoroutineKind coroutineKind,
3456+
ExtInfo ext, bool isAsync, SILCoroutineKind coroutineKind,
34553457
ParameterConvention callee,
34563458
ArrayRef<SILParameterInfo> params,
34573459
ArrayRef<SILYieldInfo> yields,
@@ -3518,7 +3520,7 @@ CanSILFunctionType SILFunctionType::get(
35183520
}
35193521

35203522
auto fnType =
3521-
new (mem) SILFunctionType(genericSig, ext, coroutineKind, callee,
3523+
new (mem) SILFunctionType(genericSig, ext, isAsync, coroutineKind, callee,
35223524
params, yields, normalResults, errorResult,
35233525
patternSubs, invocationSubs,
35243526
ctx, properties, witnessMethodConformance);

lib/AST/ASTDemangler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ Type ASTBuilder::createImplFunctionType(
558558
auto conv = getResultConvention(errorResult->getConvention());
559559
funcErrorResult.emplace(type, conv);
560560
}
561-
return SILFunctionType::get(genericSig, einfo, funcCoroutineKind,
561+
return SILFunctionType::get(genericSig, einfo,
562+
/*isAsync*/ false, funcCoroutineKind,
562563
funcCalleeConvention, funcParams, funcYields,
563564
funcResults, funcErrorResult,
564565
SubstitutionMap(), SubstitutionMap(), Ctx);

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4249,6 +4249,12 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
42494249
llvm_unreachable("bad convention");
42504250
}
42514251

4252+
void printSILAsyncAttr(bool isAsync) {
4253+
if (isAsync) {
4254+
Printer << "@async ";
4255+
}
4256+
}
4257+
42524258
void printCalleeConvention(ParameterConvention conv) {
42534259
switch (conv) {
42544260
case ParameterConvention::Direct_Unowned:
@@ -4271,6 +4277,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
42714277

42724278
void visitSILFunctionType(SILFunctionType *T) {
42734279
printSILCoroutineKind(T->getCoroutineKind());
4280+
printSILAsyncAttr(T->isAsync());
42744281
printFunctionExtInfo(T->getASTContext(), T->getExtInfo(),
42754282
T->getWitnessMethodConformanceOrInvalid());
42764283
printCalleeConvention(T->getCalleeConvention());

lib/AST/Type.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4378,6 +4378,7 @@ case TypeKind::Id:
43784378
return SILFunctionType::get(
43794379
fnTy->getInvocationGenericSignature(),
43804380
fnTy->getExtInfo(),
4381+
fnTy->isAsync(),
43814382
fnTy->getCoroutineKind(),
43824383
fnTy->getCalleeConvention(),
43834384
transInterfaceParams,
@@ -5371,7 +5372,7 @@ SILFunctionType::withInvocationSubstitutions(SubstitutionMap subs) const {
53715372
assert(!subs || CanGenericSignature(subs.getGenericSignature())
53725373
== getInvocationGenericSignature());
53735374
return SILFunctionType::get(getInvocationGenericSignature(),
5374-
getExtInfo(), getCoroutineKind(),
5375+
getExtInfo(), isAsync(), getCoroutineKind(),
53755376
getCalleeConvention(),
53765377
getParameters(), getYields(), getResults(),
53775378
getOptionalErrorResult(),
@@ -5389,7 +5390,7 @@ SILFunctionType::withPatternSubstitutions(SubstitutionMap subs) const {
53895390
assert(!subs || CanGenericSignature(subs.getGenericSignature())
53905391
== getPatternGenericSignature());
53915392
return SILFunctionType::get(getInvocationGenericSignature(),
5392-
getExtInfo(), getCoroutineKind(),
5393+
getExtInfo(), isAsync(), getCoroutineKind(),
53935394
getCalleeConvention(),
53945395
getParameters(), getYields(), getResults(),
53955396
getOptionalErrorResult(),
@@ -5408,7 +5409,7 @@ SILFunctionType::withPatternSpecialization(CanGenericSignature sig,
54085409
assert(!subs || CanGenericSignature(subs.getGenericSignature())
54095410
== getSubstGenericSignature());
54105411
return SILFunctionType::get(sig,
5411-
getExtInfo(), getCoroutineKind(),
5412+
getExtInfo(), isAsync(), getCoroutineKind(),
54125413
getCalleeConvention(),
54135414
getParameters(), getYields(), getResults(),
54145415
getOptionalErrorResult(),

lib/AST/TypeRepr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ void AttributedTypeRepr::printAttrs(ASTPrinter &Printer,
171171
Printer.printStructurePost(PrintStructureKind::BuiltinAttribute);
172172
Printer << " ";
173173
}
174+
175+
if (hasAttr(TAK_async))
176+
Printer.printSimpleAttr("@async") << " ";
174177
}
175178

176179
IdentTypeRepr *IdentTypeRepr::create(ASTContext &C,

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-
SILCoroutineKind::None,
3059+
/*isAsync*/ false, SILCoroutineKind::None,
30603060
/*callee*/ ParameterConvention::Direct_Unowned,
30613061
/*params*/ {}, /*yields*/ {},
30623062
/*results*/ {}, /*error*/ None,

lib/IRGen/LoadableByAddress.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ LargeSILTypeMapper::getNewSILFunctionType(GenericEnvironment *env,
297297
auto newFnType = SILFunctionType::get(
298298
fnType->getInvocationGenericSignature(),
299299
fnType->getExtInfo(),
300+
fnType->isAsync(),
300301
fnType->getCoroutineKind(),
301302
fnType->getCalleeConvention(),
302303
newParams,
@@ -2361,6 +2362,7 @@ static bool rewriteFunctionReturn(StructLoweringState &pass) {
23612362
auto NewTy = SILFunctionType::get(
23622363
loweredTy->getSubstGenericSignature(),
23632364
loweredTy->getExtInfo(),
2365+
loweredTy->isAsync(),
23642366
loweredTy->getCoroutineKind(),
23652367
loweredTy->getCalleeConvention(),
23662368
loweredTy->getParameters(),

0 commit comments

Comments
 (0)