Skip to content

Optimize keypaths in language 6 mode #81139

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
Apr 29, 2025

Conversation

eeckstein
Copy link
Contributor

In language 6 mode keypath instructions are created as existentials and the optimizer needs to look through the open_existential_ref instructions to recognize a keypath.

rdar://150173106

In language 6 mode keypath instructions are created as existentials and the optimizer needs to look through the `open_existential_ref` instructions to recognize a keypath.

rdar://150173106
@eeckstein eeckstein requested a review from aschwaighofer April 28, 2025 13:52
@eeckstein
Copy link
Contributor Author

@swift-ci test

@slavapestov
Copy link
Contributor

What changes in Swift 6 mode?

@eeckstein
Copy link
Contributor Author

What changes in Swift 6 mode?

keypath literals are created as existentials:

  %2 = keypath $any WritableKeyPath<Element, Int> & Sendable, (root $Element; stored_property #Element.id : $Int) // user: %3
  %3 = open_existential_ref %2 to $@opened("C446880C-244A-11F0-AE41-0EA13E3AABB1", any WritableKeyPath<Element, Int> & Sendable) Self // user: %4

@dnadoba
Copy link
Contributor

dnadoba commented Apr 28, 2025

Swift 6 mode enables -enable-upcoming-feature InferSendableFromCaptures which causes & Sendable to be inferred.

@slavapestov
Copy link
Contributor

Ah I see.

Copy link
Contributor

@aschwaighofer aschwaighofer left a comment

Choose a reason for hiding this comment

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

lgtm

@xedin
Copy link
Contributor

xedin commented Apr 28, 2025

Yes, key path type-checking is different due to InferSendableFromCaptures, maybe we should be doing something else on the Sema side instead?

@eeckstein eeckstein merged commit 376651d into swiftlang:main Apr 29, 2025
5 checks passed
@eeckstein eeckstein deleted the keypath-optimization branch April 29, 2025 06:16
@eeckstein
Copy link
Contributor Author

maybe we should be doing something else on the Sema side instead?

Anyway, with this change, the optimizer can handle the existential keypath

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.

5 participants