Skip to content

LifetimeDependence: simplify and fix multiple bugs #79236

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

Merged
merged 13 commits into from
Feb 10, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Feb 8, 2025

Functional changes:

  • Improved modeling of dependence on local variable scopes.

  • Support for global 'let' dependencies

  • For nested modify->read accesses, only extend the read accesses.

  • Avoid making a read access dependent on an inout argument.
    The following needs to be an error to prevent span storage from being modified:

    @Lifetime(owner)
    foo(owner: inout Owner) -> Span {
    owner.span
    }

  • Improve usability of borrowing trivial values (UnsafePointer). Allow:

    let span = Span(buffer.baseAddress)

  • Ignore access scopes for trivial values.

Structural changes:

  • Delete the LifetimeDependenceUseDefWalker. The major commit in this PR deletes 120 lines of code. The added lines in the other commits are mostly tests.

  • Encapsulate all logic for variable introducers within the LifetimeDependenceInsertion pass. Once mark_dependence instructions are inserted, no subsequent pass needs to think about the "root" of a dependence.

Fixes: rdar://142451725 (Escape analysis fails with mutations)

Fixes rdar://143584461 (Extended exclusive borrow issues with MutableSpan and OutputSpan)

@atrick
Copy link
Contributor Author

atrick commented Feb 8, 2025

@swift-ci test

@atrick atrick force-pushed the fix-lifedep-access branch from 6a7b589 to 389987a Compare February 8, 2025 06:22
@atrick
Copy link
Contributor Author

atrick commented Feb 8, 2025

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Feb 8, 2025

The test failure is not related to this PR:

swift-PR-macos/branch-main/swift/test/SILOptimizer/Inputs/SpanExtras.swift:172:11: error: 'Span' is only available in iOS 9999 or newer
 170 | 
 171 | @available(macOS 9999, *)
 172 | extension Span where Element: ~Copyable {
     | |         `- error: 'Span' is only available in iOS 9999 or newer
     | `- note: add @available attribute to enclosing extension

It should be fixed here: #79239

@atrick
Copy link
Contributor Author

atrick commented Feb 8, 2025

@swift-ci smoke test macOS

@atrick atrick force-pushed the fix-lifedep-access branch from 389987a to 8421608 Compare February 9, 2025 18:49
@atrick
Copy link
Contributor Author

atrick commented Feb 9, 2025

@swift-ci test

@atrick atrick enabled auto-merge February 9, 2025 18:50
@atrick atrick force-pushed the fix-lifedep-access branch from 8421608 to f066872 Compare February 9, 2025 19:11
@atrick
Copy link
Contributor Author

atrick commented Feb 9, 2025

@swift-ci test

@atrick atrick disabled auto-merge February 9, 2025 19:15
@atrick
Copy link
Contributor Author

atrick commented Feb 9, 2025

@swift-ci Please Build Toolchain macOS Platform

Consider end_lifetime to be part of the endOperands set, which is used for
linear liveness, even though it does not end the lifetime.
A simple utility on ForwardingInstructions that should be defined alongside
similar utilities rather than inside a pass.
General utility to determine whether an argument already has an access scope
that is compatibly with this BeginAccess.
Avoid bailing out when something depends on the local variable.
Return an Initializer rather than a tuple. This makes it easier and more robust
for clients to track dependencies on initialized memory.
Functional changes:

Improved modeling of dependence on local variable scopes.

For nested modify->read accesses, only extend the read accesses.

Avoid making a read access dependent on an inout argument.
The following needs to be an error to prevent span storage from being modified:

  @Lifetime(owner)
  foo(owner: inout Owner) -> Span {
    owner.span
  }

Improve usability of borrowing trivial values (UnsafePointer). Allow:

  let span = Span(buffer.baseAddress)

Ignore access scopes for trivial values.

Structural changes:

Delete the LifetimeDependenceUseDefWalker.

Encapsulate all logic for variable introducers within the LifetimeDependenceInsertion pass. Once mark_dependence instructions are inserted, no subsequent pass needs to think about the "root" of a dependence.

Fixes: rdar://142451725 (Escape analysis fails with mutations)
This fixes functions that return @Lifetime(immortal).
Needed to diagnose MutableSpan and OutputSpan.

For now, simply remove the bailout and TODO. The next change will introduce more
logic to force a diagnostic error in rare cases that can't be handled completely.

Fixes rdar://143584461 (Extended exclusive borrow issues with
MutableSpan and OutputSpan)
@atrick atrick force-pushed the fix-lifedep-access branch from f066872 to c2842e8 Compare February 10, 2025 17:13
@atrick
Copy link
Contributor Author

atrick commented Feb 10, 2025

@swift-ci smoke test

@atrick atrick enabled auto-merge February 10, 2025 17:14
@atrick atrick merged commit 4e7623e into swiftlang:main Feb 10, 2025
3 checks passed
@atrick atrick deleted the fix-lifedep-access branch February 10, 2025 21:54
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.

1 participant