Skip to content

Fix store_borrow generation and improve its verification #60467

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 16 commits into from
Aug 18, 2022

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Aug 9, 2022

This change makes SILGen, SILOptimizer and SILVerifier changes to ensure all store_borrows are ended with an end_borrow, and uses of the store_borrow destination are all in the enclosing store_borrow scope and are via the store_borrow return address.

@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch from fcec851 to 45b2a18 Compare August 9, 2022 19:07
@meg-gupta
Copy link
Contributor Author

TODO: A utility to insert end_borrows for store_borrows

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Contributor Author

@swift-ci source compatibility test

@meg-gupta meg-gupta changed the title Fix store_borrow generation and improve its verification [WIP] Fix store_borrow generation and improve its verification Aug 9, 2022
@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch from 45b2a18 to f65817e Compare August 9, 2022 23:14
@meg-gupta
Copy link
Contributor Author

@swift-ci test source compatibility

@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch from f65817e to fd2e0b1 Compare August 10, 2022 15:22
@meg-gupta
Copy link
Contributor Author

@swift-ci smoke test

@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch 2 times, most recently from ebc16ba to 5b500b1 Compare August 11, 2022 09:05
@meg-gupta meg-gupta marked this pull request as ready for review August 11, 2022 09:06
@meg-gupta meg-gupta changed the title [WIP] Fix store_borrow generation and improve its verification Fix store_borrow generation and improve its verification Aug 11, 2022
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Contributor Author

@swift-ci benchmark

@meg-gupta
Copy link
Contributor Author

@swift-ci test source compatibility

@meg-gupta meg-gupta requested review from atrick and eeckstein August 11, 2022 09:07
@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch from 5b500b1 to f160e32 Compare August 11, 2022 21:35
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch from f160e32 to da05282 Compare August 15, 2022 03:53
@atrick
Copy link
Contributor

atrick commented Aug 15, 2022

A couple things to follow up on

Add the verifier tests cases. Make sure we have one for nested scopes: store borrow within load borrow within store borrow

TODO: GenericCloner should insert end_borrows at the function exit points

The ScopedAddressOperand/ScopedAddressValue utilities can be merged into a single ScopedAddress utility

Probably no longer need the endScope utilities. Or keep them but make them failable, or the client needs to use a bailable computeLiveness analysis first. Then call endScopeAtLiveness only if it succeeds.

Don't need some new "use-specific" utilities

@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch 3 times, most recently from d3ea0f2 to 56f1c55 Compare August 16, 2022 19:13
This change ensures all store_borrows are ended with an end_borrow, and uses of the store_borrow
destination are all in the enclosing store_borrow scope and via the store_borrow return address.

Fix tests to reflect new store_borrow pattern
Add ScopedAddressOperand and ScopedAddressValue abstraction utilities
Introduce verification for store_borrow to validate its uses are correctly enclosed in their scope.

Include end_borrow/end_access as implicit uses while validating a borrow introducer

Add flow sensitive verifier rule for store_borrow/end_borrow pair

Make sure store_borrow is always to an alloc_stack

Make sure uses to store borrow location are via its return address only
…rship

Map store_borrow return_address with the destination, so that while cloning a store_borrow into a function w/o ownership,
users of store_borrow return address can be mapped with the lowered store's destination.
@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch from 56f1c55 to be6be7f Compare August 17, 2022 18:14
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta force-pushed the fixstoreborrowsilgen branch from be6be7f to f374f2b Compare August 17, 2022 23:28
@meg-gupta
Copy link
Contributor Author

@swift-ci test and merge

@swift-ci swift-ci merged commit ba001ec into swiftlang:main Aug 18, 2022
@asl
Copy link
Contributor

asl commented Sep 30, 2022

@meg-gupta It seems that https://github.com/apple/swift/blob/main/docs/SIL.rst#store-borrow should be modified as well to outline the semantics of returned value of store_borrow.

asl added a commit that referenced this pull request Oct 5, 2022
Apparently #60467 changed the semantics of store_borrow as it started to produce a value. This change was not documented in SIL spec and not all places were updated to new semantics.

Now the adjoint of store_borrow should be generated for the value of instruction itself, not the destination address
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.

4 participants