Skip to content

Commit c56a1e8

Browse files
authored
[Distributed] Handle mangling thunks in extensions with generic AS and $Stubs (swiftlang#71914)
1 parent 92f3b0f commit c56a1e8

29 files changed

+568
-299
lines changed

include/swift/ABI/Metadata.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4992,24 +4992,7 @@ struct TargetAccessibleFunctionRecord {
49924992
AccessibleFunctionFlags Flags;
49934993
};
49944994

4995-
/// More advanced than AccessibleFunctionRecord and contains Actor name
4996-
template <typename Runtime>
4997-
struct TargetAccessibleProtocolRequirementFunctionRecord
4998-
: public TargetAccessibleFunctionRecord<Runtime> {
4999-
public:
5000-
/// The concrete Actor type for this accessor.
5001-
RelativeDirectPointer<const char, /*nullable*/ false> ConcreteActorName;
5002-
5003-
/// The concrete witness method mangled name.
5004-
/// The record name for such record is the mangled name of the protocol
5005-
/// method. This is the mangled name of the concrete witness method.
5006-
RelativeDirectPointer<const char, /*nullable*/ false>
5007-
ConcreteWitnessMethodName;
5008-
};
5009-
50104995
using AccessibleFunctionRecord = TargetAccessibleFunctionRecord<InProcess>;
5011-
using AccessibleProtocolRequirementFunctionRecord =
5012-
TargetAccessibleProtocolRequirementFunctionRecord<InProcess>;
50134996

50144997
enum class PackLifetime : uint8_t {
50154998
OnStack = 0,

include/swift/ABI/MetadataValues.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,6 @@ namespace SpecialPointerAuthDiscriminators {
16191619

16201620
/// Functions accessible at runtime (i.e. distributed method accessors).
16211621
const uint16_t AccessibleFunctionRecord = 0x438c; // = 17292
1622-
const uint16_t AccessibleProtocolRequirementFunctionRecord =
1623-
0xa98e; // = 43406
16241622

16251623
/// C type GetExtraInhabitantTag function descriminator
16261624
const uint16_t GetExtraInhabitantTagFunction = 0x392e; // = 14638

include/swift/AST/ASTMangler.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ class ASTMangler : public Mangler {
159159
DistributedThunk,
160160
DistributedAccessor,
161161
AccessibleFunctionRecord,
162-
AccessibleProtocolRequirementFunctionRecord,
163162
BackDeploymentThunk,
164163
BackDeploymentFallback,
165164
HasSymbolQuery,
@@ -246,6 +245,12 @@ class ASTMangler : public Mangler {
246245
Type GlobalActorBound,
247246
ModuleDecl *Module);
248247

248+
void appendDistributedThunk(const AbstractFunctionDecl *thunk,
249+
bool asReference);
250+
std::string mangleDistributedThunkRef(const AbstractFunctionDecl *thunk);
251+
/// Mangling for distributed function accessible function record.
252+
/// Used in Linking when emitting the record.
253+
std::string mangleDistributedThunkRecord(const AbstractFunctionDecl *thunk);
249254
std::string mangleDistributedThunk(const AbstractFunctionDecl *thunk);
250255

251256
/// Mangle a completion handler block implementation function, used for importing ObjC

include/swift/AST/TypeCheckRequests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,8 @@ class GetDistributedActorInvocationDecoderRequest :
13331333

13341334
/// Obtain the method that could be used to decode argument values passed
13351335
/// to a particular actor invocation type.
1336-
class GetDistributedActorArgumentDecodingMethodRequest :
1337-
public SimpleRequest<GetDistributedActorArgumentDecodingMethodRequest,
1336+
class GetDistributedActorConcreteArgumentDecodingMethodRequest :
1337+
public SimpleRequest<GetDistributedActorConcreteArgumentDecodingMethodRequest,
13381338
FuncDecl *(NominalTypeDecl *),
13391339
RequestFlags::Cached> {
13401340
public:

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ SWIFT_REQUEST(TypeChecker, GetDistributedRemoteCallArgumentInitFunctionRequest,
159159
SWIFT_REQUEST(TypeChecker, GetDistributedActorInvocationDecoderRequest,
160160
NominalTypeDecl *(NominalTypeDecl *),
161161
Cached, NoLocationInfo)
162-
SWIFT_REQUEST(TypeChecker, GetDistributedActorArgumentDecodingMethodRequest,
162+
SWIFT_REQUEST(TypeChecker, GetDistributedActorConcreteArgumentDecodingMethodRequest,
163163
FuncDecl *(NominalTypeDecl *),
164164
Cache, NoLocationInfo)
165165
SWIFT_REQUEST(TypeChecker, GlobalActorInstanceRequest,

include/swift/Demangling/DemangleNodes.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,6 @@ NODE(AsyncSuspendResumePartialFunction)
361361
NODE(AccessibleFunctionRecord)
362362
NODE(CompileTimeConst)
363363

364-
// Added in Swift 6.0
365-
NODE(AccessibleProtocolRequirementFunctionRecord)
366-
367364
// Added in Swift 5.7
368365
NODE(BackDeploymentThunk)
369366
NODE(BackDeploymentFallback)

include/swift/IRGen/Linking.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ class LinkEntity {
521521

522522
/// Accessible function record, which describes a function that can be
523523
/// looked up by name by the runtime.
524+
/// The pointer is a SILFunction*.
524525
AccessibleFunctionRecord,
525-
AccessibleProtocolRequirementFunctionRecord,
526526

527527
/// Extended existential type shape.
528528
/// Pointer is the (generalized) existential type.

include/swift/Runtime/AccessibleFunction.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424
namespace swift {
2525
namespace runtime {
2626

27-
SWIFT_RUNTIME_STDLIB_SPI
28-
const AccessibleFunctionRecord *swift_findAccessibleFunctionForConcreteType(
29-
bool findConcreteWitness,
30-
// concrete target type, when performing a protocol method call
31-
const char *targetActorTypeNameStart, size_t targetActorTypeNameLength,
32-
// method (concrete method name, or protocol method name)
33-
const char *targetNameStart, size_t targetNameLength);
34-
35-
// DEPRECATED: Prefer 'swift_findAccessibleFunctionForConcreteType'
3627
SWIFT_RUNTIME_STDLIB_SPI
3728
const AccessibleFunctionRecord *
3829
swift_findAccessibleFunction(const char *targetNameStart,

lib/AST/ASTMangler.cpp

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,6 @@ void ASTMangler::appendSymbolKind(SymbolKind SKind) {
922922
case SymbolKind::DistributedThunk: return appendOperator("TE");
923923
case SymbolKind::DistributedAccessor: return appendOperator("TF");
924924
case SymbolKind::AccessibleFunctionRecord: return appendOperator("HF");
925-
case SymbolKind::AccessibleProtocolRequirementFunctionRecord:
926-
return appendOperator("HpF");
927925
case SymbolKind::BackDeploymentThunk: return appendOperator("Twb");
928926
case SymbolKind::BackDeploymentFallback: return appendOperator("TwB");
929927
case SymbolKind::HasSymbolQuery: return appendOperator("TwS");
@@ -3904,11 +3902,13 @@ ASTMangler::mangleOpaqueTypeDescriptorRecord(const OpaqueTypeDecl *decl) {
39043902
return finalize();
39053903
}
39063904

3907-
std::string ASTMangler::mangleDistributedThunk(const AbstractFunctionDecl *thunk) {
3905+
void ASTMangler::appendDistributedThunk(
3906+
const AbstractFunctionDecl *thunk, bool asReference) {
39083907
// Marker protocols cannot be checked at runtime, so there is no point
39093908
// in recording them for distributed thunks.
39103909
llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(AllowMarkerProtocols,
39113910
false);
3911+
// TODO: add a flag to skip class/struct information from parameter types
39123912

39133913
// Since computed property SILDeclRef's refer to the "originator"
39143914
// of the thunk, we need to mangle distributed thunks of accessors
@@ -3931,8 +3931,52 @@ std::string ASTMangler::mangleDistributedThunk(const AbstractFunctionDecl *thunk
39313931
thunk = storage->getDistributedThunk();
39323932
assert(thunk);
39333933
}
3934+
assert(isa<AbstractFunctionDecl>(thunk) &&
3935+
"distributed thunk to mangle must be function decl");
3936+
assert(thunk->getContextKind() == DeclContextKind::AbstractFunctionDecl);
3937+
3938+
auto inProtocolExtensionMangleAsReference =
3939+
[&thunk, asReference]() -> ProtocolDecl * {
3940+
if (!asReference) {
3941+
return nullptr;
3942+
}
3943+
3944+
if (auto extension = dyn_cast<ExtensionDecl>(thunk->getDeclContext())) {
3945+
return dyn_cast_or_null<ProtocolDecl>(extension->getExtendedNominal());
3946+
}
3947+
return nullptr;
3948+
};
3949+
3950+
if (auto type = inProtocolExtensionMangleAsReference()) {
3951+
appendContext(type->getDeclContext(), thunk->getAlternateModuleName());
3952+
auto baseName = type->getBaseName();
3953+
appendIdentifier(Twine("$", baseName.getIdentifier().str()).str());
3954+
appendOperator("C"); // necessary for roundtrip, though we don't use it
3955+
} else {
3956+
appendContextOf(thunk);
3957+
}
39343958

3935-
return mangleEntity(thunk, SymbolKind::DistributedThunk);
3959+
appendIdentifier(thunk->getBaseName().getIdentifier().str());
3960+
appendDeclType(thunk, FunctionMangling);
3961+
appendOperator("F");
3962+
appendSymbolKind(SymbolKind::DistributedThunk);
3963+
}
3964+
3965+
std::string ASTMangler::mangleDistributedThunkRef(const AbstractFunctionDecl *thunk) {
3966+
beginMangling();
3967+
appendDistributedThunk(thunk, /*asReference=*/true);
3968+
return finalize();
3969+
}
3970+
std::string ASTMangler::mangleDistributedThunkRecord(const AbstractFunctionDecl *thunk) {
3971+
beginMangling();
3972+
appendDistributedThunk(thunk, /*asReference=*/true);
3973+
appendSymbolKind(SymbolKind::AccessibleFunctionRecord);
3974+
return finalize();
3975+
}
3976+
std::string ASTMangler::mangleDistributedThunk(const AbstractFunctionDecl *thunk) {
3977+
beginMangling();
3978+
appendDistributedThunk(thunk, /*asReference=*/false);
3979+
return finalize();
39363980
}
39373981

39383982
void ASTMangler::appendMacroExpansionContext(

lib/AST/DistributedDecl.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Type swift::getSerializationRequirementTypesForMember(
139139
return signature->getConcreteType(SerReqAssocType);
140140
}
141141

142-
llvm_unreachable("Unable to fetch ActorSystem type!");
142+
llvm_unreachable("Unable to fetch SerializationRequirement type!");
143143
}
144144

145145
Type swift::getDistributedActorSystemType(NominalTypeDecl *actor) {
@@ -325,11 +325,8 @@ Type ASTContext::getAssociatedTypeOfDistributedSystemOfActor(
325325

326326
FuncDecl*
327327
ASTContext::getDistributedActorArgumentDecodingMethod(NominalTypeDecl *actor) {
328-
if (!actor->isDistributedActor())
329-
return nullptr;
330-
331328
return evaluateOrDefault(
332-
evaluator, GetDistributedActorArgumentDecodingMethodRequest{actor}, nullptr);
329+
evaluator, GetDistributedActorConcreteArgumentDecodingMethodRequest{actor}, nullptr);
333330
}
334331

335332
NominalTypeDecl*

0 commit comments

Comments
 (0)