diff --git a/include/swift/Driver/Action.h b/include/swift/Driver/Action.h index b2d6ed1a2c5..f4f15b8affe 100644 --- a/include/swift/Driver/Action.h +++ b/include/swift/Driver/Action.h @@ -127,7 +127,7 @@ public: } }; -class CompileJobAction : public JobAction { +class IncrementalJobAction : public JobAction { public: struct InputInfo { enum Status { @@ -136,6 +136,8 @@ public: NeedsNonCascadingBuild, NewlyAdded }; + + public: Status status = UpToDate; llvm::sys::TimePoint<> previousModTime; @@ -153,18 +155,32 @@ private: InputInfo inputInfo; public: - CompileJobAction(file_types::ID OutputType) - : JobAction(Action::Kind::CompileJob, None, OutputType), - inputInfo() {} - - CompileJobAction(Action *Input, file_types::ID OutputType, InputInfo info) - : JobAction(Action::Kind::CompileJob, Input, OutputType), - inputInfo(info) {} + IncrementalJobAction(Kind Kind, ArrayRef Inputs, + file_types::ID Type, InputInfo info) + : JobAction(Kind, Inputs, Type), inputInfo(info) {} +public: InputInfo getInputInfo() const { return inputInfo; } +public: + static bool classof(const Action *A) { + return A->getKind() == Action::Kind::CompileJob; + } +}; + +class CompileJobAction : public IncrementalJobAction { +private: + virtual void anchor() override; + +public: + CompileJobAction(file_types::ID OutputType) + : IncrementalJobAction(Action::Kind::CompileJob, None, OutputType, {}) {} + CompileJobAction(Action *Input, file_types::ID OutputType, InputInfo info) + : IncrementalJobAction(Action::Kind::CompileJob, Input, OutputType, + info) {} + static bool classof(const Action *A) { return A->getKind() == Action::Kind::CompileJob; } diff --git a/lib/Driver/Action.cpp b/lib/Driver/Action.cpp index 25117800eed..27f0d9306d9 100644 --- a/lib/Driver/Action.cpp +++ b/lib/Driver/Action.cpp @@ -43,6 +43,8 @@ void InputAction::anchor() {} void JobAction::anchor() {} +void IncrementalJobAction::anchor() {} + void CompileJobAction::anchor() {} void InterpretJobAction::anchor() {} diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index c373d401a25..503c88c0ffb 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -860,7 +860,7 @@ namespace driver { computeFirstRoundCompileJobsForIncrementalCompilation(); for (const Job *Cmd : Comp.getJobs()) { - if (Cmd->getFirstSwiftPrimaryInput().empty() || + if (!isa(Cmd->getSource()) || compileJobsToSchedule.count(Cmd)) { scheduleCommandIfNecessaryAndPossible(Cmd); noteBuilding(Cmd, /*willBeBuilding*/ true, /*isTentative=*/false, @@ -899,20 +899,22 @@ namespace driver { CommandSet computeDependenciesAndGetNeededCompileJobs(const bool forRanges) { auto getEveryCompileJob = [&] { - CommandSet everyCompileJob; + CommandSet everyIncrementalJob; for (const Job *Cmd : Comp.getJobs()) { - if (!Cmd->getFirstSwiftPrimaryInput().empty()) - everyCompileJob.insert(Cmd); + if (isa(Cmd->getSource())) + everyIncrementalJob.insert(Cmd); } - return everyCompileJob; + return everyIncrementalJob; }; CommandSet jobsToSchedule; CommandSet initialCascadingCommands; for (const Job *cmd : Comp.getJobs()) { - const StringRef primary = cmd->getFirstSwiftPrimaryInput(); - if (primary.empty()) - continue; // not Compile + // Skip jobs that have no associated incremental info. + if (!isa(cmd->getSource())) { + continue; + } + const Optional> shouldSchedAndIsCascading = computeShouldInitiallyScheduleJobAndDependendents(cmd, forRanges); if (!shouldSchedAndIsCascading) diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 562b70c47dd..2a8394b0327 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -181,6 +181,28 @@ AsyncContextLayout irgen::getAsyncContextLayout( paramInfos.push_back({ty, parameter.getConvention()}); } + Optional trailingWitnessInfo; + if (originalType->getRepresentation() == + SILFunctionTypeRepresentation::WitnessMethod) { + assert(getTrailingWitnessSignatureLength(IGF.IGM, originalType) == 2); + + // First, the Self metadata. + { + auto ty = SILType(); + auto &ti = IGF.IGM.getTypeMetadataPtrTypeInfo(); + valTypes.push_back(ty); + typeInfos.push_back(&ti); + } + // Then, the Self witness table. + { + auto ty = SILType(); + auto &ti = IGF.IGM.getWitnessTablePtrTypeInfo(); + valTypes.push_back(ty); + typeInfos.push_back(&ti); + } + trailingWitnessInfo = AsyncContextLayout::TrailingWitnessInfo(); + } + // ResultTypes directResults...; auto directResults = fnConv.getDirectSILResults(); for (auto result : directResults) { @@ -192,11 +214,11 @@ AsyncContextLayout irgen::getAsyncContextLayout( directReturnInfos.push_back(result); } - return AsyncContextLayout(IGF.IGM, LayoutStrategy::Optimal, valTypes, - typeInfos, IGF, originalType, substitutedType, - substitutionMap, std::move(bindings), errorType, - canHaveValidError, paramInfos, indirectReturnInfos, - directReturnInfos, localContextInfo); + return AsyncContextLayout( + IGF.IGM, LayoutStrategy::Optimal, valTypes, typeInfos, IGF, originalType, + substitutedType, substitutionMap, std::move(bindings), + trailingWitnessInfo, errorType, canHaveValidError, paramInfos, + indirectReturnInfos, directReturnInfos, localContextInfo); } AsyncContextLayout::AsyncContextLayout( @@ -204,8 +226,8 @@ AsyncContextLayout::AsyncContextLayout( ArrayRef fieldTypeInfos, IRGenFunction &IGF, CanSILFunctionType originalType, CanSILFunctionType substitutedType, SubstitutionMap substitutionMap, NecessaryBindings &&bindings, - SILType errorType, bool canHaveValidError, - ArrayRef argumentInfos, + Optional trailingWitnessInfo, SILType errorType, + bool canHaveValidError, ArrayRef argumentInfos, ArrayRef indirectReturnInfos, ArrayRef directReturnInfos, Optional localContextInfo) @@ -218,6 +240,7 @@ AsyncContextLayout::AsyncContextLayout( indirectReturnInfos(indirectReturnInfos.begin(), indirectReturnInfos.end()), localContextInfo(localContextInfo), bindings(std::move(bindings)), + trailingWitnessInfo(trailingWitnessInfo), argumentInfos(argumentInfos.begin(), argumentInfos.end()) { #ifndef NDEBUG assert(fieldTypeInfos.size() == fieldTypes.size() && @@ -1931,6 +1954,17 @@ class AsyncCallEmission final : public CallEmission { getCallee().getSubstitutions()); } + void saveValue(ElementLayout layout, Explosion &explosion, bool isOutlined) { + Address addr = layout.project(IGF, context, /*offsets*/ llvm::None); + auto &ti = cast(layout.getType()); + ti.initialize(IGF, explosion, addr, isOutlined); + } + void loadValue(ElementLayout layout, Explosion &explosion) { + Address addr = layout.project(IGF, context, /*offsets*/ llvm::None); + auto &ti = layout.getType(); + cast(ti).loadAsTake(IGF, addr, explosion); + } + public: AsyncCallEmission(IRGenFunction &IGF, llvm::Value *selfValue, Callee &&callee) : CallEmission(IGF, selfValue, std::move(callee)) { @@ -1976,21 +2010,15 @@ public: llArgs.add(selfValue); } auto layout = getAsyncContextLayout(); - for (unsigned index = 0, count = layout.getArgumentCount(); index < count; - ++index) { - auto fieldLayout = layout.getArgumentLayout(index); - Address fieldAddr = - fieldLayout.project(IGF, context, /*offsets*/ llvm::None); - auto &ti = cast(fieldLayout.getType()); - ti.initialize(IGF, llArgs, fieldAddr, isOutlined); - } for (unsigned index = 0, count = layout.getIndirectReturnCount(); index < count; ++index) { auto fieldLayout = layout.getIndirectReturnLayout(index); - Address fieldAddr = - fieldLayout.project(IGF, context, /*offsets*/ llvm::None); - cast(fieldLayout.getType()) - .initialize(IGF, llArgs, fieldAddr, isOutlined); + saveValue(fieldLayout, llArgs, isOutlined); + } + for (unsigned index = 0, count = layout.getArgumentCount(); index < count; + ++index) { + auto fieldLayout = layout.getArgumentLayout(index); + saveValue(fieldLayout, llArgs, isOutlined); } if (layout.hasBindings()) { auto bindingLayout = layout.getBindingsLayout(); @@ -1999,10 +2027,7 @@ public: } if (selfValue) { auto fieldLayout = layout.getLocalContextLayout(); - Address fieldAddr = - fieldLayout.project(IGF, context, /*offsets*/ llvm::None); - auto &ti = cast(fieldLayout.getType()); - ti.initialize(IGF, llArgs, fieldAddr, isOutlined); + saveValue(fieldLayout, llArgs, isOutlined); } } void emitCallToUnmappedExplosion(llvm::CallInst *call, Explosion &out) override { @@ -2018,20 +2043,13 @@ public: // argument buffer. return; } - assert(call->arg_size() == 1); - auto context = call->arg_begin()->get(); // Gather the values. Explosion nativeExplosion; auto layout = getAsyncContextLayout(); - auto dataAddr = layout.emitCastTo(IGF, context); for (unsigned index = 0, count = layout.getDirectReturnCount(); index < count; ++index) { auto fieldLayout = layout.getDirectReturnLayout(index); - Address fieldAddr = - fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None); - auto &fieldTI = fieldLayout.getType(); - cast(fieldTI).loadAsTake(IGF, fieldAddr, - nativeExplosion); + loadValue(fieldLayout, nativeExplosion); } out = nativeSchema.mapFromNative(IGF.IGM, IGF, nativeExplosion, resultType); diff --git a/lib/IRGen/GenCall.h b/lib/IRGen/GenCall.h index 91e440d7925..893e5f5eeae 100644 --- a/lib/IRGen/GenCall.h +++ b/lib/IRGen/GenCall.h @@ -89,6 +89,7 @@ namespace irgen { SILType type; ParameterConvention convention; }; + struct TrailingWitnessInfo {}; private: enum class FixedIndex : unsigned { @@ -107,28 +108,59 @@ namespace irgen { SmallVector indirectReturnInfos; Optional localContextInfo; NecessaryBindings bindings; + Optional trailingWitnessInfo; SmallVector argumentInfos; + unsigned getErrorIndex() { return (unsigned)FixedIndex::Error; } + unsigned getFirstIndirectReturnIndex() { + return getErrorIndex() + getErrorCount(); + } + unsigned getLocalContextIndex() { + assert(hasLocalContext()); + return getFirstIndirectReturnIndex() + getIndirectReturnCount(); + } + unsigned getIndexAfterLocalContext() { + return getFirstIndirectReturnIndex() + getIndirectReturnCount() + + (hasLocalContext() ? 1 : 0); + } + unsigned getBindingsIndex() { + assert(hasBindings()); + return getIndexAfterLocalContext(); + } + unsigned getIndexAfterBindings() { + return getIndexAfterLocalContext() + (hasBindings() ? 1 : 0); + } + unsigned getFirstArgumentIndex() { return getIndexAfterBindings(); } + unsigned getIndexAfterArguments() { + return getFirstArgumentIndex() + getArgumentCount(); + } + unsigned getSelfMetadataIndex() { + assert(hasTrailingWitnesses()); + return getIndexAfterArguments(); + } + unsigned getSelfWitnessTableIndex() { + assert(hasTrailingWitnesses()); + return getIndexAfterArguments() + 1; + } + unsigned getIndexAfterTrailingWitnesses() { + return getIndexAfterArguments() + (hasTrailingWitnesses() ? 2 : 0); + } + unsigned getFirstDirectReturnIndex() { + return getIndexAfterTrailingWitnesses(); + } + public: bool canHaveError() { return canHaveValidError; } - unsigned getErrorIndex() { return (unsigned)FixedIndex::Error; } ElementLayout getErrorLayout() { return getElement(getErrorIndex()); } unsigned getErrorCount() { return (unsigned)FixedCount::Error; } SILType getErrorType() { return errorType; } - unsigned getFirstIndirectReturnIndex() { - return getErrorIndex() + getErrorCount(); - } ElementLayout getIndirectReturnLayout(unsigned index) { return getElement(getFirstIndirectReturnIndex() + index); } unsigned getIndirectReturnCount() { return indirectReturnInfos.size(); } bool hasLocalContext() { return (bool)localContextInfo; } - unsigned getLocalContextIndex() { - assert(hasLocalContext()); - return getFirstIndirectReturnIndex() + getIndirectReturnCount(); - } ElementLayout getLocalContextLayout() { assert(hasLocalContext()); return getElement(getLocalContextIndex()); @@ -141,65 +173,53 @@ namespace irgen { assert(hasLocalContext()); return localContextInfo->type; } - unsigned getIndexAfterLocalContext() { - return getFirstIndirectReturnIndex() + getIndirectReturnCount() + - (hasLocalContext() ? 1 : 0); - } bool hasBindings() const { return !bindings.empty(); } - unsigned getBindingsIndex() { - assert(hasBindings()); - return getIndexAfterLocalContext(); - } ElementLayout getBindingsLayout() { assert(hasBindings()); return getElement(getBindingsIndex()); } - ParameterConvention getBindingsConvention() { - return ParameterConvention::Direct_Unowned; - } const NecessaryBindings &getBindings() const { return bindings; } - unsigned getFirstArgumentIndex() { - return getIndexAfterLocalContext() + (hasBindings() ? 1 : 0); - } ElementLayout getArgumentLayout(unsigned index) { return getElement(getFirstArgumentIndex() + index); } - ParameterConvention getArgumentConvention(unsigned index) { - return argumentInfos[index].convention; - } SILType getArgumentType(unsigned index) { return argumentInfos[index].type; } + // Returns the type of a parameter of the substituted function using the + // indexing of the function parameters, *not* the indexing of + // AsyncContextLayout. SILType getParameterType(unsigned index) { SILFunctionConventions origConv(substitutedType, IGF.getSILModule()); return origConv.getSILArgumentType( index, IGF.IGM.getMaximalTypeExpansionContext()); } unsigned getArgumentCount() { return argumentInfos.size(); } - unsigned getIndexAfterArguments() { - return getFirstArgumentIndex() + getArgumentCount(); + bool hasTrailingWitnesses() { return (bool)trailingWitnessInfo; } + ElementLayout getSelfMetadataLayout() { + assert(hasTrailingWitnesses()); + return getElement(getSelfMetadataIndex()); + } + ElementLayout getSelfWitnessTableLayout() { + return getElement(getSelfWitnessTableIndex()); } - unsigned getFirstDirectReturnIndex() { return getIndexAfterArguments(); } unsigned getDirectReturnCount() { return directReturnInfos.size(); } ElementLayout getDirectReturnLayout(unsigned index) { return getElement(getFirstDirectReturnIndex() + index); } - AsyncContextLayout(IRGenModule &IGM, LayoutStrategy strategy, - ArrayRef fieldTypes, - ArrayRef fieldTypeInfos, - IRGenFunction &IGF, CanSILFunctionType originalType, - CanSILFunctionType substitutedType, - SubstitutionMap substitutionMap, - NecessaryBindings &&bindings, SILType errorType, - bool canHaveValidError, - ArrayRef argumentInfos, - ArrayRef directReturnInfos, - ArrayRef indirectReturnInfos, - Optional localContextInfo); + AsyncContextLayout( + IRGenModule &IGM, LayoutStrategy strategy, ArrayRef fieldTypes, + ArrayRef fieldTypeInfos, IRGenFunction &IGF, + CanSILFunctionType originalType, CanSILFunctionType substitutedType, + SubstitutionMap substitutionMap, NecessaryBindings &&bindings, + Optional trailingWitnessInfo, SILType errorType, + bool canHaveValidError, ArrayRef argumentInfos, + ArrayRef directReturnInfos, + ArrayRef indirectReturnInfos, + Optional localContextInfo); }; AsyncContextLayout getAsyncContextLayout(IRGenFunction &IGF, diff --git a/lib/IRGen/GenProto.cpp b/lib/IRGen/GenProto.cpp index af2b5b5d98a..b120effa52a 100644 --- a/lib/IRGen/GenProto.cpp +++ b/lib/IRGen/GenProto.cpp @@ -3100,7 +3100,11 @@ NecessaryBindings NecessaryBindings::computeBindings( continue; case MetadataSource::Kind::SelfMetadata: - bindings.addTypeMetadata(getSubstSelfType(IGM, origType, subs)); + // Async functions pass the SelfMetadata and SelfWitnessTable parameters + // along explicitly. + if (forPartialApplyForwarder) { + bindings.addTypeMetadata(getSubstSelfType(IGM, origType, subs)); + } continue; case MetadataSource::Kind::SelfWitnessTable: diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 0b51850255d..a81b576da14 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -1221,6 +1221,14 @@ class AsyncNativeCCEntryPointArgumentEmission final /*const*/ AsyncContextLayout layout; const Address dataAddr; + llvm::Value *loadValue(ElementLayout layout) { + Address addr = layout.project(IGF, dataAddr, /*offsets*/ llvm::None); + auto &ti = cast(layout.getType()); + Explosion explosion; + ti.loadAsTake(IGF, addr, explosion); + return explosion.claimNext(); + } + public: AsyncNativeCCEntryPointArgumentEmission(IRGenSILFunction &IGF, SILBasicBlock &entry, @@ -1234,36 +1242,17 @@ public: Address addr = errorLayout.project(IGF, dataAddr, /*offsets*/ llvm::None); return addr.getAddress(); } - llvm::Value *getErrorResultAddrForCall() { - auto errorLayout = layout.getErrorLayout(); - auto &ti = cast(errorLayout.getType()); - auto allocaAddr = ti.allocateStack(IGF, layout.getErrorType(), "arg"); - auto addrInContext = - layout.getErrorLayout().project(IGF, dataAddr, /*offsets*/ llvm::None); - Explosion explosion; - ti.loadAsTake(IGF, addrInContext, explosion); - ti.initialize(IGF, explosion, allocaAddr.getAddress(), - /*isOutlined*/ false); - return allocaAddr.getAddress().getAddress(); - } llvm::Value *getContext() override { auto contextLayout = layout.getLocalContextLayout(); - Address addr = contextLayout.project(IGF, dataAddr, /*offsets*/ llvm::None); - auto &ti = cast(contextLayout.getType()); - Explosion explosion; - ti.loadAsTake(IGF, addr, explosion); - return explosion.claimNext(); + return loadValue(contextLayout); } Explosion getArgumentExplosion(unsigned index, unsigned size) override { assert(size > 0); Explosion result; for (unsigned i = index, end = index + size; i < end; ++i) { auto argumentLayout = layout.getArgumentLayout(i); - auto addr = argumentLayout.project(IGF, dataAddr, /*offsets*/ llvm::None); - auto &ti = cast(argumentLayout.getType()); - Explosion explosion; - ti.loadAsTake(IGF, addr, explosion); - result.add(explosion.claimAll()); + auto *value = loadValue(argumentLayout); + result.add(value); } return result; } @@ -1274,18 +1263,17 @@ public: "indirected through the context"); } llvm::Value *getIndirectResult(unsigned index) override { - Address dataAddr = layout.emitCastTo(IGF, context); - unsigned baseIndirectReturnIndex = layout.getFirstIndirectReturnIndex(); - unsigned elementIndex = baseIndirectReturnIndex + index; - auto &fieldLayout = layout.getElement(elementIndex); - Address fieldAddr = - fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None); - return IGF.Builder.CreateLoad(fieldAddr); + auto fieldLayout = layout.getIndirectReturnLayout(index); + return loadValue(fieldLayout); }; llvm::Value *getSelfWitnessTable() override { - llvm_unreachable("unimplemented"); + auto fieldLayout = layout.getSelfWitnessTableLayout(); + return loadValue(fieldLayout); + } + llvm::Value *getSelfMetadata() override { + auto fieldLayout = layout.getSelfMetadataLayout(); + return loadValue(fieldLayout); } - llvm::Value *getSelfMetadata() override { llvm_unreachable("unimplemented"); } llvm::Value *getCoroutineBuffer() override { llvm_unreachable("unimplemented"); } @@ -3115,16 +3103,13 @@ static void emitReturnInst(IRGenSILFunction &IGF, auto layout = getAsyncContextLayout(IGF); Address dataAddr = layout.emitCastTo(IGF, context); - unsigned index = layout.getFirstDirectReturnIndex(); - for (auto r : - IGF.CurSILFn->getLoweredFunctionType()->getDirectFormalResults()) { - (void)r; - auto &fieldLayout = layout.getElement(index); + for (unsigned index = 0, count = layout.getDirectReturnCount(); + index < count; ++index) { + auto fieldLayout = layout.getDirectReturnLayout(index); Address fieldAddr = fieldLayout.project(IGF, dataAddr, /*offsets*/ llvm::None); cast(fieldLayout.getType()) .initialize(IGF, result, fieldAddr, /*isOutlined*/ false); - ++index; } IGF.Builder.CreateRetVoid(); } else { diff --git a/test/IRGen/async/run-call-classinstance-int64-to-void.sil b/test/IRGen/async/run-call-classinstance-int64-to-void.sil index cce841fa8e0..1f1adbfd61d 100644 --- a/test/IRGen/async/run-call-classinstance-int64-to-void.sil +++ b/test/IRGen/async/run-call-classinstance-int64-to-void.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-classinstance-void-to-void.sil b/test/IRGen/async/run-call-classinstance-void-to-void.sil index cad66b346e9..40da285fed9 100644 --- a/test/IRGen/async/run-call-classinstance-void-to-void.sil +++ b/test/IRGen/async/run-call-classinstance-void-to-void.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-existential-to-void.sil b/test/IRGen/async/run-call-existential-to-void.sil index f76c750e2ff..29019ab1946 100644 --- a/test/IRGen/async/run-call-existential-to-void.sil +++ b/test/IRGen/async/run-call-existential-to-void.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-generic-to-generic.sil b/test/IRGen/async/run-call-generic-to-generic.sil index 491d5b610f3..d5da1c9f97e 100644 --- a/test/IRGen/async/run-call-generic-to-generic.sil +++ b/test/IRGen/async/run-call-generic-to-generic.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none @@ -35,7 +35,7 @@ bb0(%0 : $Int32, %1 : $UnsafeMutablePointer> %out_addr = alloc_stack $Int64 %genericToGeneric = function_ref @genericToGeneric : $@async @convention(thin) (@in_guaranteed T) -> @out T - %result1 = apply %genericToGeneric(%int_addr, %out_addr) : $@async @convention(thin) (@in_guaranteed T) -> @out T + %result1 = apply %genericToGeneric(%out_addr, %int_addr) : $@async @convention(thin) (@in_guaranteed T) -> @out T %print_int = function_ref @printInt64 : $@convention(thin) (Int64) -> () %out = load %out_addr : $*Int64 diff --git a/test/IRGen/async/run-call-generic-to-void.sil b/test/IRGen/async/run-call-generic-to-void.sil index d692426cbaf..94f6d550c3e 100644 --- a/test/IRGen/async/run-call-generic-to-void.sil +++ b/test/IRGen/async/run-call-generic-to-void.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil b/test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil index 5b8ae8f9b01..1bce84155f6 100644 --- a/test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil +++ b/test/IRGen/async/run-call-genericEquatable-x2-to-bool.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-int64-and-int64-to-void.sil b/test/IRGen/async/run-call-int64-and-int64-to-void.sil index a23df61b548..8921d5ac538 100644 --- a/test/IRGen/async/run-call-int64-and-int64-to-void.sil +++ b/test/IRGen/async/run-call-int64-and-int64-to-void.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-int64-to-void.sil b/test/IRGen/async/run-call-int64-to-void.sil index a0a7775df3a..5425e64cc2a 100644 --- a/test/IRGen/async/run-call-int64-to-void.sil +++ b/test/IRGen/async/run-call-int64-to-void.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-protocolextension_instance-void-to-int64.sil b/test/IRGen/async/run-call-protocolextension_instance-void-to-int64.sil index 10badd65e16..fae1f0549f1 100644 --- a/test/IRGen/async/run-call-protocolextension_instance-void-to-int64.sil +++ b/test/IRGen/async/run-call-protocolextension_instance-void-to-int64.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-protocolwitness_instance-void-to-int64.sil b/test/IRGen/async/run-call-protocolwitness_instance-void-to-int64.sil new file mode 100644 index 00000000000..b260aaf31ac --- /dev/null +++ b/test/IRGen/async/run-call-protocolwitness_instance-void-to-int64.sil @@ -0,0 +1,73 @@ +// RUN: %empty-directory(%t) +// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule +// RUN: %target-codesign %t/%target-library-name(PrintShims) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-codesign %t/main +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: swift_test_mode_optimize_none +// UNSUPPORTED: use_os_stdlib + +import Builtin +import Swift +import PrintShims + +sil public_external @printGeneric : $@convention(thin) (@in_guaranteed T) -> () +sil public_external @printInt64 : $@convention(thin) (Int64) -> () + +protocol P { + func printMe() async -> Int64 +} + +struct I : P { + @_hasStorage let int: Int64 { get } + func printMe() async -> Int64 + init(int: Int64) +} + +// CHECK-LL-LABEL: define hidden swiftcc void @I_printMe(%swift.context* {{%[0-9]*}}) {{#[0-9]*}} { +sil hidden @I_printMe : $@async @convention(method) (I) -> Int64 { +bb0(%self : $I): + %self_addr = alloc_stack $I + store %self to %self_addr : $*I + %printGeneric = function_ref @printGeneric : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () + %printGeneric_result = apply %printGeneric(%self_addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () + dealloc_stack %self_addr : $*I + %result = struct_extract %self : $I, #I.int + return %result : $Int64 +} + +// CHECK-LL-LABEL: define internal swiftcc void @I_P_printMe(%swift.context* {{%[0-9]*}}) {{#[0-9]*}} { +sil private [transparent] [thunk] @I_P_printMe : $@async @convention(witness_method: P) (@in_guaranteed I) -> Int64 { +bb0(%self_addr : $*I): + %self = load %self_addr : $*I + %I_printMe = function_ref @I_printMe : $@async @convention(method) (I) -> Int64 + %result = apply %I_printMe(%self) : $@async @convention(method) (I) -> Int64 + return %result : $Int64 +} + +sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { +bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): + %i_type = metatype $@thin I.Type + %i_int_literal = integer_literal $Builtin.Int64, 99 + %i_int = struct $Int64 (%i_int_literal : $Builtin.Int64) + %i = struct $I (%i_int : $Int64) + %i_addr = alloc_stack $I + store %i to %i_addr : $*I + %P_printMe = witness_method $I, #P.printMe : (Self) -> () async -> Int64 : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 + %result = apply %P_printMe(%i_addr) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 // CHECK: I(int: 99) + dealloc_stack %i_addr : $*I + %printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> () + %printInt64_result = apply %printInt64(%result) : $@convention(thin) (Int64) -> () // CHECK: 99 + + %out_literal = integer_literal $Builtin.Int32, 0 + %out = struct $Int32 (%out_literal : $Builtin.Int32) + return %out : $Int32 +} + +sil_witness_table hidden I: P module main { + method #P.printMe: (Self) -> () async -> Int64 : @I_P_printMe +} + diff --git a/test/IRGen/async/run-call-structinstance-int64-to-void.sil b/test/IRGen/async/run-call-structinstance-int64-to-void.sil index ae950265fd4..612cbdb9c4b 100644 --- a/test/IRGen/async/run-call-structinstance-int64-to-void.sil +++ b/test/IRGen/async/run-call-structinstance-int64-to-void.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-nothrow_call-sync-throw.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-nothrow_call-sync-throw.sil index 1441327807b..b8cb7270ebc 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-nothrow_call-sync-throw.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-nothrow_call-sync-throw.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-throw.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-throw.sil index 14a92c62729..de2055a6f17 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-throw.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-async-throw.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-nothrow_call-async-throw.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-nothrow_call-async-throw.sil index 49daf094c4e..4d45943257f 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-nothrow_call-async-throw.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-nothrow_call-async-throw.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-throw.sil b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-throw.sil index 95c083a9558..64a5a42098f 100644 --- a/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-throw.sil +++ b/test/IRGen/async/run-call-void-throws-to-int-throwing_call-sync-throw.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-void-to-existential.sil b/test/IRGen/async/run-call-void-to-existential.sil index fc58a6c6446..24cbcc6f91b 100644 --- a/test/IRGen/async/run-call-void-to-existential.sil +++ b/test/IRGen/async/run-call-void-to-existential.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-void-to-int64-and-int64.sil b/test/IRGen/async/run-call-void-to-int64-and-int64.sil index ebfd51c0b06..27a5ae1767e 100644 --- a/test/IRGen/async/run-call-void-to-int64-and-int64.sil +++ b/test/IRGen/async/run-call-void-to-int64-and-int64.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-void-to-int64.sil b/test/IRGen/async/run-call-void-to-int64.sil index 168bca6875f..48efd5e337c 100644 --- a/test/IRGen/async/run-call-void-to-int64.sil +++ b/test/IRGen/async/run-call-void-to-int64.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call-void-to-struct_large.sil b/test/IRGen/async/run-call-void-to-struct_large.sil index abb78dacaf2..006355b21a1 100644 --- a/test/IRGen/async/run-call-void-to-struct_large.sil +++ b/test/IRGen/async/run-call-void-to-struct_large.sil @@ -4,7 +4,7 @@ // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL // RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) // RUN: %target-codesign %t/main -// RUN: %target-run %t/main | %FileCheck %s +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: swift_test_mode_optimize_none diff --git a/test/IRGen/async/run-call_generic-protocolwitness_instance-generic-to-int64-and-generic.sil b/test/IRGen/async/run-call_generic-protocolwitness_instance-generic-to-int64-and-generic.sil new file mode 100644 index 00000000000..796e25df195 --- /dev/null +++ b/test/IRGen/async/run-call_generic-protocolwitness_instance-generic-to-int64-and-generic.sil @@ -0,0 +1,97 @@ +// RUN: %empty-directory(%t) +// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule +// RUN: %target-codesign %t/%target-library-name(PrintShims) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-codesign %t/main +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: swift_test_mode_optimize_none +// UNSUPPORTED: use_os_stdlib + +import Builtin +import Swift +import PrintShims + +sil public_external @printGeneric : $@convention(thin) (@in_guaranteed T) -> () +sil public_external @printInt64 : $@convention(thin) (Int64) -> () + +protocol P { + func printMe(_ t: T) async -> (Int64, T) +} + +extension P { + func callPrintMe(_ t: T) async -> (Int64, T) +} + +struct I : P { + @_hasStorage let int: Int64 { get } + func printMe(_ t: T) async -> (Int64, T) + init(int: Int64) +} + +sil hidden @I_printMe : $@convention(method) @async (@in_guaranteed T, I) -> (Int64, @out T) { +bb0(%out_addr : $*T, %in_addr : $*T, %self : $I): + %self_addr = alloc_stack $I + store %self to %self_addr : $*I + %printGeneric = function_ref @printGeneric : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () + %printGeneric_result = apply %printGeneric(%self_addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () + dealloc_stack %self_addr : $*I + %value = struct_extract %self : $I, #I.int + copy_addr %in_addr to [initialization] %out_addr : $*T + return %value : $Int64 +} + +// CHECK-LL: define internal swiftcc void @I_P_printMe(%swift.context* {{%[0-9]*}}) {{#[0-9]*}} { +sil private [transparent] [thunk] @I_P_printMe : $@convention(witness_method: P) @async <τ_0_0> (@in_guaranteed τ_0_0, @in_guaranteed I) -> (Int64, @out τ_0_0) { +bb0(%out_addr : $*τ_0_0, %in_addr : $*τ_0_0, %self_addr : $*I): + %self = load %self_addr : $*I + %I_printMe = function_ref @I_printMe : $@convention(method) @async <τ_0_0> (@in_guaranteed τ_0_0, I) -> (Int64, @out τ_0_0) + %result = apply %I_printMe<τ_0_0>(%out_addr, %in_addr, %self) : $@convention(method) @async <τ_0_0> (@in_guaranteed τ_0_0, I) -> (Int64, @out τ_0_0) + return %result : $Int64 +} + +sil hidden @callPrintMe : $@convention(thin) (@in_guaranteed T, @in_guaranteed U) -> (Int64, @out U) { +bb0(%out_addr : $*U, %self_addr : $*T, %in_addr : $*U): + %I_P_printMe = witness_method $T, #P.printMe : (Self) -> (T) async -> (Int64, T) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P><τ_1_0> (@in_guaranteed τ_1_0, @in_guaranteed τ_0_0) -> (Int64, @out τ_1_0) + %result = apply %I_P_printMe(%out_addr, %in_addr, %self_addr) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P><τ_1_0> (@in_guaranteed τ_1_0, @in_guaranteed τ_0_0) -> (Int64, @out τ_1_0) + return %result : $Int64 +} + +sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { +bb0(%argc : $Int32, %argv : $UnsafeMutablePointer>>): + %I_type = metatype $@thin I.Type + %int_literal = integer_literal $Builtin.Int64, 99 + %int = struct $Int64 (%int_literal : $Builtin.Int64) + %i = struct $I (%int : $Int64) + %out_addr = alloc_stack $I + %in_addr = alloc_stack $I + store %i to %in_addr : $*I + %i_addr = alloc_stack $I + store %i to %i_addr : $*I + %callPrintMe = function_ref @callPrintMe : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : P> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> (Int64, @out τ_0_1) + %result = apply %callPrintMe(%out_addr, %in_addr, %i_addr) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : P> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> (Int64, @out τ_0_1) + dealloc_stack %i_addr : $*I + dealloc_stack %in_addr : $*I + %out = load %out_addr : $*I + dealloc_stack %out_addr : $*I + %printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> () + %printInt64_result = apply %printInt64(%result) : $@convention(thin) (Int64) -> () // CHECK: 99 + %out_addr_2 = alloc_stack $I + store %out to %out_addr_2 : $*I + %printGeneric = function_ref @printGeneric : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () + %printGeneric_result = apply %printGeneric(%out_addr_2) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () // CHECK: I(int: 99) + dealloc_stack %out_addr_2 : $*I + + + + %returnCode_literal = integer_literal $Builtin.Int32, 0 + %returnCode = struct $Int32 (%returnCode_literal : $Builtin.Int32) + return %returnCode : $Int32 +} + + +sil_witness_table hidden I: P module main { + method #P.printMe: (Self) -> (T) async -> (Int64, T) : @I_P_printMe +} diff --git a/test/IRGen/async/run-call_generic-protocolwitness_instance-void-to-int64.sil b/test/IRGen/async/run-call_generic-protocolwitness_instance-void-to-int64.sil new file mode 100644 index 00000000000..99b78463e33 --- /dev/null +++ b/test/IRGen/async/run-call_generic-protocolwitness_instance-void-to-int64.sil @@ -0,0 +1,80 @@ +// RUN: %empty-directory(%t) +// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule +// RUN: %target-codesign %t/%target-library-name(PrintShims) +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL +// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t) +// RUN: %target-codesign %t/main +// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: swift_test_mode_optimize_none +// UNSUPPORTED: use_os_stdlib + +import Builtin +import Swift +import PrintShims + +sil public_external @printGeneric : $@convention(thin) (@in_guaranteed T) -> () +sil public_external @printInt64 : $@convention(thin) (Int64) -> () + +protocol P { + func printMe() async -> Int64 +} + +struct I : P { + @_hasStorage let int: Int64 { get } + func printMe() async -> Int64 + init(int: Int64) +} + +// CHECK-LL-LABEL: define hidden swiftcc void @I_printMe(%swift.context* {{%[0-9]*}}) {{#[0-9]*}} { +sil hidden @I_printMe : $@async @convention(method) (I) -> Int64 { +bb0(%self : $I): + %self_addr = alloc_stack $I + store %self to %self_addr : $*I + %printGeneric = function_ref @printGeneric : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () + %printGeneric_result = apply %printGeneric(%self_addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () + dealloc_stack %self_addr : $*I + %result = struct_extract %self : $I, #I.int + return %result : $Int64 +} + +// CHECK-LL-LABEL: define internal swiftcc void @I_P_printMe(%swift.context* {{%[0-9]*}}) {{#[0-9]*}} { +sil private [transparent] [thunk] @I_P_printMe : $@async @convention(witness_method: P) (@in_guaranteed I) -> Int64 { +bb0(%self_addr : $*I): + %self = load %self_addr : $*I + %I_printMe = function_ref @I_printMe : $@async @convention(method) (I) -> Int64 + %result = apply %I_printMe(%self) : $@async @convention(method) (I) -> Int64 + return %result : $Int64 +} + +sil hidden @callPrintMe : $@convention(thin) (@in_guaranteed T) -> Int64 { +bb0(%t : $*T): + %I_P_printMe = witness_method $T, #P.printMe : (Self) -> () async -> Int64 : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 + %result = apply %I_P_printMe(%t) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 + return %result : $Int64 +} + +sil @main : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { +bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): + %i_type = metatype $@thin I.Type + %i_int_literal = integer_literal $Builtin.Int64, 99 + %i_int = struct $Int64 (%i_int_literal : $Builtin.Int64) + %i = struct $I (%i_int : $Int64) + %i_addr = alloc_stack $I + store %i to %i_addr : $*I + %callPrintMe = function_ref @callPrintMe : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 + %result = apply %callPrintMe(%i_addr) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 // users: %13, %11 // CHECK: I(int: 99) + dealloc_stack %i_addr : $*I + %printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> () + %printInt64_result = apply %printInt64(%result) : $@convention(thin) (Int64) -> () // CHECK: 99 + + %out_literal = integer_literal $Builtin.Int32, 0 + %out = struct $Int32 (%out_literal : $Builtin.Int32) + return %out : $Int32 +} + +sil_witness_table hidden I: P module main { + method #P.printMe: (Self) -> () async -> Int64 : @I_P_printMe +} +