Skip to content

Commit 8c4dea9

Browse files
authored
Revert "[concurrency] Add support for HopToMainActorIfNeededThunk." (#79938)
* Revert "[concurrency] Add support for HopToMainActorIfNeededThunk." This reverts commit 0e0665b. * remove some last bits of 0e0665b
1 parent 1a08018 commit 8c4dea9

27 files changed

+1
-729
lines changed

include/swift/AST/SILThunkKind.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ struct SILThunkKind {
3434
/// purposes of the underlying thunking machinery.
3535
Identity = 1,
3636

37-
/// A thunk that checks if a value is on the main actor and if it isn't
38-
/// jumps to the main actor. It expects that the passed in function does not
39-
/// have any arguments, results, is synchronous, and does not throw.
40-
HopToMainActorIfNeeded = 2,
41-
42-
MaxValue = HopToMainActorIfNeeded,
37+
MaxValue = Identity,
4338
};
4439

4540
InnerTy innerTy;
@@ -73,8 +68,6 @@ struct SILThunkKind {
7368
return Demangle::MangledSILThunkKind::Invalid;
7469
case Identity:
7570
return Demangle::MangledSILThunkKind::Identity;
76-
case HopToMainActorIfNeeded:
77-
return Demangle::MangledSILThunkKind::HopToMainActorIfNeeded;
7871
}
7972
}
8073
};

include/swift/Basic/Features.def

-3
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,6 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(CoroutineAccessors, true)
476476
/// modify/read single-yield coroutines always execute code post-yield code
477477
EXPERIMENTAL_FEATURE(CoroutineAccessorsUnwindOnCallerError, false)
478478

479-
/// When a parameter has unspecified isolation, infer it as main actor isolated.
480-
EXPERIMENTAL_FEATURE(GenerateForceToMainActorThunks, false)
481-
482479
EXPERIMENTAL_FEATURE(AddressableParameters, true)
483480
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AddressableTypes, true)
484481

include/swift/Demangling/Demangle.h

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ enum class MangledDifferentiabilityKind : char {
141141
enum class MangledSILThunkKind : char {
142142
Invalid = 0,
143143
Identity = 'I',
144-
HopToMainActorIfNeeded = 'H',
145144
};
146145

147146
/// The pass that caused the specialization to occur. We use this to make sure

include/swift/Demangling/DemangleNodes.def

-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ NODE(ReflectionMetadataSuperclassDescriptor)
294294
NODE(GenericTypeParamDecl)
295295
NODE(CurryThunk)
296296
NODE(SILThunkIdentity)
297-
NODE(SILThunkHopToMainActorIfNeeded)
298297
NODE(DispatchThunk)
299298
NODE(MethodDescriptor)
300299
NODE(ProtocolRequirementsBaseDescriptor)

include/swift/SIL/SILBuilder.h

-7
Original file line numberDiff line numberDiff line change
@@ -1239,13 +1239,6 @@ class SILBuilder {
12391239
return createThunk(Loc, Op, ThunkInst::Kind::Identity, substitutionMap);
12401240
}
12411241

1242-
ThunkInst *
1243-
createHopToMainActorIfNeededThunk(SILLocation Loc, SILValue Op,
1244-
SubstitutionMap substitutionMap = {}) {
1245-
return createThunk(Loc, Op, ThunkInst::Kind::HopToMainActorIfNeeded,
1246-
substitutionMap);
1247-
}
1248-
12491242
ConvertEscapeToNoEscapeInst *
12501243
createConvertEscapeToNoEscape(SILLocation Loc, SILValue Op, SILType Ty,
12511244
bool lifetimeGuaranteed) {

lib/AST/FeatureSet.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ UNINTERESTING_FEATURE(ExtractConstantsFromMembers)
199199
UNINTERESTING_FEATURE(GroupActorErrors)
200200
UNINTERESTING_FEATURE(SameElementRequirements)
201201
UNINTERESTING_FEATURE(UnspecifiedMeansMainActorIsolated)
202-
UNINTERESTING_FEATURE(GenerateForceToMainActorThunks)
203202

204203
static bool usesFeatureSendingArgsAndResults(Decl *decl) {
205204
auto isFunctionTypeWithSending = [](Type type) {

lib/Demangling/Demangler.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -2859,9 +2859,6 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
28592859
switch (nextChar()) {
28602860
case 'I':
28612861
return createWithChild(Node::Kind::SILThunkIdentity, popNode(isEntity));
2862-
case 'H':
2863-
return createWithChild(Node::Kind::SILThunkHopToMainActorIfNeeded,
2864-
popNode(isEntity));
28652862
default:
28662863
return nullptr;
28672864
}

lib/Demangling/NodePrinter.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ class NodePrinter {
369369
case Node::Kind::CoroutineContinuationPrototype:
370370
case Node::Kind::CurryThunk:
371371
case Node::Kind::SILThunkIdentity:
372-
case Node::Kind::SILThunkHopToMainActorIfNeeded:
373372
case Node::Kind::DispatchThunk:
374373
case Node::Kind::Deallocator:
375374
case Node::Kind::IsolatedDeallocator:
@@ -1454,10 +1453,6 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
14541453
Printer << "identity thunk of ";
14551454
print(Node->getChild(0), depth + 1);
14561455
return nullptr;
1457-
case Node::Kind::SILThunkHopToMainActorIfNeeded:
1458-
Printer << "hop to main actor thunk of ";
1459-
print(Node->getChild(0), depth + 1);
1460-
return nullptr;
14611456
case Node::Kind::DispatchThunk:
14621457
Printer << "dispatch thunk of ";
14631458
print(Node->getChild(0), depth + 1);

lib/Demangling/OldRemangler.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -2545,12 +2545,6 @@ ManglingError Remangler::mangleSILThunkIdentity(Node *node, unsigned depth) {
25452545
return ManglingError::Success;
25462546
}
25472547

2548-
ManglingError Remangler::mangleSILThunkHopToMainActorIfNeeded(Node *node,
2549-
unsigned depth) {
2550-
Buffer << "<sil-hop-to-main-actor-if-needed-thunk>";
2551-
return ManglingError::Success;
2552-
}
2553-
25542548
ManglingError Remangler::mangleDispatchThunk(Node *node, unsigned depth) {
25552549
Buffer << "<dispatch-thunk>";
25562550
return ManglingError::Success;

lib/Demangling/Remangler.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -3403,14 +3403,6 @@ ManglingError Remangler::mangleSILThunkIdentity(Node *node, unsigned depth) {
34033403
return ManglingError::Success;
34043404
}
34053405

3406-
ManglingError Remangler::mangleSILThunkHopToMainActorIfNeeded(Node *node,
3407-
unsigned depth) {
3408-
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1)); // type
3409-
Buffer << "TT"
3410-
<< "H";
3411-
return ManglingError::Success;
3412-
}
3413-
34143406
ManglingError Remangler::mangleDispatchThunk(Node *node, unsigned depth) {
34153407
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
34163408
Buffer << "Tj";

lib/SIL/IR/SILInstructions.cpp

-39
Original file line numberDiff line numberDiff line change
@@ -2818,42 +2818,6 @@ bool ConvertFunctionInst::onlyConvertsSendable() const {
28182818
getNonSendableFuncType(getType());
28192819
}
28202820

2821-
static CanSILFunctionType getDerivedFunctionTypeForHopToMainActorIfNeeded(
2822-
SILFunction *fn, CanSILFunctionType inputFunctionType,
2823-
SubstitutionMap subMap) {
2824-
inputFunctionType = inputFunctionType->substGenericArgs(
2825-
fn->getModule(), subMap, fn->getTypeExpansionContext());
2826-
bool needsSubstFunctionType = false;
2827-
for (auto param : inputFunctionType->getParameters()) {
2828-
needsSubstFunctionType |= param.getInterfaceType()->hasTypeParameter();
2829-
}
2830-
for (auto result : inputFunctionType->getResults()) {
2831-
needsSubstFunctionType |= result.getInterfaceType()->hasTypeParameter();
2832-
}
2833-
for (auto yield : inputFunctionType->getYields()) {
2834-
needsSubstFunctionType |= yield.getInterfaceType()->hasTypeParameter();
2835-
}
2836-
2837-
SubstitutionMap appliedSubs;
2838-
if (needsSubstFunctionType) {
2839-
appliedSubs = inputFunctionType->getCombinedSubstitutions();
2840-
}
2841-
2842-
auto extInfoBuilder =
2843-
inputFunctionType->getExtInfo()
2844-
.intoBuilder()
2845-
.withRepresentation(SILFunctionType::Representation::Thick)
2846-
.withIsPseudogeneric(false);
2847-
2848-
return SILFunctionType::get(
2849-
nullptr, extInfoBuilder.build(), inputFunctionType->getCoroutineKind(),
2850-
ParameterConvention::Direct_Guaranteed,
2851-
inputFunctionType->getParameters(), inputFunctionType->getYields(),
2852-
inputFunctionType->getResults(),
2853-
inputFunctionType->getOptionalErrorResult(), appliedSubs,
2854-
SubstitutionMap(), inputFunctionType->getASTContext());
2855-
}
2856-
28572821
static CanSILFunctionType
28582822
getDerivedFunctionTypeForIdentityThunk(SILFunction *fn,
28592823
CanSILFunctionType inputFunctionType,
@@ -2906,9 +2870,6 @@ ThunkInst::Kind::getDerivedFunctionType(SILFunction *fn,
29062870
case Identity:
29072871
return getDerivedFunctionTypeForIdentityThunk(fn, inputFunctionType,
29082872
subMap);
2909-
case HopToMainActorIfNeeded:
2910-
return getDerivedFunctionTypeForHopToMainActorIfNeeded(
2911-
fn, inputFunctionType, subMap);
29122873
}
29132874

29142875
llvm_unreachable("Covered switch isn't covered?!");

lib/SIL/IR/SILPrinter.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -2148,9 +2148,6 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
21482148
case ThunkInst::Kind::Identity:
21492149
*this << "[identity] ";
21502150
break;
2151-
case ThunkInst::Kind::HopToMainActorIfNeeded:
2152-
*this << "[hop_to_mainactor_if_needed] ";
2153-
break;
21542151
}
21552152
*this << Ctx.getID(ti->getOperand());
21562153
printSubstitutions(

lib/SIL/Parser/ParseSIL.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -4113,8 +4113,6 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
41134113

41144114
auto kind = llvm::StringSwitch<ThunkInst::Kind>(attrName)
41154115
.Case("identity", ThunkInst::Kind::Identity)
4116-
.Case("hop_to_mainactor_if_needed",
4117-
ThunkInst::Kind::HopToMainActorIfNeeded)
41184116
.Default(ThunkInst::Kind::Invalid);
41194117
if (!kind) {
41204118
P.diagnose(OpcodeLoc, diag::sil_thunkinst_failed_to_parse_kind, attrName);

lib/SIL/Verifier/SILVerifier.cpp

-21
Original file line numberDiff line numberDiff line change
@@ -5248,27 +5248,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
52485248
require(resTI == ti->getThunkKind().getDerivedFunctionType(
52495249
ti->getFunction(), objTI, ti->getSubstitutionMap()),
52505250
"resTI is not the thunk kind assigned derived function type");
5251-
5252-
auto originalCalleeFuncType =
5253-
ti->getOperand()->getType().castTo<SILFunctionType>();
5254-
5255-
switch (ti->getThunkKind()) {
5256-
case ThunkInst::Kind::Invalid:
5257-
break;
5258-
case ThunkInst::Kind::Identity:
5259-
break;
5260-
case ThunkInst::Kind::HopToMainActorIfNeeded:
5261-
require(originalCalleeFuncType->getParameters().empty(),
5262-
"Hop To Main Actor If Needed cannot have any parameters");
5263-
require(originalCalleeFuncType->getResults().empty(),
5264-
"Hop To Main Actor If Needed cannot have any results");
5265-
// We require that hop_to_main_actor inputs do not an error since we
5266-
// have to have no results.
5267-
require(!originalCalleeFuncType->hasErrorResult(),
5268-
"HopToMainActorIfNeeded thunks cannot have input without an "
5269-
"error result");
5270-
break;
5271-
}
52725251
}
52735252

52745253
void checkConvertEscapeToNoEscapeInst(ConvertEscapeToNoEscapeInst *ICI) {

lib/SILGen/ManagedValue.h

-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ class ManagedValue {
332332
assert(!hasCleanup());
333333
return getValue();
334334
}
335-
336335
/// Treat getValue() as used so that we can access the value directly when
337336
/// debugging without needing to interpret the flag field.
338337
LLVM_ATTRIBUTE_USED

lib/SILGen/SILGenBuilder.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -1228,17 +1228,3 @@ ManagedValue SILGenBuilder::borrowObjectRValue(SILGenFunction &SGF,
12281228
}
12291229
return SGF.emitFormalEvaluationManagedBeginBorrow(loc, value);
12301230
}
1231-
1232-
ManagedValue SILGenBuilder::createHopToMainActorIfNeededThunk(
1233-
SILLocation loc, ManagedValue op, SubstitutionMap substitutionMap) {
1234-
if (op.getOwnershipKind() == OwnershipKind::None) {
1235-
auto *thunkedFunc = createHopToMainActorIfNeededThunk(
1236-
loc, op.forward(getSILGenFunction()), substitutionMap);
1237-
return SGF.emitManagedRValueWithCleanup(thunkedFunc);
1238-
}
1239-
1240-
CleanupCloner cloner(*this, op);
1241-
auto *thunkedFunc = createHopToMainActorIfNeededThunk(
1242-
loc, op.forward(getSILGenFunction()), substitutionMap);
1243-
return cloner.clone(thunkedFunc);
1244-
}

lib/SILGen/SILGenBuilder.h

-5
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,6 @@ class SILGenBuilder : public SILBuilder {
544544

545545
createTupleAddrConstructor(loc, destAddr, values, isInitOfDest);
546546
}
547-
548-
using SILBuilder::createHopToMainActorIfNeededThunk;
549-
ManagedValue
550-
createHopToMainActorIfNeededThunk(SILLocation loc, ManagedValue op,
551-
SubstitutionMap substitutionMap = {});
552547
};
553548

554549
} // namespace Lowering

lib/SILGen/SILGenFunction.cpp

-44
Original file line numberDiff line numberDiff line change
@@ -1111,50 +1111,6 @@ SILGenFunction::emitClosureValue(SILLocation loc, SILDeclRef constant,
11111111
}
11121112
}
11131113

1114-
// If GenerateForceToMainActorThunks and Dynamic Actor Isolation Checking is
1115-
// enabled and we have a synchronous function...
1116-
if (F.getASTContext().LangOpts.hasFeature(
1117-
Feature::GenerateForceToMainActorThunks) &&
1118-
F.getASTContext().LangOpts.isDynamicActorIsolationCheckingEnabled() &&
1119-
!functionTy.castTo<SILFunctionType>()->isAsync()) {
1120-
1121-
// See if that function is a closure which requires dynamic isolation
1122-
// checking that doesn't take any parameters or results. In such a case, we
1123-
// create a hop to main actor if needed thunk.
1124-
if (auto *closureExpr = constant.getClosureExpr()) {
1125-
if (closureExpr->requiresDynamicIsolationChecking()) {
1126-
auto actorIsolation = closureExpr->getActorIsolation();
1127-
switch (actorIsolation) {
1128-
case ActorIsolation::Unspecified:
1129-
case ActorIsolation::Nonisolated:
1130-
case ActorIsolation::CallerIsolationInheriting:
1131-
case ActorIsolation::NonisolatedUnsafe:
1132-
case ActorIsolation::ActorInstance:
1133-
break;
1134-
1135-
case ActorIsolation::Erased:
1136-
llvm_unreachable("closure cannot have erased isolation");
1137-
1138-
case ActorIsolation::GlobalActor:
1139-
// For now only do this if we are using the main actor and are calling
1140-
// a function that doesn't depend on its result and doesn't have any
1141-
// parameters.
1142-
//
1143-
// NOTE: Since errors are results, this means that we cannot do this
1144-
// for throwing functions.
1145-
if (auto *args = closureExpr->getArgs();
1146-
(!args || args->empty()) && actorIsolation.isMainActor() &&
1147-
closureExpr->getResultType()->getCanonicalType() ==
1148-
B.getASTContext().TheEmptyTupleType &&
1149-
!result.getType().castTo<SILFunctionType>()->hasErrorResult()) {
1150-
result = B.createHopToMainActorIfNeededThunk(loc, result, subs);
1151-
}
1152-
break;
1153-
}
1154-
}
1155-
}
1156-
}
1157-
11581114
return result;
11591115
}
11601116

0 commit comments

Comments
 (0)