Skip to content

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Aug 29, 2025

  • Lifetime inference: restructure to support multiple dependencies.
    Restructure the inference logic to allow the same function declaration to
    independently annotate or infer different lifetime targets.

    For example:

    @_lifetime(borrow a)
    /* DEFAULT: @_lifetime(b: copy b)
    func f(a: A, b: inout B) -> NE

    The fact that we prevented this was somewhat accidental and surprising.

    This restructuring simplifies the code but also gives us much more control over
    the inference logic.

  • Lifetime inference: comment the change in 'inout' behavior.

  • Lifetime inference test case update.
    Cleanup the tests so we can cross reference them with the documentation.

  • Document @_lifetime annotation

@atrick atrick marked this pull request as draft August 29, 2025 17:27
@atrick atrick requested a review from meg-gupta August 29, 2025 17:27
@atrick atrick force-pushed the lifedep-mutating-default branch 5 times, most recently from 5700395 to 7a7cbd9 Compare September 3, 2025 05:56
@atrick atrick requested a review from glessard September 3, 2025 05:57
@atrick atrick marked this pull request as ready for review September 3, 2025 05:58
@atrick
Copy link
Contributor Author

atrick commented Sep 3, 2025

@swift-ci test

@atrick atrick force-pushed the lifedep-mutating-default branch from 7a7cbd9 to 130cf4c Compare September 3, 2025 06:28
@atrick
Copy link
Contributor Author

atrick commented Sep 3, 2025

@swift-ci test

@atrick atrick force-pushed the lifedep-mutating-default branch 2 times, most recently from 1323928 to f40c966 Compare September 4, 2025 01:02
@atrick
Copy link
Contributor Author

atrick commented Sep 4, 2025

@swift-ci test

Restructure the inference logic to allow the same function declaration to
independently annotate or infer different lifetime targets.

For example:

   @_lifetime(borrow a)
   /* DEFAULT: @_lifetime(b: copy b)
   func f(a: A, b: inout B) -> NE

The fact that we prevented this was somewhat accidental and surprising.

This restructuring simplifies the code but also gives us much more control over
the inference logic.

Fixes: rdar://159288750 ("A function cannot have a ~Escapable 'inout' parameter
in addition to other ~Escapable parameters" is not actionable)
Infer @_lifetime(self: copy self) for mutating methods without requiring the
experimental Lifetimes feature to be disabled. Treatment of mutating 'self' is
now consistent with other 'inout' parameters.

Example:

    extension MutableSpan {
      mutating func mutatingMethod() {...}
    }
Cleanup the tests so we can cross reference them with the documentation.

Update the tests to allow multiple annotations and defaults.
@atrick atrick force-pushed the lifedep-mutating-default branch from f40c966 to 91ab0b7 Compare September 4, 2025 05:43
@atrick
Copy link
Contributor Author

atrick commented Sep 4, 2025

@swift-ci test

Copy link
Contributor

@glessard glessard left a comment

Choose a reason for hiding this comment

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

lgtm

}

// ==========================================================================
// MARK: Inferrence rules
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// MARK: Inferrence rules
// MARK: Inference rules

@atrick atrick merged commit 5926420 into swiftlang:main Sep 4, 2025
5 checks passed
@atrick atrick deleted the lifedep-mutating-default branch September 4, 2025 22:44
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