Skip to content

Conversation

@atrick
Copy link
Contributor

@atrick atrick commented Dec 12, 2025

  • [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'.

@atrick
Copy link
Contributor Author

atrick commented Dec 12, 2025

@swift-ci test

// 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 {
Copy link
Contributor

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

Copy link
Contributor Author

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.
Infer @Lifetime(result: copy arg) for every (result: R, arg: A) pair
such that R == A and 'arg' is not 'inout'.
@atrick
Copy link
Contributor Author

atrick commented Dec 13, 2025

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Dec 13, 2025

@swift-ci test source compatibility

@atrick
Copy link
Contributor Author

atrick commented Dec 13, 2025

@swift-ci benchmark

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