Skip to content

[Observation] Add type annotation on cached keypaths #78842

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

porglezomp
Copy link
Contributor

Having a KeyPath with an inferred type that contains a "some" type gives an error, like:

error: property definition has inferred type '...', involving the 'some' return type of another declaration

This is not diagnosed if there is an explicit type, so add an explicit type for the cached keypath when the property has an annotated type. This doesn't resolve cases where there is no type annotation on a property and the inferred type contains a some type, but this can always be resolved by adding an explicit type.

rdar://143466616

Having a KeyPath with an inferred type that contains a "some" type gives
an error, like:

  error: property definition has inferred type '...', involving the
   'some' return type of another declaration

This is not diagnosed if there is an explicit type, so add an explicit
type for the cached keypath when the property has an annotated type.
This doesn't resolve cases where there is no type annotation on a
property and the inferred type contains a `some` type, but this can
always be resolved by adding an explicit type.

rdar://143466616
@porglezomp porglezomp requested a review from a team as a code owner January 23, 2025 10:25
}

/*
// FIXME: This case is not handled yet. Properties that have no type annotation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question for reviewers: I don't know how best to handle this case.

The simplest thing to do is just disable the optimization when there's no explicit type, but that's an annoying performance hazard when it's idiomatic to use an inferred type for most default-initialized properties.

It's very simple to fix the rare case where this fails (just add a type annotation) but that's still leaving in a source break.

@porglezomp
Copy link
Contributor Author

@swift-ci please smoke test

1 similar comment
@glessard
Copy link
Contributor

@swift-ci please smoke test

@porglezomp
Copy link
Contributor Author

I guess this will be superseded by #78853 disabling the optimization entirely

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