Skip to content

Commit 45d85bb

Browse files
authored
Merge pull request #2768 from swiftwasm/main
[pull] swiftwasm from main
2 parents 2c0208f + 1c2b80f commit 45d85bb

File tree

80 files changed

+402
-208
lines changed

Some content is hidden

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

80 files changed

+402
-208
lines changed

include/swift/Runtime/Concurrency.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ size_t swift_task_getJobFlags(AsyncTask* task);
225225
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
226226
bool swift_task_isCancelled(AsyncTask* task);
227227

228+
/// Create and add an cancellation record to the task.
229+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
230+
CancellationNotificationStatusRecord*
231+
swift_task_addCancellationHandler(
232+
AsyncTask *task, CancellationNotificationStatusRecord::FunctionType handler);
233+
234+
/// Remove the passed cancellation record from the task.
235+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
236+
void swift_task_removeCancellationHandler(
237+
AsyncTask *task, CancellationNotificationStatusRecord *record);
238+
228239
using TaskLocalValuesFragment = AsyncTask::TaskLocalValuesFragment;
229240

230241
/// Get a task local value from the passed in task. Its Swift signature is

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ FUNCTION(TaskCreateFutureFunc,
15271527
// ExecutorRef currentExecutor,
15281528
// ExecutorRef newExecutor);
15291529
FUNCTION(TaskSwitchFunc,
1530-
swift_task_switch, SwiftCC,
1530+
swift_task_switch, SwiftAsyncCC,
15311531
ConcurrencyAvailability,
15321532
RETURNS(VoidTy),
15331533
ARGS(SwiftTaskPtrTy, SwiftExecutorPtrTy, SwiftExecutorPtrTy),

include/swift/SIL/SILVTableVisitor.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ template <class T> class SILVTableVisitor {
9292
// replace the vtable entry for B.f(); a call to A.f()
9393
// will correctly dispatch to the implementation of B.f()
9494
// in the subclass.
95+
auto *UseDC = declRef.getDecl()->getDeclContext();
9596
if (!baseRef.getDecl()->isAccessibleFrom(
96-
declRef.getDecl()->getDeclContext()))
97+
UseDC,
98+
/*forConformance=*/false,
99+
/*allowUsableFromInline=*/true))
97100
break;
98101

99102
asDerived().addMethodOverride(baseRef, declRef);

include/swift/Sema/CSBindings.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ struct LiteralRequirement {
206206
bool canBeNil,
207207
DeclContext *useDC) const;
208208

209+
void resetCoverage() {
210+
assert(isCovered() && "literal requirement is uncovered");
211+
CoveredBy = nullptr;
212+
}
213+
209214
/// Determines whether literal protocol associated with this
210215
/// meta-information is viable for inclusion as a defaultable binding.
211216
bool viableAsBinding() const { return !isCovered() && hasDefaultType(); }
@@ -465,6 +470,13 @@ struct PotentialBindings {
465470
public:
466471
void infer(Constraint *constraint);
467472

473+
/// Retract all bindings and other information related to a given
474+
/// constraint from this binding set.
475+
///
476+
/// This would happen when constraint is simplified or solver backtracks
477+
/// (either from overload choice or (some) type variable binding).
478+
void retract(Constraint *constraint);
479+
468480
/// Finalize binding computation for this type variable by
469481
/// inferring bindings from context e.g. transitive bindings.
470482
void finalize(llvm::SmallDenseMap<TypeVariableType *, PotentialBindings>

lib/AST/Decl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,13 +3418,16 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
34183418
}
34193419

34203420
bool ValueDecl::isMoreVisibleThan(ValueDecl *other) const {
3421-
auto scope = getFormalAccessScope();
3421+
auto scope = getFormalAccessScope(/*UseDC=*/nullptr,
3422+
/*treatUsableFromInlineAsPublic=*/true);
34223423

34233424
// 'other' may have come from a @testable import, so we need to upgrade it's
34243425
// visibility to public here. That is not the same as whether 'other' is
34253426
// being built with -enable-testing though -- we don't want to treat it
34263427
// differently in that case.
3427-
auto otherScope = other->getFormalAccessScope(getDeclContext());
3428+
auto otherScope =
3429+
other->getFormalAccessScope(getDeclContext(),
3430+
/*treatUsableFromInlineAsPublic=*/true);
34283431

34293432
if (scope.isPublic())
34303433
return !otherScope.isPublic();

lib/IRGen/GenCall.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ static llvm::CallingConv::ID getFreestandingConvention(IRGenModule &IGM) {
462462
/// Expand the requirements of the given abstract calling convention
463463
/// into a "physical" calling convention.
464464
llvm::CallingConv::ID irgen::expandCallingConv(IRGenModule &IGM,
465-
SILFunctionTypeRepresentation convention) {
465+
SILFunctionTypeRepresentation convention,
466+
bool isAsync) {
466467
switch (convention) {
467468
case SILFunctionTypeRepresentation::CFunctionPointer:
468469
case SILFunctionTypeRepresentation::ObjCMethod:
@@ -474,6 +475,8 @@ llvm::CallingConv::ID irgen::expandCallingConv(IRGenModule &IGM,
474475
case SILFunctionTypeRepresentation::Closure:
475476
case SILFunctionTypeRepresentation::Thin:
476477
case SILFunctionTypeRepresentation::Thick:
478+
if (isAsync)
479+
return IGM.SwiftAsyncCC;
477480
return getFreestandingConvention(IGM);
478481
}
479482
llvm_unreachable("bad calling convention!");
@@ -1849,7 +1852,8 @@ Signature SignatureExpansion::getSignature() {
18491852
(FnType->getLanguage() == SILFunctionLanguage::C) &&
18501853
"C function type without C function info");
18511854

1852-
auto callingConv = expandCallingConv(IGM, FnType->getRepresentation());
1855+
auto callingConv =
1856+
expandCallingConv(IGM, FnType->getRepresentation(), FnType->isAsync());
18531857

18541858
Signature result;
18551859
result.Type = llvmType;
@@ -4823,7 +4827,7 @@ IRGenFunction::getFunctionPointerForResumeIntrinsic(llvm::Value *resume) {
48234827
IGM.VoidTy, {IGM.Int8PtrTy, IGM.Int8PtrTy, IGM.Int8PtrTy},
48244828
false /*vaargs*/);
48254829
auto signature =
4826-
Signature(fnTy, IGM.constructInitialAttributes(), IGM.SwiftCC);
4830+
Signature(fnTy, IGM.constructInitialAttributes(), IGM.SwiftAsyncCC);
48274831
auto fnPtr = FunctionPointer(
48284832
FunctionPointer::KindTy::Function,
48294833
Builder.CreateBitOrPointerCast(resume, fnTy->getPointerTo()),

lib/IRGen/GenCall.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ namespace irgen {
316316
std::pair<bool, bool> values = {true, true},
317317
Size initialContextSize = Size(0));
318318
llvm::CallingConv::ID expandCallingConv(IRGenModule &IGM,
319-
SILFunctionTypeRepresentation convention);
319+
SILFunctionTypeRepresentation convention,
320+
bool isAsync);
320321

321322
Signature emitCastOfFunctionPointer(IRGenFunction &IGF, llvm::Value *&fnPtr,
322323
CanSILFunctionType fnType);

lib/IRGen/GenFunc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,7 @@ llvm::Function *IRGenFunction::createAsyncSuspendFn() {
25822582
IGM.getTaskSwitchFuncFn(),
25832583
{ task, executor, targetExecutor });
25842584
suspendCall->setDoesNotThrow();
2585-
suspendCall->setCallingConv(IGM.SwiftCC);
2585+
suspendCall->setCallingConv(IGM.SwiftAsyncCC);
25862586
suspendCall->setTailCall();
25872587
Builder.CreateRetVoid();
25882588
return suspendFn;

lib/IRGen/GenObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
710710
llvm::Function::Create(fwdTy, llvm::Function::InternalLinkage,
711711
MANGLE_AS_STRING(OBJC_PARTIAL_APPLY_THUNK_SYM),
712712
&IGM.Module);
713-
fwd->setCallingConv(
714-
expandCallingConv(IGM, SILFunctionTypeRepresentation::Thick));
713+
fwd->setCallingConv(expandCallingConv(
714+
IGM, SILFunctionTypeRepresentation::Thick, false/*isAsync*/));
715715

716716
fwd->setAttributes(attrs);
717717
// Merge initial attributes with attrs.

lib/IRGen/IRGenModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
547547
// TODO: use "tinycc" on platforms that support it
548548
DefaultCC = SWIFT_DEFAULT_LLVM_CC;
549549
SwiftCC = llvm::CallingConv::Swift;
550+
// TODO: Once clang support is merged this should also use
551+
// clangASTContext.getTargetInfo().isSwiftAsyncCCSupported()
552+
SwiftAsyncCC = opts.UseAsyncLowering ? llvm::CallingConv::SwiftTail : SwiftCC;
550553

551554
if (opts.DebugInfoLevel > IRGenDebugInfoLevel::None)
552555
DebugInfo = IRGenDebugInfo::createIRGenDebugInfo(IRGen.Opts, *CI, *this,

0 commit comments

Comments
 (0)