Skip to content

LifetimeDependenceScopeFixup: _read accessor: extend temporaries #80848

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 7 commits into from
Apr 17, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Apr 16, 2025

Add support for extending owned temporary values in addition to access scopes and borrow scopes. Required for _read accessors in which the coroutine depends on an owned value.

Fix unidentified LifetimeDependence.Scope initialization.

Fixes rdar://148540048 (Assigning span value to _ results in an incorrect escape diagnostic)

Fixes rdar://149226564 (Compiler crash with non-escapable storing another
non-escapable and having a deinit)

@atrick atrick requested a review from eeckstein as a code owner April 16, 2025 06:34
@atrick
Copy link
Contributor Author

atrick commented Apr 16, 2025

@swift-ci test

@atrick atrick requested a review from meg-gupta April 16, 2025 06:45

extension InstructionRange {
enum PathOverlap {
case containsPath
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to add some comments, e.g.

  // range:  ---
  //          |    pathBegin
  //          |       | 
  //          |     pathEnd
  //         ---
  case containsPath

  // range:  ---
  //          |    pathBegin
  //         ---       | 
  //                pathEnd
  // 
  case containsBegin

}
if block == pathBegin.parentBlock {
let endInBlock = block == pathEnd.parentBlock ? pathEnd : block.terminator
for inst in ReverseInstructionList(first: endInBlock) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you could use the Instruction.dominatesInSameBlock utility for this.

Copy link
Contributor Author

@atrick atrick Apr 16, 2025

Choose a reason for hiding this comment

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

I restructured the code slightly and added comments and test cases explaining why this isn't as simple as a dominance check (the loop implemented here is actually simpler and more efficient than using multiple dominance checks)

return .disjoint
}
}
// fallthru: pathBegin was not reached
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this fall-through really happen? Shouldn't the loop always find the pathBegin instruction?
If so, maybe change this to a fatalError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

restructured and commented to make it clear how this case can happen.

atrick added 4 commits April 16, 2025 16:42
Fixes rdar://148540048 (Assigning span value to `_` results in an incorrect escape diagnostic)
Refactor VariableIntroducerUseDefWalker into a general
LifetimeDependenceUseDefWalker for use with LifetimeDependenceScopeFixup.
atrick added 3 commits April 16, 2025 16:46
We sometimes use LocalVariableUtils to analyze temporary storage in which the
store_borrow is not already enclosed by an access scope.
Add support for extending owned temporary values in addition to access scopes
and borrow scopes. Required for _read accessors in which the coroutine depends
on an owned value.
Fixes rdar://149226564 (Compiler crash with non-escapable storing another
non-escapable and having a deinit)
@atrick
Copy link
Contributor Author

atrick commented Apr 16, 2025

@swift-ci smoke test

1 similar comment
@atrick
Copy link
Contributor Author

atrick commented Apr 17, 2025

@swift-ci smoke test

@atrick
Copy link
Contributor Author

atrick commented Apr 17, 2025

macOS timed out when setting up the repos

@atrick atrick enabled auto-merge April 17, 2025 06:12
@atrick
Copy link
Contributor Author

atrick commented Apr 17, 2025

@swift-ci smoke test macOS

@atrick atrick merged commit eb91bb5 into swiftlang:main Apr 17, 2025
3 checks passed
@atrick atrick deleted the read-accessor branch April 17, 2025 15: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.

2 participants