Skip to content

Commit c0ba520

Browse files
Merge pull request swiftlang#79781 from nate-chandler/general-coro/20250227/1
[CoroutineAccessors] Dispatch and PtrAuth.
2 parents b6b4a7b + 6581fec commit c0ba520

Some content is hidden

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

45 files changed

+742
-173
lines changed

docs/ABI/Mangling.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ types where the metadata itself has unknown layout.)
235235
global ::= global 'TF' // distributed method accessor
236236
global ::= global 'TI' // implementation of a dynamic_replaceable function
237237
global ::= global 'Tu' // async function pointer of a function
238-
global ::= global 'Tv' // coro function pointer of a function
239238
global ::= global 'TX' // function pointer of a dynamic_replaceable function
240239
global ::= global 'Twb' // back deployment thunk
241240
global ::= global 'TwB' // back deployment fallback function
241+
global ::= global 'Twc' // coro function pointer of a function
242242
global ::= entity entity 'TV' // vtable override thunk, derived followed by base
243243
global ::= type label-list? 'D' // type mangling for the debugger with label list for function types.
244244
global ::= type 'TC' // continuation prototype (not actually used for real symbols)

include/swift/ABI/Metadata.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -5094,9 +5094,9 @@ struct DynamicReplacementKey {
50945094
uint16_t getExtraDiscriminator() const {
50955095
return flags & 0x0000FFFF;
50965096
}
5097-
bool isAsync() const {
5098-
return ((flags >> 16 ) & 0x1);
5099-
}
5097+
bool isAsync() const { return ((flags >> 16) & 0x1); }
5098+
bool isCalleeAllocatedCoroutine() const { return ((flags >> 16) & 0x2); }
5099+
bool isData() const { return isAsync() || isCalleeAllocatedCoroutine(); }
51005100
};
51015101

51025102
/// A record describing a dynamic function replacement.

include/swift/ABI/MetadataValues.h

+37
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,23 @@ class MethodDescriptorFlags {
438438

439439
bool isAsync() const { return Value & IsAsyncMask; }
440440

441+
bool isCalleeAllocatedCoroutine() const {
442+
switch (getKind()) {
443+
case Kind::Method:
444+
case Kind::Init:
445+
case Kind::Getter:
446+
case Kind::Setter:
447+
case Kind::ModifyCoroutine:
448+
case Kind::ReadCoroutine:
449+
return false;
450+
case Kind::Read2Coroutine:
451+
case Kind::Modify2Coroutine:
452+
return true;
453+
}
454+
}
455+
456+
bool isData() const { return isAsync() || isCalleeAllocatedCoroutine(); }
457+
441458
uint16_t getExtraDiscriminator() const {
442459
return (Value >> ExtraDiscriminatorShift);
443460
}
@@ -649,6 +666,26 @@ class ProtocolRequirementFlags {
649666

650667
bool isAsync() const { return Value & IsAsyncMask; }
651668

669+
bool isCalleeAllocatedCoroutine() const {
670+
switch (getKind()) {
671+
case Kind::BaseProtocol:
672+
case Kind::Method:
673+
case Kind::Init:
674+
case Kind::Getter:
675+
case Kind::Setter:
676+
case Kind::ReadCoroutine:
677+
case Kind::ModifyCoroutine:
678+
case Kind::AssociatedTypeAccessFunction:
679+
case Kind::AssociatedConformanceAccessFunction:
680+
return false;
681+
case Kind::Read2Coroutine:
682+
case Kind::Modify2Coroutine:
683+
return true;
684+
}
685+
}
686+
687+
bool isData() const { return isAsync() || isCalleeAllocatedCoroutine(); }
688+
652689
bool isSignedWithAddress() const {
653690
return getKind() != Kind::BaseProtocol;
654691
}

include/swift/AST/IRGenOptions.h

+23-6
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,26 @@ struct PointerAuthOptions : clang::PointerAuthOptions {
230230

231231
/// Type layout string descriminator.
232232
PointerAuthSchema TypeLayoutString;
233+
234+
/// Like SwiftFunctionPointers but for use with CoroFunctionPointer values.
235+
PointerAuthSchema CoroSwiftFunctionPointers;
236+
237+
/// Like SwiftClassMethods but for use with CoroFunctionPointer values.
238+
PointerAuthSchema CoroSwiftClassMethods;
239+
240+
/// Like ProtocolWitnesses but for use with CoroFunctionPointer values.
241+
PointerAuthSchema CoroProtocolWitnesses;
242+
243+
/// Like SwiftClassMethodPointers but for use with CoroFunctionPointer
244+
/// values.
245+
PointerAuthSchema CoroSwiftClassMethodPointers;
246+
247+
/// Like SwiftDynamicReplacements but for use with CoroFunctionPointer
248+
/// values.
249+
PointerAuthSchema CoroSwiftDynamicReplacements;
250+
251+
/// Like PartialApplyCapture but for use with CoroFunctionPointer values.
252+
PointerAuthSchema CoroPartialApplyCapture;
233253
};
234254

235255
enum class JITDebugArtifact : unsigned {
@@ -502,9 +522,6 @@ class IRGenOptions {
502522
// Whether to emit typed malloc during coroutine frame allocation.
503523
unsigned EmitTypeMallocForCoroFrame : 1;
504524

505-
// Whether to use the yield_once ABI when emitting yield_once_2 coroutines.
506-
unsigned EmitYieldOnce2AsYieldOnce : 1;
507-
508525
// Whether to force emission of a frame for all async functions
509526
// (LLVM's 'frame-pointer=all').
510527
unsigned AsyncFramePointerAll : 1;
@@ -621,9 +638,9 @@ class IRGenOptions {
621638
ColocateTypeDescriptors(true), UseRelativeProtocolWitnessTables(false),
622639
UseFragileResilientProtocolWitnesses(false), EnableHotColdSplit(false),
623640
EmitAsyncFramePushPopMetadata(true), EmitTypeMallocForCoroFrame(false),
624-
EmitYieldOnce2AsYieldOnce(true), AsyncFramePointerAll(false),
625-
UseProfilingMarkerThunks(false), UseCoroCCX8664(false),
626-
UseCoroCCArm64(false), DebugInfoForProfiling(false), CmdArgs(),
641+
AsyncFramePointerAll(false), UseProfilingMarkerThunks(false),
642+
UseCoroCCX8664(false), UseCoroCCArm64(false),
643+
DebugInfoForProfiling(false), CmdArgs(),
627644
SanitizeCoverage(llvm::SanitizerCoverageOptions()),
628645
TypeInfoFilter(TypeInfoDumpFilter::All),
629646
PlatformCCallingConvention(llvm::CallingConv::C), UseCASBackend(false),

include/swift/Basic/Features.def

-3
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,6 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(CoroutineAccessors, true)
477477
/// modify/read single-yield coroutines always execute code post-yield code
478478
EXPERIMENTAL_FEATURE(CoroutineAccessorsUnwindOnCallerError, false)
479479

480-
/// modify/read coroutines use the callee-allocated ABI
481-
EXPERIMENTAL_FEATURE(CoroutineAccessorsAllocateInCallee, false)
482-
483480
/// When a parameter has unspecified isolation, infer it as main actor isolated.
484481
EXPERIMENTAL_FEATURE(GenerateForceToMainActorThunks, false)
485482

include/swift/Demangling/DemangleNodes.def

+1
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ NODE(DependentGenericInverseConformanceRequirement)
408408
NODE(Integer)
409409
NODE(NegativeInteger)
410410
NODE(DependentGenericParamValueMarker)
411+
NODE(CoroFunctionPointer)
411412

412413
#undef CONTEXT_NODE
413414
#undef NODE

include/swift/IRGen/Linking.h

+14
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,11 @@ class LinkEntity {
585585
/// The pointer is the llvm::Function* for a partial apply forwarder.
586586
PartialApplyForwarderCoroFunctionPointer,
587587

588+
/// An coro function pointer to a function which is known to exist whose
589+
/// name is known.
590+
/// The pointer is a const char* of the name.
591+
KnownCoroFunctionPointer,
592+
588593
/// An coro function pointer for a distributed accessor (method or
589594
/// property).
590595
/// The pointer is a SILFunction*.
@@ -1553,6 +1558,15 @@ class LinkEntity {
15531558
return entity;
15541559
}
15551560

1561+
static LinkEntity forKnownCoroFunctionPointer(const char *name) {
1562+
LinkEntity entity;
1563+
entity.Pointer = const_cast<char *>(name);
1564+
entity.SecondaryPointer = nullptr;
1565+
entity.Data =
1566+
LINKENTITY_SET_FIELD(Kind, unsigned(Kind::KnownCoroFunctionPointer));
1567+
return entity;
1568+
}
1569+
15561570
LinkEntity getUnderlyingEntityForCoroFunctionPointer() const {
15571571
LinkEntity entity;
15581572
entity.Pointer = Pointer;

include/swift/SIL/SILDeclRef.h

+1
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ struct SILDeclRef {
605605
}
606606

607607
bool hasAsync() const;
608+
bool isCalleeAllocatedCoroutine() const;
608609

609610
/// Return the hash code for the SIL declaration.
610611
friend llvm::hash_code hash_value(swift::SILDeclRef ref) {

lib/AST/Decl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10931,7 +10931,7 @@ bool AccessorDecl::isRequirementWithSynthesizedDefaultImplementation() const {
1093110931
if (!requiresFeatureCoroutineAccessors(getAccessorKind())) {
1093210932
return false;
1093310933
}
10934-
if (getStorage()->getOverrideLoc()) {
10934+
if (!requiresNewWitnessTableEntry()) {
1093510935
return false;
1093610936
}
1093710937
return getStorage()->requiresCorrespondingUnderscoredCoroutineAccessor(

lib/AST/FeatureSet.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ UNINTERESTING_FEATURE(SafeInteropWrappers)
392392
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
393393
UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)
394394
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
395-
UNINTERESTING_FEATURE(CoroutineAccessorsAllocateInCallee)
396395

397396
bool swift::usesFeatureIsolatedDeinit(const Decl *decl) {
398397
if (auto cd = dyn_cast<ClassDecl>(decl)) {

lib/Demangling/Demangler.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) {
155155
case Node::Kind::BackDeploymentThunk:
156156
case Node::Kind::BackDeploymentFallback:
157157
case Node::Kind::HasSymbolQuery:
158+
case Node::Kind::CoroFunctionPointer:
158159
return true;
159160
default:
160161
return false;
@@ -3134,6 +3135,8 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
31343135
switch (nextChar()) {
31353136
case 'b': return createNode(Node::Kind::BackDeploymentThunk);
31363137
case 'B': return createNode(Node::Kind::BackDeploymentFallback);
3138+
case 'c':
3139+
return createNode(Node::Kind::CoroFunctionPointer);
31373140
case 'S': return createNode(Node::Kind::HasSymbolQuery);
31383141
default:
31393142
return nullptr;

lib/Demangling/NodePrinter.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ class NodePrinter {
657657
case Node::Kind::ObjectiveCProtocolSymbolicReference:
658658
case Node::Kind::DependentGenericInverseConformanceRequirement:
659659
case Node::Kind::DependentGenericParamValueMarker:
660+
case Node::Kind::CoroFunctionPointer:
660661
return false;
661662
}
662663
printer_unreachable("bad node kind");
@@ -3478,6 +3479,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
34783479
Printer << signedValue;
34793480
return nullptr;
34803481
}
3482+
case Node::Kind::CoroFunctionPointer:
3483+
Printer << "coro function pointer to ";
3484+
return nullptr;
34813485
}
34823486

34833487
printer_unreachable("bad node kind!");

lib/Demangling/OldRemangler.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,11 @@ ManglingError Remangler::mangleAsyncFunctionPointer(Node *node,
11981198
return ManglingError::Success;
11991199
}
12001200

1201+
ManglingError Remangler::mangleCoroFunctionPointer(Node *node, unsigned depth) {
1202+
Buffer << "Twc";
1203+
return ManglingError::Success;
1204+
}
1205+
12011206
ManglingError Remangler::mangleDeallocator(Node *node, EntityContext &ctx,
12021207
unsigned depth) {
12031208
return mangleSimpleEntity(node, 'F', "D", ctx, depth + 1);

lib/Demangling/Remangler.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,11 @@ ManglingError Remangler::mangleAsyncFunctionPointer(Node *node,
10511051
return ManglingError::Success;
10521052
}
10531053

1054+
ManglingError Remangler::mangleCoroFunctionPointer(Node *node, unsigned depth) {
1055+
Buffer << "Twc";
1056+
return ManglingError::Success;
1057+
}
1058+
10541059
ManglingError Remangler::mangleDependentAssociatedTypeRef(Node *node,
10551060
unsigned depth) {
10561061
RETURN_IF_ERROR(mangleIdentifier(node->getFirstChild(), depth));
@@ -1836,6 +1841,7 @@ ManglingError Remangler::mangleGlobal(Node *node, unsigned depth) {
18361841
case Node::Kind::BackDeploymentThunk:
18371842
case Node::Kind::BackDeploymentFallback:
18381843
case Node::Kind::HasSymbolQuery:
1844+
case Node::Kind::CoroFunctionPointer:
18391845
mangleInReverseOrder = true;
18401846
break;
18411847
default:

lib/Frontend/CompilerInvocation.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -3674,12 +3674,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
36743674
Args.hasFlag(OPT_enable_fragile_resilient_protocol_witnesses,
36753675
OPT_disable_fragile_resilient_protocol_witnesses,
36763676
Opts.UseFragileResilientProtocolWitnesses);
3677-
Opts.UseProfilingMarkerThunks =
3678-
Args.hasFlag(OPT_enable_profiling_marker_thunks,
3679-
OPT_disable_profiling_marker_thunks,
3680-
Opts.UseProfilingMarkerThunks);
3681-
Opts.EmitYieldOnce2AsYieldOnce =
3682-
!LangOpts.hasFeature(Feature::CoroutineAccessorsAllocateInCallee);
3677+
Opts.UseProfilingMarkerThunks = Args.hasFlag(
3678+
OPT_enable_profiling_marker_thunks, OPT_disable_profiling_marker_thunks,
3679+
Opts.UseProfilingMarkerThunks);
36833680
Opts.EnableHotColdSplit =
36843681
Args.hasFlag(OPT_enable_split_cold_code,
36853682
OPT_disable_split_cold_code,

lib/IRGen/Callee.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,11 @@ namespace irgen {
206206
FunctionPointerKind(SpecialKind kind)
207207
: value(unsigned(kind) + SpecialOffset) {}
208208
FunctionPointerKind(CanSILFunctionType fnType)
209-
: FunctionPointerKind(fnType->isAsync()
210-
? BasicKind::AsyncFunctionPointer
211-
: BasicKind::Function) {}
209+
: FunctionPointerKind(fnType->isAsync()
210+
? BasicKind::AsyncFunctionPointer
211+
: fnType->isCalleeAllocatedCoroutine()
212+
? BasicKind::CoroFunctionPointer
213+
: BasicKind::Function) {}
212214

213215
static FunctionPointerKind defaultSync() {
214216
return BasicKind::Function;

0 commit comments

Comments
 (0)