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"
@@ -265,59 +261,6 @@ struct AddressBaseComputingVisitor
265
261
266
262
} // namespace
267
263
268
- // / Determine the isolation of conformances that could be introduced by a cast from sourceType to
269
- // / destType.
270
- // /
271
- // /
272
- static SILIsolationInfo getIsolationForCastConformances (
273
- SILValue value, CanType sourceType, CanType destType) {
274
- // If the enclosing function is @concurrent, then a cast cannot pick up
275
- // any isolated conformances because it's not on any actor.
276
- auto function = value->getFunction ();
277
- auto functionIsolation = function->getActorIsolation ();
278
- if (functionIsolation && functionIsolation->isNonisolated ())
279
- return {};
280
-
281
- auto sendableMetatype =
282
- sourceType->getASTContext ().getProtocol (KnownProtocolKind::SendableMetatype);
283
- if (!sendableMetatype)
284
- return {};
285
-
286
- if (!destType.isAnyExistentialType ())
287
- return {};
288
-
289
- const auto &destLayout = destType.getExistentialLayout ();
290
- for (auto proto : destLayout.getProtocols ()) {
291
- if (proto->isMarkerProtocol ())
292
- continue ;
293
-
294
- // If the source type already conforms to the protocol, we won't be looking
295
- // it up dynamically.
296
- if (!lookupConformance (sourceType, proto, /* allowMissing=*/ false ).isInvalid ())
297
- continue ;
298
-
299
- // If the protocol inherits SendableMetatype, it can't have isolated
300
- // conformances.
301
- if (proto->inheritsFrom (sendableMetatype))
302
- continue ;
303
-
304
- // The cast can produce a conformance with the same isolation as this
305
- // function is dynamically executing. If that's known (i.e., because we're
306
- // on a global actor), the value is isolated to that global actor.
307
- // Otherwise, it's task-isolated.
308
- if (functionIsolation && functionIsolation->isGlobalActor ()) {
309
- return SILIsolationInfo::getGlobalActorIsolated (
310
- value, functionIsolation->getGlobalActor (), proto);
311
- }
312
-
313
- // Consider the cast to be task-isolated, because the runtime could find
314
- // a conformance that is isolated to the current context.
315
- return SILIsolationInfo::getTaskIsolated (value, proto);
316
- }
317
-
318
- return {};
319
- }
320
-
321
264
// / Classify an instructions as look through when we are looking through
322
265
// / values. We assert that all instructions that are CONSTANT_TRANSLATION
323
266
// / LookThrough to make sure they stay in sync.
@@ -381,7 +324,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
381
324
382
325
// If this cast introduces isolation due to conformances, we cannot look
383
326
// through it to the source.
384
- if (!getIsolationForCastConformances (
327
+ if (!SILIsolationInfo::getForCastConformances (
385
328
llvm::cast<UnconditionalCheckedCastInst>(inst),
386
329
cast.getSourceFormalType (), cast.getTargetFormalType ())
387
330
.isDisconnected ())
@@ -2189,13 +2132,6 @@ class PartitionOpTranslator {
2189
2132
return valueMap.lookupValueID (value);
2190
2133
}
2191
2134
2192
- // / Determine the isolation of a set of conformances.
2193
- // /
2194
- // / This function identifies potentially-isolated conformances that might affect the isolation of the given
2195
- // / value.
2196
- SILIsolationInfo getIsolationFromConformances (
2197
- SILValue value, ArrayRef<ProtocolConformanceRef> conformances);
2198
-
2199
2135
public:
2200
2136
// / Return the partition consisting of all function arguments.
2201
2137
// /
@@ -3970,7 +3906,7 @@ PartitionOpTranslator::visitPointerToAddressInst(PointerToAddressInst *ptai) {
3970
3906
3971
3907
TranslationSemantics PartitionOpTranslator::visitUnconditionalCheckedCastInst (
3972
3908
UnconditionalCheckedCastInst *ucci) {
3973
- auto isolation = getIsolationForCastConformances (
3909
+ auto isolation = SILIsolationInfo::getForCastConformances (
3974
3910
ucci, ucci->getSourceFormalType (), ucci->getTargetFormalType ());
3975
3911
3976
3912
if (isolation.isDisconnected () &&
@@ -3988,7 +3924,7 @@ TranslationSemantics PartitionOpTranslator::visitUnconditionalCheckedCastInst(
3988
3924
3989
3925
TranslationSemantics PartitionOpTranslator::visitUnconditionalCheckedCastAddrInst (
3990
3926
UnconditionalCheckedCastAddrInst *uccai) {
3991
- auto isolation = getIsolationForCastConformances (
3927
+ auto isolation = SILIsolationInfo::getForCastConformances (
3992
3928
uccai->getAllOperands ()[CopyLikeInstruction::Dest].get (),
3993
3929
uccai->getSourceFormalType (), uccai->getTargetFormalType ());
3994
3930
@@ -4086,58 +4022,9 @@ PartitionOpTranslator::visitPartialApplyInst(PartialApplyInst *pai) {
4086
4022
return TranslationSemantics::Special;
4087
4023
}
4088
4024
4089
- SILIsolationInfo
4090
- PartitionOpTranslator::getIsolationFromConformances (
4091
- SILValue value, ArrayRef<ProtocolConformanceRef> conformances) {
4092
- for (auto conformance: conformances) {
4093
- if (conformance.getProtocol ()->isMarkerProtocol ())
4094
- continue ;
4095
-
4096
- // If the conformance is a pack, recurse.
4097
- if (conformance.isPack ()) {
4098
- auto pack = conformance.getPack ();
4099
- for (auto innerConformance : pack->getPatternConformances ()) {
4100
- auto isolation = getIsolationFromConformances (value, innerConformance);
4101
- if (isolation)
4102
- return isolation;
4103
- }
4104
-
4105
- continue ;
4106
- }
4107
-
4108
- // If a concrete conformance is global-actor-isolated, then the resulting
4109
- // value must be.
4110
- if (conformance.isConcrete ()) {
4111
- auto isolation = conformance.getConcrete ()->getIsolation ();
4112
- if (isolation.isGlobalActor ()) {
4113
- return SILIsolationInfo::getGlobalActorIsolated (
4114
- value, isolation.getGlobalActor (), conformance.getProtocol ());
4115
- }
4116
-
4117
- continue ;
4118
- }
4119
-
4120
- // If an abstract conformance is for a non-SendableMetatype-conforming
4121
- // type, the resulting value is task-isolated.
4122
- if (conformance.isAbstract ()) {
4123
- auto sendableMetatype =
4124
- conformance.getType ()->getASTContext ()
4125
- .getProtocol (KnownProtocolKind::SendableMetatype);
4126
- if (sendableMetatype &&
4127
- lookupConformance (conformance.getType (), sendableMetatype,
4128
- /* allowMissing=*/ false ).isInvalid ()) {
4129
- return SILIsolationInfo::getTaskIsolated (value,
4130
- conformance.getProtocol ());
4131
- }
4132
- }
4133
- }
4134
-
4135
- return {};
4136
- }
4137
-
4138
4025
TranslationSemantics
4139
4026
PartitionOpTranslator::visitInitExistentialAddrInst (InitExistentialAddrInst *ieai) {
4140
- auto conformanceIsolationInfo = getIsolationFromConformances (
4027
+ auto conformanceIsolationInfo = SILIsolationInfo::getFromConformances (
4141
4028
ieai, ieai->getConformances ());
4142
4029
4143
4030
translateSILMultiAssign (ieai->getResults (),
@@ -4149,7 +4036,7 @@ PartitionOpTranslator::visitInitExistentialAddrInst(InitExistentialAddrInst *iea
4149
4036
4150
4037
TranslationSemantics
4151
4038
PartitionOpTranslator::visitInitExistentialRefInst (InitExistentialRefInst *ieri) {
4152
- auto conformanceIsolationInfo = getIsolationFromConformances (
4039
+ auto conformanceIsolationInfo = SILIsolationInfo::getFromConformances (
4153
4040
ieri, ieri->getConformances ());
4154
4041
4155
4042
translateSILMultiAssign (ieri->getResults (),
@@ -4161,7 +4048,7 @@ PartitionOpTranslator::visitInitExistentialRefInst(InitExistentialRefInst *ieri)
4161
4048
4162
4049
TranslationSemantics
4163
4050
PartitionOpTranslator::visitInitExistentialValueInst (InitExistentialValueInst *ievi) {
4164
- auto conformanceIsolationInfo = getIsolationFromConformances (
4051
+ auto conformanceIsolationInfo = SILIsolationInfo::getFromConformances (
4165
4052
ievi, ievi->getConformances ());
4166
4053
4167
4054
translateSILMultiAssign (ievi->getResults (),
@@ -4175,7 +4062,7 @@ TranslationSemantics
4175
4062
PartitionOpTranslator::visitCheckedCastBranchInst (CheckedCastBranchInst *ccbi) {
4176
4063
// Consider whether the value produced by the cast might be task-isolated.
4177
4064
auto resultValue = ccbi->getSuccessBB ()->getArgument (0 );
4178
- auto conformanceIsolation = getIsolationForCastConformances (
4065
+ auto conformanceIsolation = SILIsolationInfo::getForCastConformances (
4179
4066
resultValue,
4180
4067
ccbi->getSourceFormalType (),
4181
4068
ccbi->getTargetFormalType ());
@@ -4192,7 +4079,7 @@ TranslationSemantics PartitionOpTranslator::visitCheckedCastAddrBranchInst(
4192
4079
4193
4080
// Consider whether the value written into by the cast might be task-isolated.
4194
4081
auto resultValue = ccabi->getAllOperands ().back ().get ();
4195
- auto conformanceIsolation = getIsolationForCastConformances (
4082
+ auto conformanceIsolation = SILIsolationInfo::getForCastConformances (
4196
4083
resultValue,
4197
4084
ccabi->getSourceFormalType (),
4198
4085
ccabi->getTargetFormalType ());
0 commit comments