[SR-15694] make isolation inference + override more consistent #41662
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During actor isolation inference, we would unconditionally choose the
isolation of the overridden decl (when, say, there is no attribute on the decl).
The overridden decl is identified with
getOverriddenDecl
.This works mostly fine, but initializers have some unusual overridden decls
returned by that method. For example, in the following code:
that method claims that
FooFrame.init()
overridesPictureFrame.init()
, whenit really does not! So, if we were to unconditionally take the isolation from
PictureFrame.init()
(and thusNSObject.init()
), then we'd infer thatFooFrame.init()
has unspecified isolation, despite the nominal it resides inbeing marked as
MainActor
. This is in essence the problem in SR-15694, whereplacing the isolation directly on the initializer fixes this issue.
If
FooFrame.init()
really does override, then why can it beMainActor
? Well,we have a rule in one part of the type-checker saying that if an ObjC-imported
decl has unspecified isolation, then overriding it with isolation is permitted.
But the other part of the type-checker dealing with the isolation inference was
not permitting that.
So, this patch unifies how actor-isolation inference is conducted to reuse that
same logic. In addition, the inference now effectively says that, if the decl
has no inferred isolation, or the inferred isolation is invalid according to the
overriding rules, then we use the isolation of the overridden decl. This
preserves the old behavior of the inference, while also fixing this issue with
ObjC declarations by expanding where isolation is allowed.
For example, as a consequence of this change, in the following code:
if
NotIsolatedPictureFrame
is a plain-old not-isolated class imported fromObjective-C, then
rotate
will now haveMainActor
isolation, instead ofhaving unspecified isolation like it was inferred to have previously. This
helps make things consistent, because
rotate
is allowed to be@MainActor
ifit were explicitly marked as such.
resolves rdar://87217618 / SR-15694