Skip to content

Commit cff02f8

Browse files
authored
Merge pull request #59926 from DougGregor/sink-actor-hop-for-get-access
Emit actor hop as part of call to the getter.
2 parents 02efc3a + bc8bd4e commit cff02f8

File tree

4 files changed

+86
-92
lines changed

4 files changed

+86
-92
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5826,13 +5826,15 @@ SILDeclRef SILGenModule::getAccessorDeclRef(AccessorDecl *accessor) {
58265826
}
58275827

58285828
/// Emit a call to a getter.
5829-
RValue SILGenFunction::emitGetAccessor(SILLocation loc, SILDeclRef get,
5830-
SubstitutionMap substitutions,
5831-
ArgumentSource &&selfValue, bool isSuper,
5832-
bool isDirectUse,
5833-
PreparedArguments &&subscriptIndices,
5834-
SGFContext c,
5835-
bool isOnSelfParameter) {
5829+
RValue SILGenFunction::emitGetAccessor(
5830+
SILLocation loc, SILDeclRef get,
5831+
SubstitutionMap substitutions,
5832+
ArgumentSource &&selfValue, bool isSuper,
5833+
bool isDirectUse,
5834+
PreparedArguments &&subscriptIndices,
5835+
SGFContext c,
5836+
bool isOnSelfParameter,
5837+
Optional<ImplicitActorHopTarget> implicitActorHopTarget) {
58365838
// Scope any further writeback just within this operation.
58375839
FormalEvaluationScope writebackScope(*this);
58385840

@@ -5843,6 +5845,9 @@ RValue SILGenFunction::emitGetAccessor(SILLocation loc, SILDeclRef get,
58435845
CanAnyFunctionType accessType = getter.getSubstFormalType();
58445846

58455847
CallEmission emission(*this, std::move(getter), std::move(writebackScope));
5848+
if (implicitActorHopTarget)
5849+
emission.setImplicitlyAsync(implicitActorHopTarget);
5850+
58465851
// Self ->
58475852
if (hasSelf) {
58485853
emission.addSelfParam(loc, std::move(selfValue),

lib/SILGen/SILGenFunction.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,12 +1440,14 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
14401440
CanType baseFormalType,
14411441
SILDeclRef accessor);
14421442

1443-
RValue emitGetAccessor(SILLocation loc, SILDeclRef getter,
1444-
SubstitutionMap substitutions,
1445-
ArgumentSource &&optionalSelfValue, bool isSuper,
1446-
bool isDirectAccessorUse,
1447-
PreparedArguments &&optionalSubscripts, SGFContext C,
1448-
bool isOnSelfParameter);
1443+
RValue emitGetAccessor(
1444+
SILLocation loc, SILDeclRef getter,
1445+
SubstitutionMap substitutions,
1446+
ArgumentSource &&optionalSelfValue, bool isSuper,
1447+
bool isDirectAccessorUse,
1448+
PreparedArguments &&optionalSubscripts, SGFContext C,
1449+
bool isOnSelfParameter,
1450+
Optional<ImplicitActorHopTarget> implicitActorHopTarget = None);
14491451

14501452
void emitSetAccessor(SILLocation loc, SILDeclRef setter,
14511453
SubstitutionMap substitutions,

lib/SILGen/SILGenLValue.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,26 +1641,26 @@ namespace {
16411641
assert(getAccessorDecl()->isGetter());
16421642

16431643
SILDeclRef getter = Accessor;
1644-
ExecutorBreadcrumb prevExecutor;
16451644
RValue rvalue;
1646-
{
1647-
FormalEvaluationScope scope(SGF);
1648-
1649-
// If the 'get' is in the context of the target's actor, do a hop first.
1650-
prevExecutor = SGF.emitHopToTargetActor(loc, ActorIso, base);
1651-
1652-
auto args =
1653-
std::move(*this).prepareAccessorArgs(SGF, loc, base, getter);
1645+
FormalEvaluationScope scope(SGF);
16541646

1655-
rvalue = SGF.emitGetAccessor(
1656-
loc, getter, Substitutions, std::move(args.base), IsSuper,
1657-
IsDirectAccessorUse, std::move(args.Indices), c,
1658-
IsOnSelfParameter);
1647+
// FIXME: This somewhat silly, because the original expression should
1648+
// already have one of these.
1649+
Optional<ImplicitActorHopTarget> implicitActorHopTarget;
1650+
if (ActorIso) {
1651+
implicitActorHopTarget = ActorIso->isGlobalActor()
1652+
? ImplicitActorHopTarget::forGlobalActor(
1653+
ActorIso->getGlobalActor())
1654+
: ImplicitActorHopTarget::forInstanceSelf();
1655+
}
16591656

1660-
} // End the evaluation scope before any hop back to the current executor.
1657+
auto args =
1658+
std::move(*this).prepareAccessorArgs(SGF, loc, base, getter);
16611659

1662-
// If we hopped to the target's executor, then we need to hop back.
1663-
prevExecutor.emit(SGF, loc);
1660+
rvalue = SGF.emitGetAccessor(
1661+
loc, getter, Substitutions, std::move(args.base), IsSuper,
1662+
IsDirectAccessorUse, std::move(args.Indices), c,
1663+
IsOnSelfParameter, implicitActorHopTarget);
16641664

16651665
return rvalue;
16661666
}

0 commit comments

Comments
 (0)