From 4145ef7a12e0330c93adf104cbebe7cba951b0ec Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Tue, 18 Aug 2020 12:20:53 -0700 Subject: [PATCH 1/2] Revert "[SIL] Add flag to SILFunction to indicate async." This reverts commit 6b28c2fe89614386b6835c9f1340a9df6152b1f5. --- include/swift/SIL/SILFunction.h | 7 ------- lib/SIL/IR/SILFunction.cpp | 2 +- lib/SIL/IR/SILFunctionBuilder.cpp | 4 ---- lib/SIL/IR/SILPrinter.cpp | 3 --- lib/SIL/Parser/ParseSIL.cpp | 24 +++++++++++------------- lib/Serialization/DeserializeSIL.cpp | 14 ++++---------- lib/Serialization/SILFormat.h | 1 - lib/Serialization/SerializeSIL.cpp | 2 +- test/SILGen/async.swift | 20 -------------------- 9 files changed, 17 insertions(+), 60 deletions(-) delete mode 100644 test/SILGen/async.swift diff --git a/include/swift/SIL/SILFunction.h b/include/swift/SIL/SILFunction.h index 8125736fc391f..ae3f940d21ad4 100644 --- a/include/swift/SIL/SILFunction.h +++ b/include/swift/SIL/SILFunction.h @@ -274,9 +274,6 @@ class SILFunction /// that it may have unboxed capture (i.e. @inout_aliasable parameters). unsigned IsWithoutActuallyEscapingThunk : 1; - /// True if this function is an async function. - unsigned IsAsync : 1; - /// If != OptimizationMode::NotSet, the optimization mode specified with an /// function attribute. unsigned OptMode : NumOptimizationModeBits; @@ -504,10 +501,6 @@ class SILFunction IsWithoutActuallyEscapingThunk = val; } - bool isAsync() const { return IsAsync; } - - void setAsync(bool val = true) { IsAsync = val; } - /// Returns the calling convention used by this entry point. SILFunctionTypeRepresentation getRepresentation() const { return getLoweredFunctionType()->getRepresentation(); diff --git a/lib/SIL/IR/SILFunction.cpp b/lib/SIL/IR/SILFunction.cpp index 8f4d425549d02..dd118be43c2ae 100644 --- a/lib/SIL/IR/SILFunction.cpp +++ b/lib/SIL/IR/SILFunction.cpp @@ -107,7 +107,7 @@ SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage, StringRef Name, ExactSelfClass(isExactSelfClass), Inlined(false), Zombie(false), HasOwnership(true), WasDeserializedCanonical(false), IsWithoutActuallyEscapingThunk(false), - IsAsync(false), OptMode(unsigned(OptimizationMode::NotSet)), + OptMode(unsigned(OptimizationMode::NotSet)), EffectsKindAttr(unsigned(E)) { assert(!Transparent || !IsDynamicReplaceable); validateSubclassScope(classSubclassScope, isThunk, nullptr); diff --git a/lib/SIL/IR/SILFunctionBuilder.cpp b/lib/SIL/IR/SILFunctionBuilder.cpp index c28ba05090b1b..b56d34ea74d00 100644 --- a/lib/SIL/IR/SILFunctionBuilder.cpp +++ b/lib/SIL/IR/SILFunctionBuilder.cpp @@ -217,10 +217,6 @@ SILFunction *SILFunctionBuilder::getOrCreateFunction( } addFunctionAttributes(F, decl->getAttrs(), mod, getOrCreateDeclaration, constant); - - if (auto *funcDecl = dyn_cast(decl)) { - F->setAsync(funcDecl->hasAsync()); - } } return F; diff --git a/lib/SIL/IR/SILPrinter.cpp b/lib/SIL/IR/SILPrinter.cpp index eed8fab9abf36..fe0f2dea86795 100644 --- a/lib/SIL/IR/SILPrinter.cpp +++ b/lib/SIL/IR/SILPrinter.cpp @@ -2598,9 +2598,6 @@ void SILFunction::print(SILPrintContext &PrintCtx) const { if (isWithoutActuallyEscapingThunk()) OS << "[without_actually_escaping] "; - if (isAsync()) - OS << "[async] "; - switch (getSpecialPurpose()) { case SILFunction::Purpose::None: break; diff --git a/lib/SIL/Parser/ParseSIL.cpp b/lib/SIL/Parser/ParseSIL.cpp index 00ceaf52ca02e..f70112cbcdaad 100644 --- a/lib/SIL/Parser/ParseSIL.cpp +++ b/lib/SIL/Parser/ParseSIL.cpp @@ -919,7 +919,6 @@ static bool parseDeclSILOptional(bool *isTransparent, bool *isWeakImported, AvailabilityContext *availability, bool *isWithoutActuallyEscapingThunk, - bool *isAsync, SmallVectorImpl *Semantics, SmallVectorImpl *SpecAttrs, ValueDecl **ClangDecl, @@ -958,8 +957,6 @@ static bool parseDeclSILOptional(bool *isTransparent, else if (isWithoutActuallyEscapingThunk && SP.P.Tok.getText() == "without_actually_escaping") *isWithoutActuallyEscapingThunk = true; - else if (isAsync && SP.P.Tok.getText() == "async") - *isAsync = true; else if (specialPurpose && SP.P.Tok.getText() == "global_init") *specialPurpose = SILFunction::Purpose::GlobalInit; else if (specialPurpose && SP.P.Tok.getText() == "lazy_getter") @@ -5682,7 +5679,6 @@ bool SILParserState::parseDeclSIL(Parser &P) { bool isWeakImported = false; AvailabilityContext availability = AvailabilityContext::alwaysAvailable(); bool isWithoutActuallyEscapingThunk = false; - bool isAsync = false; Inline_t inlineStrategy = InlineDefault; OptimizationMode optimizationMode = OptimizationMode::NotSet; SmallVector Semantics; @@ -5697,8 +5693,8 @@ bool SILParserState::parseDeclSIL(Parser &P) { &isThunk, &isDynamic, &isExactSelfClass, &DynamicallyReplacedFunction, &objCReplacementFor, &specialPurpose, &inlineStrategy, &optimizationMode, nullptr, &isWeakImported, &availability, - &isWithoutActuallyEscapingThunk, &isAsync, &Semantics, &SpecAttrs, - &ClangDecl, &MRK, FunctionState, M) || + &isWithoutActuallyEscapingThunk, &Semantics, + &SpecAttrs, &ClangDecl, &MRK, FunctionState, M) || P.parseToken(tok::at_sign, diag::expected_sil_function_name) || P.parseIdentifier(FnName, FnNameLoc, diag::expected_sil_function_name) || P.parseToken(tok::colon, diag::expected_sil_type)) @@ -5736,7 +5732,6 @@ bool SILParserState::parseDeclSIL(Parser &P) { FunctionState.F->setAvailabilityForLinkage(availability); FunctionState.F->setWithoutActuallyEscapingThunk( isWithoutActuallyEscapingThunk); - FunctionState.F->setAsync(isAsync); FunctionState.F->setInlineStrategy(inlineStrategy); FunctionState.F->setOptimizationMode(optimizationMode); FunctionState.F->setEffectsKind(MRK); @@ -5922,9 +5917,10 @@ bool SILParserState::parseSILGlobal(Parser &P) { SILParser State(P); if (parseSILLinkage(GlobalLinkage, P) || parseDeclSILOptional(nullptr, &isSerialized, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, &isLet, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, State, M) || + nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, + &isLet, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, nullptr, State, M) || P.parseToken(tok::at_sign, diag::expected_sil_value_name) || P.parseIdentifier(GlobalName, NameLoc, diag::expected_sil_value_name) || P.parseToken(tok::colon, diag::expected_sil_type)) @@ -5973,7 +5969,7 @@ bool SILParserState::parseSILProperty(Parser &P) { if (parseDeclSILOptional(nullptr, &Serialized, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, SP, M)) + nullptr, nullptr, nullptr, SP, M)) return true; ValueDecl *VD; @@ -6043,7 +6039,8 @@ bool SILParserState::parseSILVTable(Parser &P) { if (parseDeclSILOptional(nullptr, &Serialized, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, VTableState, M)) + nullptr, nullptr, nullptr, + VTableState, M)) return true; // Parse the class name. @@ -6579,7 +6576,8 @@ bool SILParserState::parseSILWitnessTable(Parser &P) { if (parseDeclSILOptional(nullptr, &isSerialized, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, WitnessState, M)) + nullptr, nullptr, nullptr, + WitnessState, M)) return true; Scope S(&P, ScopeKind::TopLevel); diff --git a/lib/Serialization/DeserializeSIL.cpp b/lib/Serialization/DeserializeSIL.cpp index d6524751b765f..b2cfae7bfd405 100644 --- a/lib/Serialization/DeserializeSIL.cpp +++ b/lib/Serialization/DeserializeSIL.cpp @@ -510,14 +510,14 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, IdentifierID replacedFunctionID; GenericSignatureID genericSigID; unsigned rawLinkage, isTransparent, isSerialized, isThunk, - isWithoutactuallyEscapingThunk, isAsync, specialPurpose, inlineStrategy, + isWithoutactuallyEscapingThunk, specialPurpose, inlineStrategy, optimizationMode, subclassScope, effect, numSpecAttrs, hasQualifiedOwnership, isWeakImported, LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass; ArrayRef SemanticsIDs; SILFunctionLayout::readRecord( scratch, rawLinkage, isTransparent, isSerialized, isThunk, - isWithoutactuallyEscapingThunk, isAsync, specialPurpose, inlineStrategy, + isWithoutactuallyEscapingThunk, specialPurpose, inlineStrategy, optimizationMode, subclassScope, effect, numSpecAttrs, hasQualifiedOwnership, isWeakImported, LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass, funcTyID, replacedFunctionID, genericSigID, @@ -625,11 +625,6 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, MF->fatal(); } - if (fn->isAsync() != isAsync) { - LLVM_DEBUG(llvm::dbgs() << "SILFunction type mismatch.\n"); - MF->fatal(); - } - } else { // Otherwise, create a new function. fn = builder.createDeclaration(name, ty, loc); @@ -638,7 +633,6 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn, fn->setSerialized(IsSerialized_t(isSerialized)); fn->setThunk(IsThunk_t(isThunk)); fn->setWithoutActuallyEscapingThunk(bool(isWithoutactuallyEscapingThunk)); - fn->setAsync((bool)isAsync); fn->setInlineStrategy(Inline_t(inlineStrategy)); fn->setSpecialPurpose(SILFunction::Purpose(specialPurpose)); fn->setEffectsKind(EffectsKind(effect)); @@ -2829,14 +2823,14 @@ bool SILDeserializer::hasSILFunction(StringRef Name, IdentifierID replacedFunctionID; GenericSignatureID genericSigID; unsigned rawLinkage, isTransparent, isSerialized, isThunk, - isWithoutactuallyEscapingThunk, isAsync, isGlobal, inlineStrategy, + isWithoutactuallyEscapingThunk, isGlobal, inlineStrategy, optimizationMode, subclassScope, effect, numSpecAttrs, hasQualifiedOwnership, isWeakImported, LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass; ArrayRef SemanticsIDs; SILFunctionLayout::readRecord( scratch, rawLinkage, isTransparent, isSerialized, isThunk, - isWithoutactuallyEscapingThunk, isAsync, isGlobal, inlineStrategy, + isWithoutactuallyEscapingThunk, isGlobal, inlineStrategy, optimizationMode, subclassScope, effect, numSpecAttrs, hasQualifiedOwnership, isWeakImported, LIST_VER_TUPLE_PIECES(available), isDynamic, isExactSelfClass, funcTyID, replacedFunctionID, genericSigID, diff --git a/lib/Serialization/SILFormat.h b/lib/Serialization/SILFormat.h index 1f572f01c127a..c1178d5f551ad 100644 --- a/lib/Serialization/SILFormat.h +++ b/lib/Serialization/SILFormat.h @@ -277,7 +277,6 @@ namespace sil_block { BCFixed<2>, // serialized BCFixed<2>, // thunks: signature optimized/reabstraction BCFixed<1>, // without_actually_escaping - BCFixed<1>, // async BCFixed<3>, // specialPurpose BCFixed<2>, // inlineStrategy BCFixed<2>, // optimizationMode diff --git a/lib/Serialization/SerializeSIL.cpp b/lib/Serialization/SerializeSIL.cpp index 74f658f3aaf6b..da46d36dd1b0a 100644 --- a/lib/Serialization/SerializeSIL.cpp +++ b/lib/Serialization/SerializeSIL.cpp @@ -433,7 +433,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) { Out, ScratchRecord, abbrCode, toStableSILLinkage(Linkage), (unsigned)F.isTransparent(), (unsigned)F.isSerialized(), (unsigned)F.isThunk(), (unsigned)F.isWithoutActuallyEscapingThunk(), - (unsigned)F.isAsync(), (unsigned)F.getSpecialPurpose(), + (unsigned)F.getSpecialPurpose(), (unsigned)F.getInlineStrategy(), (unsigned)F.getOptimizationMode(), (unsigned)F.getClassSubclassScope(), (unsigned)F.getEffectsKind(), (unsigned)numSpecAttrs, (unsigned)F.hasOwnership(), diff --git a/test/SILGen/async.swift b/test/SILGen/async.swift deleted file mode 100644 index 901978a7ac493..0000000000000 --- a/test/SILGen/async.swift +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: %target-swift-frontend -emit-silgen -enable-experimental-concurrency -module-name Async -Xllvm -sil-full-demangle -parse-as-library %s | %FileCheck %s - -import Swift - -// CHECK-LABEL: sil hidden [async] [ossa] @$s5Async04testA0yyYF : $@convention(thin) () -> () { -func testAsync() async {} -// CHECK-LABEL: sil hidden [async] [ossa] @$s5Async11testAsyncp1SiyYF : $@convention(thin) () -> Int { -func testAsyncp1() async -> Int { return 0 } - -// CHECK-LABEL: sil hidden [async] [ossa] @$s5Async5test2yyYKF : $@convention(thin) () -> @error Error { -func test2() async throws {} -// CHECK-LABEL: sil hidden [async] [ossa] @$s5Async7test2p1SiyYKF : $@convention(thin) () -> (Int, @error Error) { -func test2p1() async throws -> Int { return 0 } - -// CHECK-LABEL: sil hidden [async] [ossa] @$s5Async5test3yyyyKXEYKF : $@convention(thin) (@noescape @callee_guaranteed () -> @error Error) -> @error Error { -func test3(_ cl: () throws -> ()) async rethrows {} -// CHECK-LABEL: sil hidden [async] [ossa] @$s5Async7test3p1yS2iyKXEYKF : $@convention(thin) (@noescape @callee_guaranteed () -> (Int, @error Error)) -> (Int, @error Error) { -func test3p1(_ cl: () throws -> Int) async rethrows -> Int { return try cl() } - - From 9b8828848d3ed5a5ff90808146d008c94e3ac899 Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Mon, 17 Aug 2020 16:40:00 -0700 Subject: [PATCH 2/2] [SIL] Add SILFunctionType flag for async. --- include/swift/AST/Attr.def | 1 + include/swift/AST/Types.h | 10 ++-- include/swift/SIL/SILFunction.h | 2 + lib/AST/ASTContext.cpp | 6 ++- lib/AST/ASTDemangler.cpp | 3 +- lib/AST/ASTPrinter.cpp | 7 +++ lib/AST/Type.cpp | 7 +-- lib/AST/TypeRepr.cpp | 3 ++ lib/IRGen/GenProto.cpp | 2 +- lib/IRGen/LoadableByAddress.cpp | 2 + lib/SIL/IR/SILBuilder.cpp | 1 + lib/SIL/IR/SILFunctionType.cpp | 52 ++++++++++--------- lib/SIL/IR/SILType.cpp | 5 +- lib/SIL/Verifier/SILVerifier.cpp | 1 + lib/SILGen/SILGen.cpp | 4 +- lib/SILGen/SILGenBridging.cpp | 2 +- lib/SILGen/SILGenExpr.cpp | 6 ++- lib/SILGen/SILGenFunction.cpp | 4 +- lib/SILGen/SILGenPoly.cpp | 6 +-- .../Differentiation/JVPCloner.cpp | 8 +-- lib/SILOptimizer/Differentiation/Thunk.cpp | 6 +-- .../Differentiation/VJPCloner.cpp | 8 +-- .../ExistentialTransform.cpp | 2 +- .../FunctionSignatureOpts.cpp | 9 ++-- lib/SILOptimizer/IPO/CapturePromotion.cpp | 5 +- lib/SILOptimizer/IPO/ClosureSpecializer.cpp | 2 +- .../Mandatory/Differentiation.cpp | 11 ++-- .../Transforms/AllocBoxToStack.cpp | 5 +- lib/SILOptimizer/Transforms/Outliner.cpp | 4 +- .../UtilityPasses/BugReducerTester.cpp | 3 +- lib/SILOptimizer/Utils/Generics.cpp | 11 ++-- lib/Sema/TypeCheckType.cpp | 18 +++++-- lib/Serialization/Deserialization.cpp | 5 +- lib/Serialization/ModuleFormat.h | 3 +- lib/Serialization/Serialization.cpp | 2 +- test/SIL/Parser/async.sil | 11 +++- test/SIL/Serialization/basic.sil | 4 +- 37 files changed, 153 insertions(+), 88 deletions(-) diff --git a/include/swift/AST/Attr.def b/include/swift/AST/Attr.def index 660128379a139..2c744e4c0769a 100644 --- a/include/swift/AST/Attr.def +++ b/include/swift/AST/Attr.def @@ -53,6 +53,7 @@ TYPE_ATTR(noescape) TYPE_ATTR(escaping) TYPE_ATTR(differentiable) TYPE_ATTR(noDerivative) +TYPE_ATTR(async) // SIL-specific attributes TYPE_ATTR(block_storage) diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 0f911f4fb5ae4..e3fbbd4e742c2 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -362,11 +362,12 @@ class alignas(1 << TypeAlignInBits) TypeBase { ID : 32 ); - SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+2+1+1, + SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+1+2+1+1, ExtInfoBits : NumSILExtInfoBits, HasClangTypeInfo : 1, CalleeConvention : 3, HasErrorResult : 1, + IsAsync : 1, CoroutineKind : 2, HasInvocationSubs : 1, HasPatternSubs : 1 @@ -3979,7 +3980,7 @@ class SILFunctionType final + 1); } - SILFunctionType(GenericSignature genericSig, ExtInfo ext, + SILFunctionType(GenericSignature genericSig, ExtInfo ext, bool isAsync, SILCoroutineKind coroutineKind, ParameterConvention calleeConvention, ArrayRef params, @@ -3993,7 +3994,8 @@ class SILFunctionType final public: static CanSILFunctionType - get(GenericSignature genericSig, ExtInfo ext, SILCoroutineKind coroutineKind, + get(GenericSignature genericSig, ExtInfo ext, bool isAsync, + SILCoroutineKind coroutineKind, ParameterConvention calleeConvention, ArrayRef interfaceParams, ArrayRef interfaceYields, @@ -4046,6 +4048,8 @@ class SILFunctionType final return SILCoroutineKind(Bits.SILFunctionType.CoroutineKind); } + bool isAsync() const { return Bits.SILFunctionType.IsAsync; } + /// Return the array of all the yields. ArrayRef getYields() const { return const_cast(this)->getMutableYields(); diff --git a/include/swift/SIL/SILFunction.h b/include/swift/SIL/SILFunction.h index ae3f940d21ad4..5297539e43494 100644 --- a/include/swift/SIL/SILFunction.h +++ b/include/swift/SIL/SILFunction.h @@ -501,6 +501,8 @@ class SILFunction IsWithoutActuallyEscapingThunk = val; } + bool isAsync() const { return LoweredType->isAsync(); } + /// Returns the calling convention used by this entry point. SILFunctionTypeRepresentation getRepresentation() const { return getLoweredFunctionType()->getRepresentation(); diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 830aed2cfe57a..ef19cd4d46b31 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3283,6 +3283,7 @@ void SILFunctionType::Profile( SILFunctionType::SILFunctionType( GenericSignature genericSig, ExtInfo ext, + bool isAsync, SILCoroutineKind coroutineKind, ParameterConvention calleeConvention, ArrayRef params, @@ -3308,6 +3309,7 @@ SILFunctionType::SILFunctionType( "Bits were dropped!"); static_assert(SILExtInfoBuilder::NumMaskBits == NumSILExtInfoBits, "ExtInfo and SILFunctionTypeBitfields must agree on bit size"); + Bits.SILFunctionType.IsAsync = isAsync; Bits.SILFunctionType.CoroutineKind = unsigned(coroutineKind); NumParameters = params.size(); if (coroutineKind == SILCoroutineKind::None) { @@ -3451,7 +3453,7 @@ CanSILBlockStorageType SILBlockStorageType::get(CanType captureType) { CanSILFunctionType SILFunctionType::get( GenericSignature genericSig, - ExtInfo ext, SILCoroutineKind coroutineKind, + ExtInfo ext, bool isAsync, SILCoroutineKind coroutineKind, ParameterConvention callee, ArrayRef params, ArrayRef yields, @@ -3518,7 +3520,7 @@ CanSILFunctionType SILFunctionType::get( } auto fnType = - new (mem) SILFunctionType(genericSig, ext, coroutineKind, callee, + new (mem) SILFunctionType(genericSig, ext, isAsync, coroutineKind, callee, params, yields, normalResults, errorResult, patternSubs, invocationSubs, ctx, properties, witnessMethodConformance); diff --git a/lib/AST/ASTDemangler.cpp b/lib/AST/ASTDemangler.cpp index 44d32c84a7a7d..6e44fd70da0ef 100644 --- a/lib/AST/ASTDemangler.cpp +++ b/lib/AST/ASTDemangler.cpp @@ -558,7 +558,8 @@ Type ASTBuilder::createImplFunctionType( auto conv = getResultConvention(errorResult->getConvention()); funcErrorResult.emplace(type, conv); } - return SILFunctionType::get(genericSig, einfo, funcCoroutineKind, + return SILFunctionType::get(genericSig, einfo, + /*isAsync*/ false, funcCoroutineKind, funcCalleeConvention, funcParams, funcYields, funcResults, funcErrorResult, SubstitutionMap(), SubstitutionMap(), Ctx); diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 9423bf8506aa3..ed03d9a2c35c0 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -4249,6 +4249,12 @@ class TypePrinter : public TypeVisitor { llvm_unreachable("bad convention"); } + void printSILAsyncAttr(bool isAsync) { + if (isAsync) { + Printer << "@async "; + } + } + void printCalleeConvention(ParameterConvention conv) { switch (conv) { case ParameterConvention::Direct_Unowned: @@ -4271,6 +4277,7 @@ class TypePrinter : public TypeVisitor { void visitSILFunctionType(SILFunctionType *T) { printSILCoroutineKind(T->getCoroutineKind()); + printSILAsyncAttr(T->isAsync()); printFunctionExtInfo(T->getASTContext(), T->getExtInfo(), T->getWitnessMethodConformanceOrInvalid()); printCalleeConvention(T->getCalleeConvention()); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index f26c9e39182af..bc7d9b780b659 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -4378,6 +4378,7 @@ case TypeKind::Id: return SILFunctionType::get( fnTy->getInvocationGenericSignature(), fnTy->getExtInfo(), + fnTy->isAsync(), fnTy->getCoroutineKind(), fnTy->getCalleeConvention(), transInterfaceParams, @@ -5371,7 +5372,7 @@ SILFunctionType::withInvocationSubstitutions(SubstitutionMap subs) const { assert(!subs || CanGenericSignature(subs.getGenericSignature()) == getInvocationGenericSignature()); return SILFunctionType::get(getInvocationGenericSignature(), - getExtInfo(), getCoroutineKind(), + getExtInfo(), isAsync(), getCoroutineKind(), getCalleeConvention(), getParameters(), getYields(), getResults(), getOptionalErrorResult(), @@ -5389,7 +5390,7 @@ SILFunctionType::withPatternSubstitutions(SubstitutionMap subs) const { assert(!subs || CanGenericSignature(subs.getGenericSignature()) == getPatternGenericSignature()); return SILFunctionType::get(getInvocationGenericSignature(), - getExtInfo(), getCoroutineKind(), + getExtInfo(), isAsync(), getCoroutineKind(), getCalleeConvention(), getParameters(), getYields(), getResults(), getOptionalErrorResult(), @@ -5408,7 +5409,7 @@ SILFunctionType::withPatternSpecialization(CanGenericSignature sig, assert(!subs || CanGenericSignature(subs.getGenericSignature()) == getSubstGenericSignature()); return SILFunctionType::get(sig, - getExtInfo(), getCoroutineKind(), + getExtInfo(), isAsync(), getCoroutineKind(), getCalleeConvention(), getParameters(), getYields(), getResults(), getOptionalErrorResult(), diff --git a/lib/AST/TypeRepr.cpp b/lib/AST/TypeRepr.cpp index bb7e6e65f74e5..6490258e3b922 100644 --- a/lib/AST/TypeRepr.cpp +++ b/lib/AST/TypeRepr.cpp @@ -171,6 +171,9 @@ void AttributedTypeRepr::printAttrs(ASTPrinter &Printer, Printer.printStructurePost(PrintStructureKind::BuiltinAttribute); Printer << " "; } + + if (hasAttr(TAK_async)) + Printer.printSimpleAttr("@async") << " "; } IdentTypeRepr *IdentTypeRepr::create(ASTContext &C, diff --git a/lib/IRGen/GenProto.cpp b/lib/IRGen/GenProto.cpp index 2795553485a5a..6282e402545c8 100644 --- a/lib/IRGen/GenProto.cpp +++ b/lib/IRGen/GenProto.cpp @@ -3056,7 +3056,7 @@ GenericTypeRequirements::GenericTypeRequirements(IRGenModule &IGM, // Construct a representative function type. auto generics = ncGenerics.getCanonicalSignature(); auto fnType = SILFunctionType::get(generics, SILFunctionType::ExtInfo(), - SILCoroutineKind::None, + /*isAsync*/ false, SILCoroutineKind::None, /*callee*/ ParameterConvention::Direct_Unowned, /*params*/ {}, /*yields*/ {}, /*results*/ {}, /*error*/ None, diff --git a/lib/IRGen/LoadableByAddress.cpp b/lib/IRGen/LoadableByAddress.cpp index 2a509cbfeeb89..6d798d7ea8131 100644 --- a/lib/IRGen/LoadableByAddress.cpp +++ b/lib/IRGen/LoadableByAddress.cpp @@ -297,6 +297,7 @@ LargeSILTypeMapper::getNewSILFunctionType(GenericEnvironment *env, auto newFnType = SILFunctionType::get( fnType->getInvocationGenericSignature(), fnType->getExtInfo(), + fnType->isAsync(), fnType->getCoroutineKind(), fnType->getCalleeConvention(), newParams, @@ -2361,6 +2362,7 @@ static bool rewriteFunctionReturn(StructLoweringState &pass) { auto NewTy = SILFunctionType::get( loweredTy->getSubstGenericSignature(), loweredTy->getExtInfo(), + loweredTy->isAsync(), loweredTy->getCoroutineKind(), loweredTy->getCalleeConvention(), loweredTy->getParameters(), diff --git a/lib/SIL/IR/SILBuilder.cpp b/lib/SIL/IR/SILBuilder.cpp index c925cc83bb737..d6a876037c0b9 100644 --- a/lib/SIL/IR/SILBuilder.cpp +++ b/lib/SIL/IR/SILBuilder.cpp @@ -107,6 +107,7 @@ SILType SILBuilder::getPartialApplyResultType( auto appliedFnType = SILFunctionType::get(nullptr, extInfo, + FTI->isAsync(), FTI->getCoroutineKind(), calleeConvention, newParams, diff --git a/lib/SIL/IR/SILFunctionType.cpp b/lib/SIL/IR/SILFunctionType.cpp index 2d3e10054313d..0e50bdd34f8e4 100644 --- a/lib/SIL/IR/SILFunctionType.cpp +++ b/lib/SIL/IR/SILFunctionType.cpp @@ -94,6 +94,7 @@ CanSILFunctionType SILFunctionType::getUnsubstitutedType(SILModule &M) const { : CanGenericSignature(); return SILFunctionType::get(signature, getExtInfo(), + isAsync(), getCoroutineKind(), getCalleeConvention(), params, yields, results, errorResult, @@ -287,11 +288,11 @@ SILFunctionType::getWithDifferentiability(DifferentiabilityKind kind, } auto newExtInfo = getExtInfo().intoBuilder().withDifferentiabilityKind(kind).build(); - return get(getInvocationGenericSignature(), newExtInfo, getCoroutineKind(), - getCalleeConvention(), newParameters, getYields(), newResults, - getOptionalErrorResult(), getPatternSubstitutions(), - getInvocationSubstitutions(), getASTContext(), - getWitnessMethodConformanceOrInvalid()); + return get(getInvocationGenericSignature(), newExtInfo, isAsync(), + getCoroutineKind(), getCalleeConvention(), newParameters, + getYields(), newResults, getOptionalErrorResult(), + getPatternSubstitutions(), getInvocationSubstitutions(), + getASTContext(), getWitnessMethodConformanceOrInvalid()); } CanSILFunctionType SILFunctionType::getWithoutDifferentiability() { @@ -311,9 +312,9 @@ CanSILFunctionType SILFunctionType::getWithoutDifferentiability() { newResults.push_back(result.getWithDifferentiability( SILResultDifferentiability::DifferentiableOrNotApplicable)); return SILFunctionType::get( - getInvocationGenericSignature(), nondiffExtInfo, getCoroutineKind(), - getCalleeConvention(), newParams, getYields(), newResults, - getOptionalErrorResult(), getPatternSubstitutions(), + getInvocationGenericSignature(), nondiffExtInfo, isAsync(), + getCoroutineKind(), getCalleeConvention(), newParams, getYields(), + newResults, getOptionalErrorResult(), getPatternSubstitutions(), getInvocationSubstitutions(), getASTContext()); } @@ -502,9 +503,9 @@ static CanSILFunctionType getAutoDiffDifferentialType( llvm::makeArrayRef(substConformances)); } return SILFunctionType::get( - GenericSignature(), SILFunctionType::ExtInfo(), SILCoroutineKind::None, - ParameterConvention::Direct_Guaranteed, differentialParams, {}, - differentialResults, None, substitutions, + GenericSignature(), SILFunctionType::ExtInfo(), /*isAsync*/ false, + SILCoroutineKind::None, ParameterConvention::Direct_Guaranteed, + differentialParams, {}, differentialResults, None, substitutions, /*invocationSubstitutions*/ SubstitutionMap(), ctx); } @@ -681,9 +682,9 @@ static CanSILFunctionType getAutoDiffPullbackType( llvm::makeArrayRef(substConformances)); } return SILFunctionType::get( - GenericSignature(), SILFunctionType::ExtInfo(), SILCoroutineKind::None, - ParameterConvention::Direct_Guaranteed, pullbackParams, {}, - pullbackResults, None, substitutions, + GenericSignature(), SILFunctionType::ExtInfo(), /*isAsync*/ false, + SILCoroutineKind::None, ParameterConvention::Direct_Guaranteed, + pullbackParams, {}, pullbackResults, None, substitutions, /*invocationSubstitutions*/ SubstitutionMap(), ctx); } @@ -737,7 +738,7 @@ static SILFunctionType *getConstrainedAutoDiffOriginalFunctionType( constrainedInvocationGenSig->areAllParamsConcrete() ? GenericSignature() : constrainedInvocationGenSig, - original->getExtInfo(), original->getCoroutineKind(), + original->getExtInfo(), original->isAsync(), original->getCoroutineKind(), original->getCalleeConvention(), newParameters, original->getYields(), newResults, original->getOptionalErrorResult(), /*patternSubstitutions*/ SubstitutionMap(), @@ -828,6 +829,7 @@ CanSILFunctionType SILFunctionType::getAutoDiffDerivativeFunctionType( // cache and return. cachedResult = SILFunctionType::get( constrainedOriginalFnTy->getSubstGenericSignature(), extInfo, + constrainedOriginalFnTy->isAsync(), constrainedOriginalFnTy->getCoroutineKind(), constrainedOriginalFnTy->getCalleeConvention(), newParameters, constrainedOriginalFnTy->getYields(), newResults, @@ -913,9 +915,9 @@ CanSILFunctionType SILFunctionType::getAutoDiffTransposeFunctionType( for (auto &res : getResults()) newParameters.push_back(getParameterInfoForOriginalResult(res)); return SILFunctionType::get( - getInvocationGenericSignature(), getExtInfo(), getCoroutineKind(), - getCalleeConvention(), newParameters, getYields(), newResults, - getOptionalErrorResult(), getPatternSubstitutions(), + getInvocationGenericSignature(), getExtInfo(), isAsync(), + getCoroutineKind(), getCalleeConvention(), newParameters, getYields(), + newResults, getOptionalErrorResult(), getPatternSubstitutions(), /*invocationSubstitutions*/ {}, getASTContext()); } @@ -989,7 +991,8 @@ Lowering::adjustFunctionType(CanSILFunctionType type, return type; return SILFunctionType::get(type->getInvocationGenericSignature(), - extInfo, type->getCoroutineKind(), callee, + extInfo, type->isAsync(), + type->getCoroutineKind(), callee, type->getParameters(), type->getYields(), type->getResults(), type->getOptionalErrorResult(), @@ -1016,9 +1019,9 @@ CanSILFunctionType SILFunctionType::getWithExtInfo(ExtInfo newExt) { : Lowering::DefaultThickCalleeConvention) : ParameterConvention::Direct_Unowned); - return get(getInvocationGenericSignature(), newExt, getCoroutineKind(), - calleeConvention, getParameters(), getYields(), getResults(), - getOptionalErrorResult(), getPatternSubstitutions(), + return get(getInvocationGenericSignature(), newExt, isAsync(), + getCoroutineKind(), calleeConvention, getParameters(), getYields(), + getResults(), getOptionalErrorResult(), getPatternSubstitutions(), getInvocationSubstitutions(), getASTContext(), getWitnessMethodConformanceOrInvalid()); } @@ -2166,7 +2169,8 @@ static CanSILFunctionType getSILFunctionType( } } - return SILFunctionType::get(genericSig, silExtInfo, coroutineKind, + return SILFunctionType::get(genericSig, silExtInfo, + substFnInterfaceType->isAsync(), coroutineKind, calleeConvention, inputs, yields, results, errorResult, substitutions, SubstitutionMap(), @@ -3756,7 +3760,7 @@ class SILTypeSubstituter : ? origType->getInvocationGenericSignature() : nullptr; - return SILFunctionType::get(genericSig, extInfo, + return SILFunctionType::get(genericSig, extInfo, origType->isAsync(), origType->getCoroutineKind(), origType->getCalleeConvention(), substParams, substYields, substResults, substErrorResult, diff --git a/lib/SIL/IR/SILType.cpp b/lib/SIL/IR/SILType.cpp index 48ca1e5cbc47d..28f323ccf8769 100644 --- a/lib/SIL/IR/SILType.cpp +++ b/lib/SIL/IR/SILType.cpp @@ -671,9 +671,10 @@ TypeBase::replaceSubstitutedSILFunctionTypesWithUnsubstituted(SILModule &M) cons if (!didChange) return sft; - + return SILFunctionType::get(sft->getInvocationGenericSignature(), - sft->getExtInfo(), sft->getCoroutineKind(), + sft->getExtInfo(), sft->isAsync(), + sft->getCoroutineKind(), sft->getCalleeConvention(), newParams, newYields, newResults, newErrorResult, diff --git a/lib/SIL/Verifier/SILVerifier.cpp b/lib/SIL/Verifier/SILVerifier.cpp index c2f3de4038027..3f27e20fe801d 100644 --- a/lib/SIL/Verifier/SILVerifier.cpp +++ b/lib/SIL/Verifier/SILVerifier.cpp @@ -3003,6 +3003,7 @@ class SILVerifier : public SILVerifierBase { auto fnTy = SILFunctionType::get(nullptr, methodTy->getExtInfo(), + methodTy->isAsync(), methodTy->getCoroutineKind(), methodTy->getCalleeConvention(), dynParams, diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index cd36b343f0e58..dffd4c3b8dfdf 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -419,7 +419,7 @@ SILGenModule::getKeyPathProjectionCoroutine(bool isReadAccess, /*clangFunctionType*/ nullptr) .build(); - auto functionTy = SILFunctionType::get(sig, extInfo, + auto functionTy = SILFunctionType::get(sig, extInfo, /*isAsync*/ false, SILCoroutineKind::YieldOnce, ParameterConvention::Direct_Unowned, params, @@ -482,7 +482,7 @@ SILFunction *SILGenModule::emitTopLevelFunction(SILLocation Loc) { }; CanSILFunctionType topLevelType = SILFunctionType::get(nullptr, extInfo, - SILCoroutineKind::None, + /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, params, /*yields*/ {}, SILResultInfo(Int32Ty, diff --git a/lib/SILGen/SILGenBridging.cpp b/lib/SILGen/SILGenBridging.cpp index 7eedc3b1975fa..a013d5b188baa 100644 --- a/lib/SILGen/SILGenBridging.cpp +++ b/lib/SILGen/SILGenBridging.cpp @@ -578,7 +578,7 @@ ManagedValue SILGenFunction::emitFuncToBlock(SILLocation loc, } auto invokeTy = SILFunctionType::get( - genericSig, extInfo, SILCoroutineKind::None, + genericSig, extInfo, /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, params, /*yields*/ {}, blockInterfaceTy->getResults(), blockInterfaceTy->getOptionalErrorResult(), diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index cb8273d129e1e..8ef8f36c118ee 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -2750,6 +2750,7 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM, return SILFunctionType::get(genericSig, SILFunctionType::ExtInfo::getThin(), + /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, params, {}, result, None, @@ -2896,9 +2897,10 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM, params.push_back({C.getUnsafeRawPointerDecl()->getDeclaredInterfaceType() ->getCanonicalType(), ParameterConvention::Direct_Unowned}); - + return SILFunctionType::get(genericSig, SILFunctionType::ExtInfo::getThin(), + /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, params, {}, {}, None, @@ -3081,6 +3083,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM, auto signature = SILFunctionType::get(genericSig, SILFunctionType::ExtInfo::getThin(), + /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, params, /*yields*/ {}, results, None, @@ -3255,6 +3258,7 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM, auto signature = SILFunctionType::get(genericSig, SILFunctionType::ExtInfo::getThin(), + /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, params, /*yields*/ {}, results, None, diff --git a/lib/SILGen/SILGenFunction.cpp b/lib/SILGen/SILGenFunction.cpp index d9acdc516f6ac..7f6cf2516db66 100644 --- a/lib/SILGen/SILGenFunction.cpp +++ b/lib/SILGen/SILGenFunction.cpp @@ -602,6 +602,7 @@ void SILGenFunction::emitArtificialTopLevel(Decl *mainDecl) { SILFunctionType::ExtInfo() .withRepresentation(SILFunctionType::Representation:: CFunctionPointer), + /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, SILParameterInfo(anyObjectMetaTy, @@ -697,7 +698,8 @@ void SILGenFunction::emitArtificialTopLevel(Decl *mainDecl) { // has an overlay to fix the type of argv. .withRepresentation(SILFunctionType::Representation::Thin) .build(), - SILCoroutineKind::None, ParameterConvention::Direct_Unowned, argTypes, + /*isAsync*/ false, SILCoroutineKind::None, + ParameterConvention::Direct_Unowned, argTypes, /*yields*/ {}, SILResultInfo(argc->getType().getASTType(), ResultConvention::Unowned), /*error result*/ None, SubstitutionMap(), SubstitutionMap(), diff --git a/lib/SILGen/SILGenPoly.cpp b/lib/SILGen/SILGenPoly.cpp index 0ee11d74f6439..110edd25ba171 100644 --- a/lib/SILGen/SILGenPoly.cpp +++ b/lib/SILGen/SILGenPoly.cpp @@ -3245,9 +3245,9 @@ CanSILFunctionType SILGenFunction::buildThunkType( // The type of the thunk function. return SILFunctionType::get( - genericSig, extInfoBuilder.build(), expectedType->getCoroutineKind(), - ParameterConvention::Direct_Unowned, interfaceParams, interfaceYields, - interfaceResults, interfaceErrorResult, + genericSig, extInfoBuilder.build(), expectedType->isAsync(), + expectedType->getCoroutineKind(), ParameterConvention::Direct_Unowned, + interfaceParams, interfaceYields, interfaceResults, interfaceErrorResult, expectedType->getPatternSubstitutions(), SubstitutionMap(), getASTContext()); } diff --git a/lib/SILOptimizer/Differentiation/JVPCloner.cpp b/lib/SILOptimizer/Differentiation/JVPCloner.cpp index 8152f409d7592..b6df19215ba4d 100644 --- a/lib/SILOptimizer/Differentiation/JVPCloner.cpp +++ b/lib/SILOptimizer/Differentiation/JVPCloner.cpp @@ -1587,10 +1587,10 @@ void JVPCloner::Implementation::prepareForDifferentialGeneration() { auto *diffGenericEnv = diffGenericSig ? diffGenericSig->getGenericEnvironment() : nullptr; auto diffType = SILFunctionType::get( - diffGenericSig, origTy->getExtInfo(), origTy->getCoroutineKind(), - origTy->getCalleeConvention(), dfParams, {}, dfResults, None, - origTy->getPatternSubstitutions(), origTy->getInvocationSubstitutions(), - original->getASTContext()); + diffGenericSig, origTy->getExtInfo(), origTy->isAsync(), + origTy->getCoroutineKind(), origTy->getCalleeConvention(), dfParams, {}, + dfResults, None, origTy->getPatternSubstitutions(), + origTy->getInvocationSubstitutions(), original->getASTContext()); SILOptFunctionBuilder fb(context.getTransform()); auto linkage = jvp->isSerialized() ? SILLinkage::Public : SILLinkage::Hidden; diff --git a/lib/SILOptimizer/Differentiation/Thunk.cpp b/lib/SILOptimizer/Differentiation/Thunk.cpp index 820805fff06d9..bd1817c6f3994 100644 --- a/lib/SILOptimizer/Differentiation/Thunk.cpp +++ b/lib/SILOptimizer/Differentiation/Thunk.cpp @@ -242,9 +242,9 @@ CanSILFunctionType buildThunkType(SILFunction *fn, // The type of the thunk function. return SILFunctionType::get( - genericSig, extInfoBuilder.build(), expectedType->getCoroutineKind(), - ParameterConvention::Direct_Unowned, interfaceParams, interfaceYields, - interfaceResults, interfaceErrorResult, + genericSig, extInfoBuilder.build(), expectedType->isAsync(), + expectedType->getCoroutineKind(), ParameterConvention::Direct_Unowned, + interfaceParams, interfaceYields, interfaceResults, interfaceErrorResult, expectedType->getPatternSubstitutions(), SubstitutionMap(), fn->getASTContext()); } diff --git a/lib/SILOptimizer/Differentiation/VJPCloner.cpp b/lib/SILOptimizer/Differentiation/VJPCloner.cpp index 186173e025bc3..c3037cdb76693 100644 --- a/lib/SILOptimizer/Differentiation/VJPCloner.cpp +++ b/lib/SILOptimizer/Differentiation/VJPCloner.cpp @@ -893,10 +893,10 @@ SILFunction *VJPCloner::Implementation::createEmptyPullback() { auto *pbGenericEnv = pbGenericSig ? pbGenericSig->getGenericEnvironment() : nullptr; auto pbType = SILFunctionType::get( - pbGenericSig, origTy->getExtInfo(), origTy->getCoroutineKind(), - origTy->getCalleeConvention(), pbParams, {}, adjResults, None, - origTy->getPatternSubstitutions(), origTy->getInvocationSubstitutions(), - original->getASTContext()); + pbGenericSig, origTy->getExtInfo(), origTy->isAsync(), + origTy->getCoroutineKind(), origTy->getCalleeConvention(), pbParams, {}, + adjResults, None, origTy->getPatternSubstitutions(), + origTy->getInvocationSubstitutions(), original->getASTContext()); SILOptFunctionBuilder fb(context.getTransform()); auto linkage = vjp->isSerialized() ? SILLinkage::Public : SILLinkage::Private; diff --git a/lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp b/lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp index 66617c63b0c24..839810a36223d 100644 --- a/lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp +++ b/lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp @@ -403,7 +403,7 @@ ExistentialTransform::createExistentialSpecializedFunctionType() { /// Return the new signature. return SILFunctionType::get( - NewGenericSig, ExtInfo, FTy->getCoroutineKind(), + NewGenericSig, ExtInfo, FTy->isAsync(), FTy->getCoroutineKind(), FTy->getCalleeConvention(), InterfaceParams, FTy->getYields(), FTy->getResults(), InterfaceErrorResult, SubstitutionMap(), SubstitutionMap(), diff --git a/lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp b/lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp index 7d1f34ea07cc4..328f55ab17ee9 100644 --- a/lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp +++ b/lib/SILOptimizer/FunctionSignatureTransforms/FunctionSignatureOpts.cpp @@ -408,10 +408,11 @@ FunctionSignatureTransformDescriptor::createOptimizedSILFunctionType() { UsesGenerics ? FTy->getInvocationGenericSignature() : nullptr; return SILFunctionType::get( - GenericSig, ExtInfo, FTy->getCoroutineKind(), FTy->getCalleeConvention(), - InterfaceParams, InterfaceYields, InterfaceResults, InterfaceErrorResult, - FTy->getPatternSubstitutions(), SubstitutionMap(), - F->getModule().getASTContext(), witnessMethodConformance); + GenericSig, ExtInfo, FTy->isAsync(), FTy->getCoroutineKind(), + FTy->getCalleeConvention(), InterfaceParams, InterfaceYields, + InterfaceResults, InterfaceErrorResult, FTy->getPatternSubstitutions(), + SubstitutionMap(), F->getModule().getASTContext(), + witnessMethodConformance); } /// Compute what the function interface will look like based on the diff --git a/lib/SILOptimizer/IPO/CapturePromotion.cpp b/lib/SILOptimizer/IPO/CapturePromotion.cpp index 37533fef306fc..ee4f6badc8505 100644 --- a/lib/SILOptimizer/IPO/CapturePromotion.cpp +++ b/lib/SILOptimizer/IPO/CapturePromotion.cpp @@ -428,8 +428,9 @@ ClosureCloner::initCloned(SILOptFunctionBuilder &FunctionBuilder, // Create the thin function type for the cloned closure. auto ClonedTy = SILFunctionType::get( OrigFTI->getInvocationGenericSignature(), OrigFTI->getExtInfo(), - OrigFTI->getCoroutineKind(), OrigFTI->getCalleeConvention(), - ClonedInterfaceArgTys, OrigFTI->getYields(), OrigFTI->getResults(), + OrigFTI->isAsync(), OrigFTI->getCoroutineKind(), + OrigFTI->getCalleeConvention(), ClonedInterfaceArgTys, + OrigFTI->getYields(), OrigFTI->getResults(), OrigFTI->getOptionalErrorResult(), SubstitutionMap(), SubstitutionMap(), M.getASTContext(), OrigFTI->getWitnessMethodConformanceOrInvalid()); diff --git a/lib/SILOptimizer/IPO/ClosureSpecializer.cpp b/lib/SILOptimizer/IPO/ClosureSpecializer.cpp index 05ab7bcaf6f10..137054e99ec18 100644 --- a/lib/SILOptimizer/IPO/ClosureSpecializer.cpp +++ b/lib/SILOptimizer/IPO/ClosureSpecializer.cpp @@ -670,7 +670,7 @@ ClosureSpecCloner::initCloned(SILOptFunctionBuilder &FunctionBuilder, auto ClonedTy = SILFunctionType::get( ClosureUserFunTy->getInvocationGenericSignature(), ExtInfo, - ClosureUserFunTy->getCoroutineKind(), + ClosureUserFunTy->isAsync(), ClosureUserFunTy->getCoroutineKind(), ClosureUserFunTy->getCalleeConvention(), NewParameterInfoList, ClosureUserFunTy->getYields(), ClosureUserFunTy->getResults(), ClosureUserFunTy->getOptionalErrorResult(), diff --git a/lib/SILOptimizer/Mandatory/Differentiation.cpp b/lib/SILOptimizer/Mandatory/Differentiation.cpp index 083f840e892e7..a2e60703933bf 100644 --- a/lib/SILOptimizer/Mandatory/Differentiation.cpp +++ b/lib/SILOptimizer/Mandatory/Differentiation.cpp @@ -872,7 +872,8 @@ static void emitFatalError(ADContext &context, SILFunction *f, // Fatal error function must have type `@convention(thin) () -> Never`. auto fatalErrorFnType = SILFunctionType::get( /*genericSig*/ nullptr, SILFunctionType::ExtInfo::getThin(), - SILCoroutineKind::None, ParameterConvention::Direct_Unowned, {}, + /*isAsync*/ false, SILCoroutineKind::None, + ParameterConvention::Direct_Unowned, {}, /*interfaceYields*/ {}, neverResultInfo, /*interfaceErrorResults*/ None, {}, {}, context.getASTContext()); auto fnBuilder = SILOptFunctionBuilder(context.getTransform()); @@ -1024,10 +1025,10 @@ static SILValue promoteCurryThunkApplicationToDifferentiableFunction( auto newThunkResult = thunkResult.getWithInterfaceType(diffResultFnTy); auto thunkType = SILFunctionType::get( thunkTy->getSubstGenericSignature(), thunkTy->getExtInfo(), - thunkTy->getCoroutineKind(), thunkTy->getCalleeConvention(), - thunkTy->getParameters(), {}, {newThunkResult}, {}, - thunkTy->getPatternSubstitutions(), thunkTy->getInvocationSubstitutions(), - thunkTy->getASTContext()); + thunkTy->isAsync(), thunkTy->getCoroutineKind(), + thunkTy->getCalleeConvention(), thunkTy->getParameters(), {}, + {newThunkResult}, {}, thunkTy->getPatternSubstitutions(), + thunkTy->getInvocationSubstitutions(), thunkTy->getASTContext()); // Construct new curry thunk, returning a `@differentiable` function. SILOptFunctionBuilder fb(dt.getTransform()); diff --git a/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp b/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp index 6483b47a12a6f..93571944f8312 100644 --- a/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp +++ b/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp @@ -699,8 +699,9 @@ SILFunction *PromotedParamCloner::initCloned(SILOptFunctionBuilder &FuncBuilder, // the parameters promoted. auto ClonedTy = SILFunctionType::get( OrigFTI->getInvocationGenericSignature(), OrigFTI->getExtInfo(), - OrigFTI->getCoroutineKind(), OrigFTI->getCalleeConvention(), - ClonedInterfaceArgTys, OrigFTI->getYields(), OrigFTI->getResults(), + OrigFTI->isAsync(), OrigFTI->getCoroutineKind(), + OrigFTI->getCalleeConvention(), ClonedInterfaceArgTys, + OrigFTI->getYields(), OrigFTI->getResults(), OrigFTI->getOptionalErrorResult(), OrigFTI->getPatternSubstitutions(), OrigFTI->getInvocationSubstitutions(), M.getASTContext(), OrigFTI->getWitnessMethodConformanceOrInvalid()); diff --git a/lib/SILOptimizer/Transforms/Outliner.cpp b/lib/SILOptimizer/Transforms/Outliner.cpp index e052a6b000f3c..4426205c94ff0 100644 --- a/lib/SILOptimizer/Transforms/Outliner.cpp +++ b/lib/SILOptimizer/Transforms/Outliner.cpp @@ -302,7 +302,7 @@ CanSILFunctionType BridgedProperty::getOutlinedFunctionType(SILModule &M) { /*clangFunctionType*/ nullptr) .build(); auto FunctionType = SILFunctionType::get( - nullptr, ExtInfo, SILCoroutineKind::None, + nullptr, ExtInfo, /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, Parameters, /*yields*/ {}, Results, None, SubstitutionMap(), SubstitutionMap(), @@ -1203,7 +1203,7 @@ CanSILFunctionType ObjCMethodCall::getOutlinedFunctionType(SILModule &M) { SILResultInfo(BridgedReturn.getReturnType(), ResultConvention::Owned)); } auto FunctionType = SILFunctionType::get( - nullptr, ExtInfo, SILCoroutineKind::None, + nullptr, ExtInfo, /*isAsync*/ false, SILCoroutineKind::None, ParameterConvention::Direct_Unowned, Parameters, {}, Results, None, SubstitutionMap(), SubstitutionMap(), diff --git a/lib/SILOptimizer/UtilityPasses/BugReducerTester.cpp b/lib/SILOptimizer/UtilityPasses/BugReducerTester.cpp index a8f823e584d5a..3ec8f130c3496 100644 --- a/lib/SILOptimizer/UtilityPasses/BugReducerTester.cpp +++ b/lib/SILOptimizer/UtilityPasses/BugReducerTester.cpp @@ -89,7 +89,8 @@ class BugReducerTester : public SILFunctionTransform { false /*noescape*/, DifferentiabilityKind::NonDifferentiable, nullptr /*clangFunctionType*/) .build(), - SILCoroutineKind::None, ParameterConvention::Direct_Unowned, + /*isAsync*/ false, SILCoroutineKind::None, + ParameterConvention::Direct_Unowned, ArrayRef(), ArrayRef(), ResultInfoArray, None, SubstitutionMap(), SubstitutionMap(), getFunction()->getModule().getASTContext()); diff --git a/lib/SILOptimizer/Utils/Generics.cpp b/lib/SILOptimizer/Utils/Generics.cpp index 2bde614efd66c..39dfd0c59c28f 100644 --- a/lib/SILOptimizer/Utils/Generics.cpp +++ b/lib/SILOptimizer/Utils/Generics.cpp @@ -785,10 +785,11 @@ ReabstractionInfo::createSubstitutedType(SILFunction *OrigF, // Use the new specialized generic signature. auto NewFnTy = SILFunctionType::get( - CanSpecializedGenericSig, FnTy->getExtInfo(), FnTy->getCoroutineKind(), - FnTy->getCalleeConvention(), FnTy->getParameters(), FnTy->getYields(), - FnTy->getResults(), FnTy->getOptionalErrorResult(), - FnTy->getPatternSubstitutions(), SubstitutionMap(), M.getASTContext(), + CanSpecializedGenericSig, FnTy->getExtInfo(), FnTy->isAsync(), + FnTy->getCoroutineKind(), FnTy->getCalleeConvention(), + FnTy->getParameters(), FnTy->getYields(), FnTy->getResults(), + FnTy->getOptionalErrorResult(), FnTy->getPatternSubstitutions(), + SubstitutionMap(), M.getASTContext(), FnTy->getWitnessMethodConformanceOrInvalid()); // This is an interface type. It should not have any archetypes. @@ -856,7 +857,7 @@ createSpecializedType(CanSILFunctionType SubstFTy, SILModule &M) const { ? SubstFTy->getInvocationGenericSignature() : CanGenericSignature(); return SILFunctionType::get( - Signature, SubstFTy->getExtInfo(), + Signature, SubstFTy->getExtInfo(), SubstFTy->isAsync(), SubstFTy->getCoroutineKind(), SubstFTy->getCalleeConvention(), SpecializedParams, SpecializedYields, SpecializedResults, SubstFTy->getOptionalErrorResult(), SubstitutionMap(), SubstitutionMap(), diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index 2cd63edbe1563..864d2b926adb9 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -1749,6 +1749,7 @@ namespace { Type resolveSILFunctionType(FunctionTypeRepr *repr, TypeResolutionOptions options, + bool isAsync = false, SILCoroutineKind coroutineKind = SILCoroutineKind::None, SILFunctionType::ExtInfo extInfo @@ -2078,7 +2079,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs, static const TypeAttrKind FunctionAttrs[] = { TAK_convention, TAK_pseudogeneric, TAK_callee_owned, TAK_callee_guaranteed, TAK_noescape, TAK_autoclosure, - TAK_differentiable, TAK_escaping, TAK_yield_once, TAK_yield_many + TAK_differentiable, TAK_escaping, TAK_yield_once, TAK_yield_many, TAK_async }; auto checkUnsupportedAttr = [&](TypeAttrKind attr) { @@ -2146,6 +2147,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs, SILFunctionType::Representation rep; TypeRepr *witnessMethodProtocol = nullptr; + auto isAsync = attrs.has(TAK_async); + auto coroutineKind = SILCoroutineKind::None; if (attrs.has(TAK_yield_once)) { coroutineKind = SILCoroutineKind::YieldOnce; @@ -2227,7 +2230,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs, attrs.has(TAK_noescape), diffKind, nullptr) .build(); - ty = resolveSILFunctionType(fnRepr, options, coroutineKind, extInfo, + ty = resolveSILFunctionType(fnRepr, options, isAsync, coroutineKind, extInfo, calleeConvention, witnessMethodProtocol); if (!ty || ty->hasError()) return ty; @@ -2470,6 +2473,13 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs, attrs.clearAttribute(TAK_dynamic_self); } + // In SIL *only*, allow @async to specify an async function + if ((options & TypeResolutionFlags::SILMode) && attrs.has(TAK_async)) { + if (fnRepr != nullptr) { + attrs.clearAttribute(TAK_async); + } + } + for (unsigned i = 0; i != TypeAttrKind::TAK_Count; ++i) if (attrs.has((TypeAttrKind)i)) { diagnoseInvalid(repr, attrs.getLoc((TypeAttrKind)i), @@ -2835,6 +2845,7 @@ Type TypeResolver::resolveSILBoxType(SILBoxTypeRepr *repr, Type TypeResolver::resolveSILFunctionType(FunctionTypeRepr *repr, TypeResolutionOptions options, + bool isAsync, SILCoroutineKind coroutineKind, SILFunctionType::ExtInfo extInfo, ParameterConvention callee, @@ -3029,7 +3040,8 @@ Type TypeResolver::resolveSILFunctionType(FunctionTypeRepr *repr, "found witness_method without matching conformance"); } - return SILFunctionType::get(genericSig, extInfo, coroutineKind, callee, + return SILFunctionType::get(genericSig, extInfo, isAsync, + coroutineKind, callee, interfaceParams, interfaceYields, interfaceResults, interfaceErrorResult, interfacePatternSubs, invocationSubs, diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index ec8645447d5b3..f56c3cad967e2 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -5355,6 +5355,7 @@ class TypeDeserializer { Expected deserializeSILFunctionType(ArrayRef scratch, StringRef blobData) { + bool async; uint8_t rawCoroutineKind; uint8_t rawCalleeConvention; uint8_t rawRepresentation; @@ -5372,6 +5373,7 @@ class TypeDeserializer { ClangTypeID clangFunctionTypeID; decls_block::SILFunctionTypeLayout::readRecord(scratch, + async, rawCoroutineKind, rawCalleeConvention, rawRepresentation, @@ -5561,7 +5563,8 @@ class TypeDeserializer { if (!patternSubsOrErr) return patternSubsOrErr.takeError(); - return SILFunctionType::get(invocationSig, extInfo, coroutineKind.getValue(), + return SILFunctionType::get(invocationSig, extInfo, + async, coroutineKind.getValue(), calleeConvention.getValue(), allParams, allYields, allResults, errorResult, diff --git a/lib/Serialization/ModuleFormat.h b/lib/Serialization/ModuleFormat.h index 7a8364d7852c1..0c6bc3f61564e 100644 --- a/lib/Serialization/ModuleFormat.h +++ b/lib/Serialization/ModuleFormat.h @@ -55,7 +55,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0; /// describe what change you made. The content of this comment isn't important; /// it just ensures a conflict if two people change the module format. /// Don't worry about adhering to the 80-column limit for this line. -const uint16_t SWIFTMODULE_VERSION_MINOR = 572; // revert isUserAccessible +const uint16_t SWIFTMODULE_VERSION_MINOR = 573; // @async on SILFunctionType /// A standard hash seed used for all string hashes in a serialized module. /// @@ -1049,6 +1049,7 @@ namespace decls_block { using SILFunctionTypeLayout = BCRecordLayout< SIL_FUNCTION_TYPE, + BCFixed<1>, // async? SILCoroutineKindField, // coroutine kind ParameterConventionField, // callee convention SILFunctionTypeRepresentationField, // representation diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 8c5cd273a7e3b..4e099c13de728 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -4232,7 +4232,7 @@ class Serializer::TypeSerializer : public TypeVisitor { unsigned abbrCode = S.DeclTypeAbbrCodes[SILFunctionTypeLayout::Code]; SILFunctionTypeLayout::emitRecord( S.Out, S.ScratchRecord, abbrCode, - stableCoroutineKind, stableCalleeConvention, + fnTy->isAsync(), stableCoroutineKind, stableCalleeConvention, stableRepresentation, fnTy->isPseudogeneric(), fnTy->isNoEscape(), stableDiffKind, fnTy->hasErrorResult(), fnTy->getParameters().size(), fnTy->getNumYields(), fnTy->getNumResults(), diff --git a/test/SIL/Parser/async.sil b/test/SIL/Parser/async.sil index 694f66de78175..374572412f494 100644 --- a/test/SIL/Parser/async.sil +++ b/test/SIL/Parser/async.sil @@ -1,8 +1,15 @@ // RUN: %target-sil-opt -enable-sil-verify-all=true %s | %target-sil-opt -enable-sil-verify-all=true | %FileCheck %s -// CHECK: sil [async] @async_test -sil [async] @async_test : $() -> () { +// CHECK: sil @async_test : $@async +sil @async_test : $@async () -> () { bb0: %0 = tuple () return %0 : $() } + +// CHECK: sil @take_async : $@convention(thin) (@async () -> ()) -> () +sil @take_async : $(@async () -> ()) -> () { +bb0(%fn : $@async () -> ()): + %0 = tuple () + return %0 : $() +} diff --git a/test/SIL/Serialization/basic.sil b/test/SIL/Serialization/basic.sil index dd7f9ba3a54d4..1d9f1de1a810e 100644 --- a/test/SIL/Serialization/basic.sil +++ b/test/SIL/Serialization/basic.sil @@ -15,8 +15,8 @@ bb0(%0 : @guaranteed $Builtin.NativeObject): return undef : $() } -// CHECK-LABEL: sil [async] @async_test -sil [async] @async_test : $() -> () { +// CHECK-LABEL: sil @async_test : $@async @convention(thin) +sil @async_test : $@async () -> () { bb0: %0 = tuple () return %0 : $()