Skip to content

Commit 172d9b2

Browse files
xedinktoso
authored andcommitted
[Distributed] Generate thunk for accessor as a regular method
It used to be an accessor but that is not required because SILDeclRef controls mangling which is the most imprortant and could be used to emit the right reference.
1 parent 4963fda commit 172d9b2

File tree

5 files changed

+32
-45
lines changed

5 files changed

+32
-45
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,21 +3190,6 @@ void ASTMangler::appendEntity(const ValueDecl *decl) {
31903190
// Handle accessors specially, they are mangled as modifiers on the accessed
31913191
// declaration.
31923192
if (auto accessor = dyn_cast<AccessorDecl>(decl)) {
3193-
// Distributed thunks associated with computed properties
3194-
// are currently implemented as accessors but they don't
3195-
// have to be and that could be changed in the future.
3196-
//
3197-
// Let's mangle them as `distributed func`s to make it easier
3198-
// to change implementation and because runtime needs a function
3199-
// type associated with the thunk to form a call to it.
3200-
if (accessor->isDistributedThunk()) {
3201-
appendContextOf(decl);
3202-
appendDeclName(accessor->getStorage());
3203-
appendDeclType(accessor, FunctionMangling);
3204-
appendOperator("F");
3205-
return;
3206-
}
3207-
32083193
return appendAccessorEntity(
32093194
getCodeForAccessorKind(accessor->getAccessorKind()),
32103195
accessor->getStorage(), accessor->isStatic());
@@ -3504,5 +3489,28 @@ std::string ASTMangler::mangleDistributedThunk(const AbstractFunctionDecl *thunk
35043489
// in recording them for distributed thunks.
35053490
llvm::SaveAndRestore<bool> savedAllowMarkerProtocols(AllowMarkerProtocols,
35063491
false);
3492+
3493+
// Since computed property SILDeclRef's refer to the "originator"
3494+
// of the thunk, we need to mangle distributed thunks of accessors
3495+
// specially.
3496+
if (auto *accessor = dyn_cast<AccessorDecl>(thunk)) {
3497+
// TODO: This needs to use accessor type instead of
3498+
// distributed thunk after all SILDeclRefs are switched
3499+
// to use "originator" instead of the thunk itself.
3500+
//
3501+
// ```
3502+
// beginMangling();
3503+
// appendContextOf(thunk);
3504+
// appendDeclName(accessor->getStorage());
3505+
// appendDeclType(accessor, FunctionMangling);
3506+
// appendOperator("F");
3507+
// appendSymbolKind(SymbolKind::DistributedThunk);
3508+
// return finalize();
3509+
// ```
3510+
auto *storage = accessor->getStorage();
3511+
thunk = storage->getDistributedThunk();
3512+
assert(thunk);
3513+
}
3514+
35073515
return mangleEntity(thunk, SymbolKind::DistributedThunk);
35083516
}

lib/SILGen/SILGenLValue.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,13 +3386,14 @@ void LValue::addMemberVarComponent(SILGenFunction &SGF, SILLocation loc,
33863386

33873387
void emitUsingDistributedThunk() {
33883388
auto *var = cast<VarDecl>(Storage);
3389-
SILDeclRef accessor(var->getDistributedThunk(), SILDeclRef::Kind::Func,
3389+
SILDeclRef accessor(var->getAccessor(AccessorKind::Get),
3390+
SILDeclRef::Kind::Func,
33903391
/*isForeign=*/false, /*isDistributed=*/true);
33913392

33923393
auto typeData = getLogicalStorageTypeData(
33933394
SGF.getTypeExpansionContext(), SGF.SGM, AccessKind, FormalRValueType);
33943395

3395-
asImpl().emitUsingGetterSetter(accessor, /*isDirect=*/false, typeData);
3396+
asImpl().emitUsingGetterSetter(accessor, /*isDirect=*/true, typeData);
33963397
}
33973398

33983399
} emitter(SGF, loc, var, subs, isSuper, accessKind,

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -695,25 +695,10 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
695695
}
696696
ParameterList *params = ParameterList::create(C, paramDecls); // = funcParams->clone(C);
697697

698-
FuncDecl *thunk = nullptr;
699-
if (auto *accessor = dyn_cast<AccessorDecl>(func)) {
700-
auto *distributedVar = cast<VarDecl>(accessor->getStorage());
701-
702-
thunk = AccessorDecl::create(
703-
C, /*declLoc=*/accessor->getLoc(), /*accessorKeywordLoc=*/SourceLoc(),
704-
AccessorKind::Get, distributedVar,
705-
/*staticLoc=*/SourceLoc(), StaticSpellingKind::None,
706-
/*async=*/true, /*asyncLoc=*/SourceLoc(),
707-
/*throws=*/true, /*throwsLoc=*/SourceLoc(), genericParamList, params,
708-
func->getResultInterfaceType(), accessor->getDeclContext());
709-
710-
thunk->setImplicit();
711-
} else {
712-
thunk = FuncDecl::createImplicit(
713-
C, swift::StaticSpellingKind::None, func->getName(), SourceLoc(),
714-
/*async=*/true, /*throws=*/true, genericParamList, params,
715-
func->getResultInterfaceType(), DC);
716-
}
698+
FuncDecl *thunk = FuncDecl::createImplicit(
699+
C, swift::StaticSpellingKind::None, thunkName, SourceLoc(),
700+
/*async=*/true, /*throws=*/true, genericParamList, params,
701+
func->getResultInterfaceType(), DC);
717702

718703
assert(thunk && "couldn't create a distributed thunk");
719704

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,10 +1428,7 @@ static void diagRecursivePropertyAccess(const Expr *E, const DeclContext *DC) {
14281428
if (MRE->getAccessSemantics() == AccessSemantics::Ordinary) {
14291429
bool shouldDiagnose = false;
14301430
// Warn about any property access in the getter.
1431-
//
1432-
// Distributed thunks have to refer to the "local" version
1433-
// of the property directly with implicit `self.` base.
1434-
if (Accessor->isGetter() && !Accessor->isDistributedThunk())
1431+
if (Accessor->isGetter())
14351432
shouldDiagnose = !isStore;
14361433
// Warn about stores in the setter, but allow loads.
14371434
if (Accessor->isSetter())

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,11 +3854,7 @@ bool HasIsolatedSelfRequest::evaluate(
38543854

38553855
// For accessors, consider the storage declaration.
38563856
if (auto accessor = dyn_cast<AccessorDecl>(value)) {
3857-
// distributed thunks are accessors only in spirit and
3858-
// should be handled as regular functions from isolation
3859-
// perspective.
3860-
if (!accessor->isDistributedThunk())
3861-
value = accessor->getStorage();
3857+
value = accessor->getStorage();
38623858
}
38633859

38643860
// Check whether this member can be isolated to an actor at all.

0 commit comments

Comments
 (0)