-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[lifetimes] add same-type default lifetime inference #85998
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
base: main
Are you sure you want to change the base?
Conversation
|
@swift-ci test |
bde35c9 to
54cf136
Compare
| // CHECK: @$s30lifetime_depend_infer_defaults014sameTypeParam_ef5InoutG02ne5mutNEAA0K0VAF_AFztF : $@convention(thin) (@guaranteed NE, @lifetime(copy 1) @inout NE) -> @lifetime(copy 0) @owned NE | ||
| func sameTypeParam_sameTypeInoutParam(ne: NE, mutNE: inout NE) -> NE { ne } | ||
|
|
||
| struct NonEscapableSelf: ~Escapable { |
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.
Please add some tests where the outer nominal is generic, and the method is generic, otherwise you won’t spot the incorrect usage of interface types and archetypes I pointed out in the review
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.
@slavapestov I did not expect this case to work with the current PR, but it does
protocol P_NE {
associatedtype T: ~Escapable
}
protocol Q_NE {
associatedtype U: ~Escapable
}
struct AssociatedNE<P: P_NE, Q: Q_NE> {}
extension AssociatedNE where P.T == Q.U {
func foo(a: P.T) -> Q.U {...}
}
Mapping Q.U into foos environment normalizes it to P.T so the trivial type comparison succeeds
paramTy == resultTy
Now I'm wondering if I need to even look at protocol requirements here. Is this really a sufficient same-type check?
Don't diagnose a lifetime error if a previous default already handled the non-Escapable output in question.
54cf136 to
2812196
Compare
Infer @Lifetime(result: copy arg) for every (result: R, arg: A) pair such that R == A and 'arg' is not 'inout'.
2812196 to
6aaf903
Compare
|
@swift-ci test |
|
@swift-ci test source compatibility |
|
@swift-ci benchmark |
[docs] update lifetime defaults to prioritize the same-type rule
[NFC] lifetime inference: check for prior defaults before error
Don't diagnose a lifetime error if a previous default already handled the
non-Escapable output in question.
[lifetimes] add same-type default lifetime inference
Infer @Lifetime(result: copy arg) for every (result: R, arg: A) pair
such that R == A and 'arg' is not 'inout'.