Skip to content

SILGen: Skip emitting distributed thunks for skipped accessors #69451

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
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
8 changes: 1 addition & 7 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,13 +1416,7 @@ void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
emitNativeToForeignThunk(thunk);
}

if (auto thunkDecl = AFD->getDistributedThunk()) {
if (!thunkDecl->isBodySkipped()) {
auto thunk = SILDeclRef(thunkDecl).asDistributed();
emitFunctionDefinition(SILDeclRef(thunkDecl).asDistributed(),
getFunction(thunk, ForDefinition));
}
}
emitDistributedThunkForDecl(AFD);

if (AFD->isBackDeployed(M.getASTContext())) {
// Emit the fallback function that will be used when the original function
Expand Down
5 changes: 5 additions & 0 deletions lib/SILGen/SILGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
/// Emits a thunk from an actor function to a potentially distributed call.
void emitDistributedThunk(SILDeclRef thunk);

/// Emits the distributed actor thunk for the decl if there is one associated
/// with it.
void emitDistributedThunkForDecl(
llvm::PointerUnion<AbstractFunctionDecl *, VarDecl *> varOrAFD);

/// Returns true if the given declaration must be referenced through a
/// back deployment thunk in a context with the given resilience expansion.
bool requiresBackDeploymentThunk(ValueDecl *decl,
Expand Down
17 changes: 17 additions & 0 deletions lib/SILGen/SILGenThunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ void SILGenModule::emitNativeToForeignThunk(SILDeclRef thunk) {
emitFunctionDefinition(thunk, getFunction(thunk, ForDefinition));
}

void SILGenModule::emitDistributedThunkForDecl(
llvm::PointerUnion<AbstractFunctionDecl *, VarDecl *> varOrAFD) {
FuncDecl *thunkDecl =
varOrAFD.is<AbstractFunctionDecl *>()
? varOrAFD.get<AbstractFunctionDecl *>()->getDistributedThunk()
: varOrAFD.get<VarDecl *>()->getDistributedThunk();
if (!thunkDecl)
return;

if (thunkDecl->isBodySkipped())
return;

auto thunk = SILDeclRef(thunkDecl).asDistributed();
emitFunctionDefinition(SILDeclRef(thunkDecl).asDistributed(),
getFunction(thunk, ForDefinition));
}

void SILGenModule::emitDistributedThunk(SILDeclRef thunk) {
// Thunks are always emitted by need, so don't need delayed emission.
assert(thunk.isDistributedThunk() && "distributed thunks only");
Expand Down
14 changes: 2 additions & 12 deletions lib/SILGen/SILGenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,12 +1223,7 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
SGM.emitPropertyWrapperBackingInitializer(vd);
}

if (auto *thunk = vd->getDistributedThunk()) {
auto thunkRef = SILDeclRef(thunk).asDistributed();
SGM.emitFunctionDefinition(thunkRef,
SGM.getFunction(thunkRef, ForDefinition));
}

SGM.emitDistributedThunkForDecl(vd);
visitAbstractStorageDecl(vd);
}

Expand Down Expand Up @@ -1404,12 +1399,7 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
}
}

if (auto *thunk = vd->getDistributedThunk()) {
auto thunkRef = SILDeclRef(thunk).asDistributed();
SGM.emitFunctionDefinition(thunkRef,
SGM.getFunction(thunkRef, ForDefinition));
}

SGM.emitDistributedThunkForDecl(vd);
visitAbstractStorageDecl(vd);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@ import Distributed

public distributed actor DA {
public typealias ActorSystem = LocalTestingDistributedActorSystem

// CHECK-NOT: s38distributed_thunk_skip_function_bodies2DAC9publicVarSiyYaKFTE
distributed var publicVar: Int {
let NEVER_TYPECHECK = 1
blackHole(NEVER_TYPECHECK)
return 1
}
}

@inline(never)
public func blackHole<T>(_ t: T) { }

extension DA {
// CHECK-NOT: s38distributed_thunk_skip_function_bodies2DAC20publicVarInExtensionSiyYaKFTE
distributed var publicVarInExtension: Int {
let NEVER_TYPECHECK = 1
blackHole(NEVER_TYPECHECK)
return 1
}

// CHECK-NOT: s38distributed_thunk_skip_function_bodies2DAC10publicFuncyyYaKFTE
public distributed func publicFunc() {
Expand Down