Skip to content

[ShrinkBorrowScope] Don't hoist over any applies. #40764

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

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Jan 7, 2022

Previously, hoisting was done over applies that were users of the borrowed value. Here, that is no longer done.

That hoisting was done on the theory that multiple distinct lexical scopes were equivalent to a single enclosing lexical scope. Dead borrow elimination, however, means that they are not in fact the same: If a callee takes an object as an argument, and in that callee that argument is dead, FSO and inliniing (even with approaches to maintain lexical borrow scopes when the value that is borrowed comes from an owned argument) can result in a dead borrow scope in the caller which could then be eliminated which would then enable the destroy_value to be hoisted over the inlined body, including over barriers.

Allow jumping around via matching parens by adding omitted matches.
Previously, the body--of the loop that iterated the instructions in the
block--contained the check that the instruction over which hoisting
might be done is the introducer.  Here, that check is moved into
tryHoistOverInstruction.  Now that function and its other caller,
canHoistOverInstruction, will return the right value (false) if they are
ever called with the introducer (though that could not happen without
this change).
Previously, hoisting was done over applies that were users of the
borrowed value.  Here, that is no longer done.

That hoisting was done on the theory that multiple distinct lexical
scopes were equivalent to a single enclosing lexical scope.  Dead borrow
elimination, however, means that they are not in fact the same, however:
If a callee takes an object as an argument, and in that callee that
argument is dead, FSO and inliniing (even with approaches to maintain
lexical borrow scopes when the value that is borrowed comes from an
owned argument) can result in a dead borrow scope in the caller which
could then be eliminated which would then enable the destroy_value
to be hoisted over the inlined body, including over barriers.
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler requested a review from atrick January 7, 2022 17:38
@swift-ci
Copy link
Contributor

swift-ci commented Jan 7, 2022

Build failed
Swift Test OS X Platform
Git Sha - 3ba8a93

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

This change is safe of course but

  • the code you're ripping out will still be useful for when we do hoist over applies. You just need to convert the copy_value to copy_value [lexical] to tie the two scopes together

- we'll need to make sure any regressions are fixed when we reenable hoisting... or defer this change until we have a way to hoist safely

@nate-chandler the second half of this comment was nonsense. I had thought that this code was already enabled by default.

@nate-chandler
Copy link
Contributor Author

@swift-ci please test macos platform

@nate-chandler nate-chandler merged commit c5efe9a into swiftlang:main Jan 10, 2022
@nate-chandler nate-chandler deleted the copy-propagation/shrink-borrow-scope/dont-hoist-over-any-applies branch January 10, 2022 15:39
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.

3 participants