Skip to content

[CodeCompletion] Don’t compute isolated parameter captures during code completion #73659

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

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 16, 2024

Computing capture information requires a type checked AST, which we don’t have during code completion. To fix an assertion failure, don’t look for a captured isolated parameter while computing a closure’s actor isolation during code completion.

rdar://126923558

@ahoppen
Copy link
Member Author

ahoppen commented May 16, 2024

@swift-ci Please smoke test

Comment on lines +4176 to +4211
if (checkIsolatedCapture) {
if (auto param = closure->getCaptureInfo().getIsolatedParamCapture())
return ActorIsolation::forActorInstanceCapture(param)
.withPreconcurrency(preconcurrency);
} else {
// If we don't have capture information during code completion, assume
// that the closure captures the `isolated` parameter from the parent
// context.
return parentIsolation;
}
Copy link
Contributor

@hamishknight hamishknight May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess an alternative solution would be to call computeCaptures (or setCaptureInfo) for completion to just populate an empty set of captures. Can't say I really love either solution, but I think I would mildly prefer populating empty captures since it's less invasive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavapestov Do you have a preference on whether we should call computeCaptures in completion even though we know that it will compute incomplete captures or have a parameter like this? Hamish and I don’t have super strong opinions either way.

Comment on lines 7 to 15
func test(foo: isolated Foo) {
foo.#^COMPLETE^#
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case doesn't have any closures, does it trigger the crash without the fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes. Indeed. I was trying other things in there and then forgot to reset it. Thanks for noticing.

…e completion

Computing capture information requires a type checked AST, which we don’t have during code completion. To fix an assertion failure, don’t look for a captured `isolated` parameter while computing a closure’s actor isolation during code completion.

rdar://126923558
@ahoppen ahoppen force-pushed the ahoppen/fix-capture-crash branch from a7256b1 to 22f0daf Compare June 1, 2024 00:44
@ahoppen
Copy link
Member Author

ahoppen commented Jun 1, 2024

@swift-ci Please smoke test

@ahoppen ahoppen enabled auto-merge June 1, 2024 00:44
@ahoppen ahoppen merged commit ba773d5 into swiftlang:main Jun 1, 2024
3 checks passed
@ahoppen ahoppen deleted the ahoppen/fix-capture-crash branch June 7, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants