LifetimeDependence: Support function types#86842
Merged
aidan-hall merged 8 commits intoFeb 6, 2026
Merged
Conversation
Contributor
|
Yeah, one of the fundamental invariants in the AST is that Types are supposed to be immutable, and uniqued. Let's not violate that for any reason. |
slavapestov
reviewed
Jan 28, 2026
23f51f0 to
2275893
Compare
meg-gupta
reviewed
Jan 29, 2026
meg-gupta
reviewed
Jan 29, 2026
meg-gupta
reviewed
Jan 29, 2026
meg-gupta
reviewed
Jan 29, 2026
Contributor
|
Can you add some tests to cover SIL lifetime diagnostics and function types? |
ddbaa3e to
e5729a3
Compare
Contributor
Author
|
@swift-ci test macos |
Contributor
Author
|
@swift-ci test linux |
33121ed to
482c695
Compare
Contributor
Author
|
@swift-ci test |
Contributor
Author
|
@swift-ci smoke test |
Contributor
Author
|
@swift-ci please test source compatibility |
This addresses feedback from swiftlang#86560: - Remove redundant collectParameterInfo call - Consistent naming of ParamInfo variables - Explicit type name instead of decltype Also add nullptr checks on afd, as appropriate.
142e117 to
7e903f8
Compare
Contributor
Author
|
@swift-ci test |
Contributor
Author
|
@swift-ci smoke test |
Contributor
Author
|
@swift-ci test source compatibility |
…format The isFromAnnotation flag is set if and only if the lifetime originates from a @Lifetime or @_lifetime annotation in the source program. isFromAnnotation==false means that the lifetime dependence checker would infer the same lifetime if the Swift type or decl was printed without an annotation for that dependency. More specifically, it means that the depenence was inferred by the lifetime dependence checker. Some dependencies on imported C/C++ decls are "inferred", but they either correspond to explicit lifetime information in the source (smart pointers, lifetimebound attribute) or are likely to differ from what the dependence checker would infer. As such, we set the flag to true for all of them.
To a function type's lifetimes, a base version of the type is first created with no lifetime dependence info. This is then passed to the dependence checker, and the resulting dependencies are added to it. It would be possible to do this analysis by passing just the parameter list and result type (which are available before the type is created), but this approach lets us avoid dealing with a header inclusion cycle between Types.h, ExtInfo.h, and LifetimeDependence.h, since it does not require AnyFunctionType::Param to be defined in LifetimeDependence.h.
We fall back to indices when labels are not available, but labels are preferable, because they readable, stable, and preferred by the lifetime dependencies proposal.
Includes: - rdar://166912068 test case - Nested type SIL tests - rdar://160894371 test - Many more
7e903f8 to
6aa5578
Compare
Contributor
Author
|
@swift-ci smoke test |
Contributor
Author
|
@swift-ci test |
Contributor
Author
|
@swift-ci test source compatibility |
atrick
added a commit
to atrick/swift
that referenced
this pull request
Feb 24, 2026
A nonescaping closure that returns a ~Escapable result and has no @_lifetime
annotation is assumed to depend on its closure context.
This fixes overly strict type checking introduced by:
commit e98a7a6
Date: Fri Feb 6 02:09:25 2026
Merge pull request swiftlang#86842
LifetimeDependence: Support function types
Fix:
1. Disable missing dependency diagnostics for ~Escapable results
Continue allow the most basic nonescaping closure types without annotation:
func f(body: () -> NE) -> NE
2. Disable single-parameter inference for function types
Do *not* infer a default parameter dependency here:
func f(body: (AnyObject) -> NE) -> NE
The single-parameter rule should only apply to unambiguous function
declarations. It never applies to function types. Function types should instead
infer a dependency on the closure context.
Fixes rdar://171031632 ([nonescapable] allow nonescaping closures to return
non-Escapable types)
atrick
added a commit
to atrick/swift
that referenced
this pull request
Feb 24, 2026
A nonescaping closure that returns a ~Escapable result and has no @_lifetime
annotation is assumed to depend on its closure context.
This fixes overly strict type checking introduced by:
commit e98a7a6
Date: Fri Feb 6 02:09:25 2026
Merge pull request swiftlang#86842
LifetimeDependence: Support function types
Fix:
1. Disable missing dependency diagnostics for ~Escapable results
Continue allow the most basic nonescaping closure types without annotation:
func f(body: () -> NE) -> NE
2. Disable single-parameter inference for function types
Do *not* infer a default parameter dependency here:
func f(body: (AnyObject) -> NE) -> NE
The single-parameter rule should only apply to unambiguous function
declarations. It never applies to function types. Function types should instead
infer a dependency on the closure context.
Fixes rdar://171031632 ([nonescapable] allow nonescaping closures to return
non-Escapable types)
atrick
added a commit
to atrick/swift
that referenced
this pull request
Feb 25, 2026
A nonescaping closure that returns a ~Escapable result and has no @_lifetime
annotation is assumed to depend on its closure context.
This fixes overly strict type checking introduced by:
commit e98a7a6
Date: Fri Feb 6 02:09:25 2026
Merge pull request swiftlang#86842
LifetimeDependence: Support function types
Fix:
1. Disable missing dependency diagnostics for ~Escapable results
Continue allow the most basic nonescaping closure types without annotation:
func f(body: () -> NE) -> NE
2. Disable single-parameter inference for function types
Do *not* infer a default parameter dependency here:
func f(body: (AnyObject) -> NE) -> NE
The single-parameter rule should only apply to unambiguous function
declarations. It never applies to function types. Function types should instead
infer a dependency on the closure context.
Fixes rdar://171031632 ([nonescapable] allow nonescaping closures to return
non-Escapable types)
nickolas-pohilets
pushed a commit
to nickolas-pohilets/swift
that referenced
this pull request
Mar 1, 2026
A nonescaping closure that returns a ~Escapable result and has no @_lifetime
annotation is assumed to depend on its closure context.
This fixes overly strict type checking introduced by:
commit e98a7a6
Date: Fri Feb 6 02:09:25 2026
Merge pull request swiftlang#86842
LifetimeDependence: Support function types
Fix:
1. Disable missing dependency diagnostics for ~Escapable results
Continue allow the most basic nonescaping closure types without annotation:
func f(body: () -> NE) -> NE
2. Disable single-parameter inference for function types
Do *not* infer a default parameter dependency here:
func f(body: (AnyObject) -> NE) -> NE
The single-parameter rule should only apply to unambiguous function
declarations. It never applies to function types. Function types should instead
infer a dependency on the closure context.
Fixes rdar://171031632 ([nonescapable] allow nonescaping closures to return
non-Escapable types)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First part of work originally from #85414.
Supersedes #86795.
The approach taken in this PR is as follows:
@_lifetimeannotation using parameter labels when possible.