-
Notifications
You must be signed in to change notification settings - Fork 10.7k
[WIP][IDE]: surface inferred isolation information via sourcekit #89198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jamieQ
wants to merge
1
commit into
swiftlang:main
Choose a base branch
from
jamieQ:sourcekit-isolation-info
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // RUN: %target-swift-ide-test -print-inferred-isolation -source-filename %s | %FileCheck %s | ||
|
|
||
| @globalActor | ||
| actor MyActor { | ||
| static let shared = MyActor() | ||
| } | ||
|
|
||
| @MainActor | ||
| final class C { | ||
| var n = 0 | ||
|
|
||
| func work() async { | ||
| // Closure that inherits @MainActor from the enclosing context. | ||
| // CHECK: let inheritedMain = <inferred-isolation kind="closure" isolation="@MainActor">{</inferred-isolation> | ||
| let inheritedMain = { | ||
| self.n += 1 | ||
| } | ||
| inheritedMain() | ||
|
|
||
| // Detached closure: nonisolated regardless of enclosing context. | ||
| // CHECK: Task.detached <inferred-isolation kind="closure" isolation="nonisolated">{</inferred-isolation> | ||
| Task.detached { | ||
| print("detached") | ||
| } | ||
|
|
||
| // Task closure inherits the actor context. | ||
| // CHECK: Task <inferred-isolation kind="closure" isolation="@MainActor">{</inferred-isolation> | ||
| Task { | ||
| self.n += 1 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func freeFunc() { | ||
| // Closure outside any isolated context -- nonisolated. | ||
| // CHECK: let f = <inferred-isolation kind="closure" isolation="nonisolated">{</inferred-isolation> 1 } | ||
| let f = { 1 } | ||
| _ = f() | ||
| } | ||
|
|
||
| // Closures whose isolation is *written* in the signature must not be tagged, | ||
| // since the information is already on screen. | ||
|
|
||
| func explicitMain() { | ||
| // CHECK: let g = { @MainActor in 2 } | ||
| // CHECK-NOT: <inferred-isolation {{[^>]*}}>{</inferred-isolation> @MainActor | ||
| let g = { @MainActor in 2 } | ||
| _ = g | ||
| } | ||
|
|
||
| func explicitCustom() { | ||
| // CHECK: let h = { @MyActor in 3 } | ||
| // CHECK-NOT: <inferred-isolation {{[^>]*}}>{</inferred-isolation> @MyActor | ||
| let h = { @MyActor in 3 } | ||
| _ = h | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| @MainActor | ||
| final class C { | ||
| var n = 0 | ||
|
|
||
| func work() async { | ||
| let inheritedMain = { | ||
| self.n += 1 | ||
| } | ||
| inheritedMain() | ||
|
|
||
| Task.detached { | ||
| print("detached") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // RUN: %sourcekitd-test -req=collect-inferred-isolation %s -- %s | %FileCheck %s | ||
|
|
||
| // CHECK: key.results: [ | ||
| // CHECK-NEXT: { | ||
| // CHECK-NEXT: key.kind: "closure", | ||
| // CHECK-NEXT: key.offset: {{[0-9]+}}, | ||
| // CHECK-NEXT: key.length: {{[0-9]+}}, | ||
| // CHECK-NEXT: key.actor_isolation: "@MainActor" | ||
| // CHECK-NEXT: }, | ||
| // CHECK-NEXT: { | ||
| // CHECK-NEXT: key.kind: "closure", | ||
| // CHECK-NEXT: key.offset: {{[0-9]+}}, | ||
| // CHECK-NEXT: key.length: {{[0-9]+}}, | ||
| // CHECK-NEXT: key.actor_isolation: "@concurrent" | ||
| // CHECK-NEXT: } | ||
| // CHECK-NEXT: ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| @MainActor | ||
| final class C { | ||
| var n = 0 | ||
|
|
||
| func work() async { | ||
| let inheritedMain = { | ||
| self.n += 1 | ||
| } | ||
| _ = inheritedMain | ||
|
|
||
| Task.detached { | ||
| print("detached") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Range covering only the first closure. | ||
| // We should see only the @MainActor entry. | ||
| // | ||
| // RUN: %sourcekitd-test -req=collect-inferred-isolation -pos=6:1 -length=60 %s -- %s | %FileCheck %s --check-prefix=INHERITED | ||
|
|
||
| // INHERITED: key.results: [ | ||
| // INHERITED-NEXT: { | ||
| // INHERITED-NEXT: key.kind: "closure", | ||
| // INHERITED-NEXT: key.offset: {{[0-9]+}}, | ||
| // INHERITED-NEXT: key.length: {{[0-9]+}}, | ||
| // INHERITED-NEXT: key.actor_isolation: "@MainActor" | ||
| // INHERITED-NEXT: } | ||
| // INHERITED-NEXT: ] | ||
|
|
||
| // Range covering only the second closure. | ||
| // see only the nonisolated entry; the first closure must be filtered out. | ||
| // | ||
| // RUN: %sourcekitd-test -req=collect-inferred-isolation -pos=9:1 -length=100 %s -- %s | %FileCheck %s --check-prefix=DETACHED | ||
|
|
||
| // DETACHED: key.results: [ | ||
| // DETACHED-NEXT: { | ||
| // DETACHED-NEXT: key.kind: "closure", | ||
| // DETACHED-NEXT: key.offset: {{[0-9]+}}, | ||
| // DETACHED-NEXT: key.length: {{[0-9]+}}, | ||
| // DETACHED-NEXT: key.actor_isolation: "@concurrent" | ||
| // DETACHED-NEXT: } | ||
| // DETACHED-NEXT: ] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the best thing to surface is here... In diagnostics this usually prints the variable name of the isolated param or whatever, which we could probably also do, but it would require some additional plumbing I think.