Skip to content

[Distributed] NFC: Remove Method from accessor APIs #40699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ASTMangler : public Mangler {
SwiftAsObjCThunk,
ObjCAsSwiftThunk,
DistributedThunk,
DistributedMethodAccessor,
DistributedAccessor,
AccessibleFunctionRecord
};

Expand Down
2 changes: 1 addition & 1 deletion include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ CONTEXT_NODE(Destructor)
CONTEXT_NODE(DidSet)
NODE(Directness)
NODE(DistributedThunk)
NODE(DistributedMethodAccessor)
NODE(DistributedAccessor)
NODE(DynamicAttribute)
NODE(DirectMethodReferenceAttribute)
NODE(DynamicSelf)
Expand Down
22 changes: 11 additions & 11 deletions include/swift/IRGen/Linking.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@ class LinkEntity {
KnownAsyncFunctionPointer,

/// The pointer is SILFunction*
DistributedMethodAccessor,
/// An async function pointer for a distributed method accessor.
DistributedAccessor,
/// An async function pointer for a distributed accessor (method or property).
/// The pointer is a SILFunction*.
DistributedMethodAccessorAsyncPointer,
DistributedAccessorAsyncPointer,

/// Accessible function record, which describes a function that can be
/// looked up by name by the runtime.
Expand Down Expand Up @@ -1246,10 +1246,10 @@ class LinkEntity {
Kind, unsigned(LinkEntity::Kind::PartialApplyForwarderAsyncFunctionPointer));
break;

case LinkEntity::Kind::DistributedMethodAccessor: {
case LinkEntity::Kind::DistributedAccessor: {
entity.Data = LINKENTITY_SET_FIELD(
Kind,
unsigned(LinkEntity::Kind::DistributedMethodAccessorAsyncPointer));
unsigned(LinkEntity::Kind::DistributedAccessorAsyncPointer));
break;
}

Expand Down Expand Up @@ -1280,12 +1280,12 @@ class LinkEntity {
return entity;
}

static LinkEntity forDistributedMethodAccessor(SILFunction *method) {
static LinkEntity forDistributedTargetAccessor(SILFunction *target) {
LinkEntity entity;
entity.Pointer = method;
entity.Pointer = target;
entity.SecondaryPointer = nullptr;
entity.Data =
LINKENTITY_SET_FIELD(Kind, unsigned(Kind::DistributedMethodAccessor));
LINKENTITY_SET_FIELD(Kind, unsigned(Kind::DistributedAccessor));
return entity;
}

Expand Down Expand Up @@ -1329,9 +1329,9 @@ class LinkEntity {
Kind, unsigned(LinkEntity::Kind::PartialApplyForwarder));
break;

case LinkEntity::Kind::DistributedMethodAccessorAsyncPointer:
case LinkEntity::Kind::DistributedAccessorAsyncPointer:
entity.Data = LINKENTITY_SET_FIELD(
Kind, unsigned(LinkEntity::Kind::DistributedMethodAccessor));
Kind, unsigned(LinkEntity::Kind::DistributedAccessor));
break;

default:
Expand Down Expand Up @@ -1382,7 +1382,7 @@ class LinkEntity {
getKind() == Kind::DynamicallyReplaceableFunctionVariable ||
getKind() == Kind::DynamicallyReplaceableFunctionKey ||
getKind() == Kind::SILFunction ||
getKind() == Kind::DistributedMethodAccessor ||
getKind() == Kind::DistributedAccessor ||
getKind() == Kind::AccessibleFunctionRecord;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ void ASTMangler::appendSymbolKind(SymbolKind SKind) {
case SymbolKind::SwiftAsObjCThunk: return appendOperator("To");
case SymbolKind::ObjCAsSwiftThunk: return appendOperator("TO");
case SymbolKind::DistributedThunk: return appendOperator("TE");
case SymbolKind::DistributedMethodAccessor: return appendOperator("TF");
case SymbolKind::DistributedAccessor: return appendOperator("TF");
case SymbolKind::AccessibleFunctionRecord: return appendOperator("HF");
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) {
case Node::Kind::OutlinedBridgedMethod:
case Node::Kind::MergedFunction:
case Node::Kind::DistributedThunk:
case Node::Kind::DistributedMethodAccessor:
case Node::Kind::DistributedAccessor:
case Node::Kind::DynamicallyReplaceableFunctionImpl:
case Node::Kind::DynamicallyReplaceableFunctionKey:
case Node::Kind::DynamicallyReplaceableFunctionVar:
Expand Down Expand Up @@ -2367,7 +2367,7 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
case 'D': return createNode(Node::Kind::DynamicAttribute);
case 'd': return createNode(Node::Kind::DirectMethodReferenceAttribute);
case 'E': return createNode(Node::Kind::DistributedThunk);
case 'F': return createNode(Node::Kind::DistributedMethodAccessor);
case 'F': return createNode(Node::Kind::DistributedAccessor);
case 'a': return createNode(Node::Kind::PartialApplyObjCForwarder);
case 'A': return createNode(Node::Kind::PartialApplyForwarder);
case 'm': return createNode(Node::Kind::MergedFunction);
Expand Down
6 changes: 3 additions & 3 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ class NodePrinter {
case Node::Kind::ProtocolConformanceRefInProtocolModule:
case Node::Kind::ProtocolConformanceRefInOtherModule:
case Node::Kind::DistributedThunk:
case Node::Kind::DistributedMethodAccessor:
case Node::Kind::DistributedAccessor:
case Node::Kind::DynamicallyReplaceableFunctionKey:
case Node::Kind::DynamicallyReplaceableFunctionImpl:
case Node::Kind::DynamicallyReplaceableFunctionVar:
Expand Down Expand Up @@ -2001,9 +2001,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
Printer << "distributed thunk for ";
}
return nullptr;
case Node::Kind::DistributedMethodAccessor:
case Node::Kind::DistributedAccessor:
if (!Options.ShortenThunk) {
Printer << "distributed method accessor for ";
Printer << "distributed accessor for ";
}
return nullptr;
case Node::Kind::AccessibleFunctionRecord:
Expand Down
2 changes: 1 addition & 1 deletion lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ Remangler::mangleDistributedThunk(Node *node, unsigned depth) {
}

ManglingError
Remangler::mangleDistributedMethodAccessor(Node *node, unsigned depth) {
Remangler::mangleDistributedAccessor(Node *node, unsigned depth) {
Buffer << "TF";
return ManglingError::Success;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ ManglingError Remangler::mangleGlobal(Node *node, unsigned depth) {
case Node::Kind::DirectMethodReferenceAttribute:
case Node::Kind::MergedFunction:
case Node::Kind::DistributedThunk:
case Node::Kind::DistributedMethodAccessor:
case Node::Kind::DistributedAccessor:
case Node::Kind::DynamicallyReplaceableFunctionKey:
case Node::Kind::DynamicallyReplaceableFunctionImpl:
case Node::Kind::DynamicallyReplaceableFunctionVar:
Expand Down Expand Up @@ -2251,7 +2251,7 @@ Remangler::mangleDistributedThunk(Node *node, unsigned depth) {
}

ManglingError
Remangler::mangleDistributedMethodAccessor(Node *node, unsigned depth) {
Remangler::mangleDistributedAccessor(Node *node, unsigned depth) {
Buffer << "TF";
return ManglingError::Success;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4150,7 +4150,7 @@ void IRGenModule::emitAccessibleFunctions() {
llvm::Constant *funcAddr = nullptr;
if (func->isDistributed()) {
funcAddr = getAddrOfAsyncFunctionPointer(
LinkEntity::forDistributedMethodAccessor(func));
LinkEntity::forDistributedTargetAccessor(func));
} else if (func->isAsync()) {
funcAddr = getAddrOfAsyncFunctionPointer(func);
} else {
Expand Down
66 changes: 33 additions & 33 deletions lib/IRGen/GenDistributed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DistributedAccessor {
IRGenFunction &IGF;

/// Underlying distributed method for this accessor.
SILFunction *Method;
SILFunction *Target;

/// The interface type of this accessor function.
CanSILFunctionType AccessorType;
Expand All @@ -86,25 +86,25 @@ class DistributedAccessor {
SmallVector<AllocationInfo, 4> AllocatedArguments;

public:
DistributedAccessor(IRGenFunction &IGF, SILFunction *method,
DistributedAccessor(IRGenFunction &IGF, SILFunction *target,
CanSILFunctionType accessorTy);

void emit();

private:
void computeArguments(llvm::Value *argumentBuffer, Explosion &arguments);

FunctionPointer getPointerToMethod() const;
FunctionPointer getPointerToTarget() const;

Callee getCalleeForDistributedMethod(llvm::Value *self) const;
Callee getCalleeForDistributedTarget(llvm::Value *self) const;
};

} // end namespace

/// Compute a type of a distributed method accessor function based
/// on the provided distributed method.
static CanSILFunctionType getAccessorType(IRGenModule &IGM,
SILFunction *DistMethod) {
SILFunction *Target) {
auto &Context = IGM.Context;

auto getRawPointerParmeter = [&]() {
Expand All @@ -120,10 +120,10 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
.withAsync()
.build();

auto methodTy = DistMethod->getLoweredFunctionType();
auto targetTy = Target->getLoweredFunctionType();

assert(methodTy->isAsync());
assert(methodTy->hasErrorResult());
assert(targetTy->isAsync());
assert(targetTy->hasErrorResult());

// Accessor gets argument value buffer and a reference to `self` of
// the actor and produces a call to the distributed thunk forwarding
Expand All @@ -133,18 +133,18 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
ParameterConvention::Direct_Guaranteed,
{/*argumentBuffer=*/getRawPointerParmeter(),
/*resultBuffer=*/getRawPointerParmeter(),
/*actor=*/methodTy->getParameters().back()},
/*actor=*/targetTy->getParameters().back()},
/*Yields=*/{},
/*Results=*/{},
/*ErrorResult=*/methodTy->getErrorResult(),
/*ErrorResult=*/targetTy->getErrorResult(),
/*patternSubs=*/SubstitutionMap(),
/*invocationSubs=*/SubstitutionMap(), Context);
}

llvm::Function *
IRGenModule::getAddrOfDistributedMethodAccessor(SILFunction *F,
IRGenModule::getAddrOfDistributedTargetAccessor(SILFunction *F,
ForDefinition_t forDefinition) {
auto entity = LinkEntity::forDistributedMethodAccessor(F);
auto entity = LinkEntity::forDistributedTargetAccessor(F);

llvm::Function *&entry = GlobalFuncs[entity];
if (entry) {
Expand All @@ -159,21 +159,21 @@ IRGenModule::getAddrOfDistributedMethodAccessor(SILFunction *F,
return createFunction(*this, link, signature);
}

void IRGenModule::emitDistributedMethodAccessor(SILFunction *method) {
assert(method->isDistributed());
void IRGenModule::emitDistributedTargetAccessor(SILFunction *target) {
assert(target->isDistributed());

auto *f = getAddrOfDistributedMethodAccessor(method, ForDefinition);
auto *f = getAddrOfDistributedTargetAccessor(target, ForDefinition);
if (!f->isDeclaration())
return;

IRGenFunction IGF(*this, f);
DistributedAccessor(IGF, method, getAccessorType(*this, method)).emit();
DistributedAccessor(IGF, target, getAccessorType(*this, target)).emit();
}

DistributedAccessor::DistributedAccessor(IRGenFunction &IGF,
SILFunction *method,
SILFunction *target,
CanSILFunctionType accessorTy)
: IGM(IGF.IGM), IGF(IGF), Method(method), AccessorType(accessorTy),
: IGM(IGF.IGM), IGF(IGF), Target(target), AccessorType(accessorTy),
AsyncLayout(getAsyncContextLayout(
IGM, AccessorType, AccessorType, SubstitutionMap(),
/*suppress generics*/ true,
Expand All @@ -182,7 +182,7 @@ DistributedAccessor::DistributedAccessor(IRGenFunction &IGF,

void DistributedAccessor::computeArguments(llvm::Value *argumentBuffer,
Explosion &arguments) {
auto fnType = Method->getLoweredFunctionType();
auto fnType = Target->getLoweredFunctionType();

// Cover all of the arguments except to `self` of the actor.
auto parameters = fnType->getParameters().drop_back();
Expand Down Expand Up @@ -283,8 +283,8 @@ void DistributedAccessor::computeArguments(llvm::Value *argumentBuffer,
}

void DistributedAccessor::emit() {
auto methodTy = Method->getLoweredFunctionType();
SILFunctionConventions targetConv(methodTy, IGF.getSILModule());
auto targetTy = Target->getLoweredFunctionType();
SILFunctionConventions targetConv(targetTy, IGF.getSILModule());
SILFunctionConventions accessorConv(AccessorType, IGF.getSILModule());
TypeExpansionContext expansionContext = IGM.getMaximalTypeExpansionContext();

Expand All @@ -306,7 +306,7 @@ void DistributedAccessor::emit() {
// Reference to a `self` of the actor to be called.
auto *actorSelf = params.claimNext();

GenericContextScope scope(IGM, methodTy->getInvocationGenericSignature());
GenericContextScope scope(IGM, targetTy->getInvocationGenericSignature());

// Preliminary: Setup async context for this accessor.
{
Expand All @@ -315,7 +315,7 @@ void DistributedAccessor::emit() {
/*useSpecialConvention*/ false)
.getAsyncContextIndex();

auto entity = LinkEntity::forDistributedMethodAccessor(Method);
auto entity = LinkEntity::forDistributedTargetAccessor(Target);
emitAsyncFunctionEntry(IGF, AsyncLayout, entity, asyncContextIdx);
emitAsyncFunctionPointer(IGM, IGF.CurFn, entity, AsyncLayout.getSize());
}
Expand All @@ -341,7 +341,7 @@ void DistributedAccessor::emit() {
Explosion result;
Explosion error;

auto callee = getCalleeForDistributedMethod(actorSelf);
auto callee = getCalleeForDistributedTarget(actorSelf);
auto emission =
getCallEmission(IGF, callee.getSwiftContext(), std::move(callee));

Expand All @@ -363,7 +363,7 @@ void DistributedAccessor::emit() {
// Both accessor and distributed method are always `async throws`
// so we need to load error value (if any) from the slot.
{
assert(methodTy->hasErrorResult());
assert(targetTy->hasErrorResult());

SILType errorType = accessorConv.getSILErrorType(expansionContext);
Address calleeErrorSlot =
Expand All @@ -386,23 +386,23 @@ void DistributedAccessor::emit() {
}
}

FunctionPointer DistributedAccessor::getPointerToMethod() const {
auto fnType = Method->getLoweredFunctionType();
auto fpKind = classifyFunctionPointerKind(Method);
FunctionPointer DistributedAccessor::getPointerToTarget() const {
auto fnType = Target->getLoweredFunctionType();
auto fpKind = classifyFunctionPointerKind(Target);
auto signature = IGM.getSignature(fnType, fpKind.useSpecialConvention());

auto *fnPtr =
llvm::ConstantExpr::getBitCast(IGM.getAddrOfAsyncFunctionPointer(Method),
llvm::ConstantExpr::getBitCast(IGM.getAddrOfAsyncFunctionPointer(Target),
signature.getType()->getPointerTo());

return FunctionPointer::forDirect(
FunctionPointer::Kind(fnType), fnPtr,
IGM.getAddrOfSILFunction(Method, NotForDefinition), signature);
IGM.getAddrOfSILFunction(Target, NotForDefinition), signature);
}

Callee
DistributedAccessor::getCalleeForDistributedMethod(llvm::Value *self) const {
auto fnType = Method->getLoweredFunctionType();
DistributedAccessor::getCalleeForDistributedTarget(llvm::Value *self) const {
auto fnType = Target->getLoweredFunctionType();
CalleeInfo info{fnType, fnType, SubstitutionMap()};
return {std::move(info), getPointerToMethod(), self};
return {std::move(info), getPointerToTarget(), self};
}
4 changes: 2 additions & 2 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1643,10 +1643,10 @@ private: \
Address getAddrOfObjCISAMask();

llvm::Function *
getAddrOfDistributedMethodAccessor(SILFunction *F,
getAddrOfDistributedTargetAccessor(SILFunction *F,
ForDefinition_t forDefinition);

void emitDistributedMethodAccessor(SILFunction *method);
void emitDistributedTargetAccessor(SILFunction *method);

/// Retrieve the generic signature for the current generic context, or null if no
/// generic environment is active.
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ void IRGenSILFunction::emitSILFunction() {
// Emit distributed accessor, and mark the thunk as accessible
// by name at runtime through it.
if (CurSILFn->isDistributed() && CurSILFn->isThunk()) {
IGM.emitDistributedMethodAccessor(CurSILFn);
IGM.emitDistributedTargetAccessor(CurSILFn);
IGM.addAccessibleFunction(CurSILFn);
}

Expand Down
Loading