15
15
#include " swift/SILOptimizer/Analysis/RegionAnalysis.h"
16
16
17
17
#include " swift/AST/ASTWalker.h"
18
- #include " swift/AST/ConformanceLookup.h"
19
18
#include " swift/AST/DiagnosticsSIL.h"
20
19
#include " swift/AST/Expr.h"
21
- #include " swift/AST/ExistentialLayout.h"
22
- #include " swift/AST/PackConformance.h"
23
- #include " swift/AST/ProtocolConformance.h"
24
20
#include " swift/AST/Type.h"
25
21
#include " swift/Basic/Assertions.h"
26
22
#include " swift/Basic/FrozenMultiMap.h"
@@ -274,59 +270,6 @@ struct AddressBaseComputingVisitor
274
270
275
271
} // namespace
276
272
277
- // / Determine the isolation of conformances that could be introduced by a cast from sourceType to
278
- // / destType.
279
- // /
280
- // /
281
- static SILIsolationInfo getIsolationForCastConformances (
282
- SILValue value, CanType sourceType, CanType destType) {
283
- // If the enclosing function is @concurrent, then a cast cannot pick up
284
- // any isolated conformances because it's not on any actor.
285
- auto function = value->getFunction ();
286
- auto functionIsolation = function->getActorIsolation ();
287
- if (functionIsolation && functionIsolation->isNonisolated ())
288
- return {};
289
-
290
- auto sendableMetatype =
291
- sourceType->getASTContext ().getProtocol (KnownProtocolKind::SendableMetatype);
292
- if (!sendableMetatype)
293
- return {};
294
-
295
- if (!destType.isAnyExistentialType ())
296
- return {};
297
-
298
- const auto &destLayout = destType.getExistentialLayout ();
299
- for (auto proto : destLayout.getProtocols ()) {
300
- if (proto->isMarkerProtocol ())
301
- continue ;
302
-
303
- // If the source type already conforms to the protocol, we won't be looking
304
- // it up dynamically.
305
- if (!lookupConformance (sourceType, proto, /* allowMissing=*/ false ).isInvalid ())
306
- continue ;
307
-
308
- // If the protocol inherits SendableMetatype, it can't have isolated
309
- // conformances.
310
- if (proto->inheritsFrom (sendableMetatype))
311
- continue ;
312
-
313
- // The cast can produce a conformance with the same isolation as this
314
- // function is dynamically executing. If that's known (i.e., because we're
315
- // on a global actor), the value is isolated to that global actor.
316
- // Otherwise, it's task-isolated.
317
- if (functionIsolation && functionIsolation->isGlobalActor ()) {
318
- return SILIsolationInfo::getGlobalActorIsolated (
319
- value, functionIsolation->getGlobalActor (), proto);
320
- }
321
-
322
- // Consider the cast to be task-isolated, because the runtime could find
323
- // a conformance that is isolated to the current context.
324
- return SILIsolationInfo::getTaskIsolated (value, proto);
325
- }
326
-
327
- return {};
328
- }
329
-
330
273
// / Classify an instructions as look through when we are looking through
331
274
// / values. We assert that all instructions that are CONSTANT_TRANSLATION
332
275
// / LookThrough to make sure they stay in sync.
@@ -391,7 +334,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
391
334
392
335
// If this cast introduces isolation due to conformances, we cannot look
393
336
// through it to the source.
394
- if (!getIsolationForCastConformances (
337
+ if (!SILIsolationInfo::getForCastConformances (
395
338
llvm::cast<UnconditionalCheckedCastInst>(inst),
396
339
cast.getSourceFormalType (), cast.getTargetFormalType ())
397
340
.isDisconnected ())
@@ -2231,13 +2174,6 @@ class PartitionOpTranslator {
2231
2174
return valueMap.lookupValueID (value);
2232
2175
}
2233
2176
2234
- // / Determine the isolation of a set of conformances.
2235
- // /
2236
- // / This function identifies potentially-isolated conformances that might affect the isolation of the given
2237
- // / value.
2238
- SILIsolationInfo getIsolationFromConformances (
2239
- SILValue value, ArrayRef<ProtocolConformanceRef> conformances);
2240
-
2241
2177
public:
2242
2178
// / Return the partition consisting of all function arguments.
2243
2179
// /
@@ -4014,7 +3950,7 @@ PartitionOpTranslator::visitPointerToAddressInst(PointerToAddressInst *ptai) {
4014
3950
4015
3951
TranslationSemantics PartitionOpTranslator::visitUnconditionalCheckedCastInst (
4016
3952
UnconditionalCheckedCastInst *ucci) {
4017
- auto isolation = getIsolationForCastConformances (
3953
+ auto isolation = SILIsolationInfo::getForCastConformances (
4018
3954
ucci, ucci->getSourceFormalType (), ucci->getTargetFormalType ());
4019
3955
4020
3956
if (isolation.isDisconnected () &&
@@ -4032,7 +3968,7 @@ TranslationSemantics PartitionOpTranslator::visitUnconditionalCheckedCastInst(
4032
3968
4033
3969
TranslationSemantics PartitionOpTranslator::visitUnconditionalCheckedCastAddrInst (
4034
3970
UnconditionalCheckedCastAddrInst *uccai) {
4035
- auto isolation = getIsolationForCastConformances (
3971
+ auto isolation = SILIsolationInfo::getForCastConformances (
4036
3972
uccai->getAllOperands ()[CopyLikeInstruction::Dest].get (),
4037
3973
uccai->getSourceFormalType (), uccai->getTargetFormalType ());
4038
3974
@@ -4130,58 +4066,9 @@ PartitionOpTranslator::visitPartialApplyInst(PartialApplyInst *pai) {
4130
4066
return TranslationSemantics::Special;
4131
4067
}
4132
4068
4133
- SILIsolationInfo
4134
- PartitionOpTranslator::getIsolationFromConformances (
4135
- SILValue value, ArrayRef<ProtocolConformanceRef> conformances) {
4136
- for (auto conformance: conformances) {
4137
- if (conformance.getProtocol ()->isMarkerProtocol ())
4138
- continue ;
4139
-
4140
- // If the conformance is a pack, recurse.
4141
- if (conformance.isPack ()) {
4142
- auto pack = conformance.getPack ();
4143
- for (auto innerConformance : pack->getPatternConformances ()) {
4144
- auto isolation = getIsolationFromConformances (value, innerConformance);
4145
- if (isolation)
4146
- return isolation;
4147
- }
4148
-
4149
- continue ;
4150
- }
4151
-
4152
- // If a concrete conformance is global-actor-isolated, then the resulting
4153
- // value must be.
4154
- if (conformance.isConcrete ()) {
4155
- auto isolation = conformance.getConcrete ()->getIsolation ();
4156
- if (isolation.isGlobalActor ()) {
4157
- return SILIsolationInfo::getGlobalActorIsolated (
4158
- value, isolation.getGlobalActor (), conformance.getProtocol ());
4159
- }
4160
-
4161
- continue ;
4162
- }
4163
-
4164
- // If an abstract conformance is for a non-SendableMetatype-conforming
4165
- // type, the resulting value is task-isolated.
4166
- if (conformance.isAbstract ()) {
4167
- auto sendableMetatype =
4168
- conformance.getType ()->getASTContext ()
4169
- .getProtocol (KnownProtocolKind::SendableMetatype);
4170
- if (sendableMetatype &&
4171
- lookupConformance (conformance.getType (), sendableMetatype,
4172
- /* allowMissing=*/ false ).isInvalid ()) {
4173
- return SILIsolationInfo::getTaskIsolated (value,
4174
- conformance.getProtocol ());
4175
- }
4176
- }
4177
- }
4178
-
4179
- return {};
4180
- }
4181
-
4182
4069
TranslationSemantics
4183
4070
PartitionOpTranslator::visitInitExistentialAddrInst (InitExistentialAddrInst *ieai) {
4184
- auto conformanceIsolationInfo = getIsolationFromConformances (
4071
+ auto conformanceIsolationInfo = SILIsolationInfo::getFromConformances (
4185
4072
ieai, ieai->getConformances ());
4186
4073
4187
4074
translateSILMultiAssign (ieai->getResults (),
@@ -4193,7 +4080,7 @@ PartitionOpTranslator::visitInitExistentialAddrInst(InitExistentialAddrInst *iea
4193
4080
4194
4081
TranslationSemantics
4195
4082
PartitionOpTranslator::visitInitExistentialRefInst (InitExistentialRefInst *ieri) {
4196
- auto conformanceIsolationInfo = getIsolationFromConformances (
4083
+ auto conformanceIsolationInfo = SILIsolationInfo::getFromConformances (
4197
4084
ieri, ieri->getConformances ());
4198
4085
4199
4086
translateSILMultiAssign (ieri->getResults (),
@@ -4205,7 +4092,7 @@ PartitionOpTranslator::visitInitExistentialRefInst(InitExistentialRefInst *ieri)
4205
4092
4206
4093
TranslationSemantics
4207
4094
PartitionOpTranslator::visitInitExistentialValueInst (InitExistentialValueInst *ievi) {
4208
- auto conformanceIsolationInfo = getIsolationFromConformances (
4095
+ auto conformanceIsolationInfo = SILIsolationInfo::getFromConformances (
4209
4096
ievi, ievi->getConformances ());
4210
4097
4211
4098
translateSILMultiAssign (ievi->getResults (),
@@ -4219,7 +4106,7 @@ TranslationSemantics
4219
4106
PartitionOpTranslator::visitCheckedCastBranchInst (CheckedCastBranchInst *ccbi) {
4220
4107
// Consider whether the value produced by the cast might be task-isolated.
4221
4108
auto resultValue = ccbi->getSuccessBB ()->getArgument (0 );
4222
- auto conformanceIsolation = getIsolationForCastConformances (
4109
+ auto conformanceIsolation = SILIsolationInfo::getForCastConformances (
4223
4110
resultValue,
4224
4111
ccbi->getSourceFormalType (),
4225
4112
ccbi->getTargetFormalType ());
@@ -4236,7 +4123,7 @@ TranslationSemantics PartitionOpTranslator::visitCheckedCastAddrBranchInst(
4236
4123
4237
4124
// Consider whether the value written into by the cast might be task-isolated.
4238
4125
auto resultValue = ccabi->getAllOperands ().back ().get ();
4239
- auto conformanceIsolation = getIsolationForCastConformances (
4126
+ auto conformanceIsolation = SILIsolationInfo::getForCastConformances (
4240
4127
resultValue,
4241
4128
ccabi->getSourceFormalType (),
4242
4129
ccabi->getTargetFormalType ());
0 commit comments