Skip to content

Fix store borrow verification #59360

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 2 commits into from
Jun 13, 2022

Conversation

eeckstein
Copy link
Contributor

  • fix verification of store_borrow locations in the MemoryLifetimeVerifier
  • document that a store_borrow location must not be modified by other instructions in SIL.rst

In case of a single-block location, the verification of store_borrow locations didn't work in all cases.
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested review from meg-gupta and atrick June 10, 2022 09:14
@meg-gupta
Copy link
Contributor

LGTM

1 similar comment
@meg-gupta
Copy link
Contributor

LGTM

@@ -3745,6 +3745,8 @@ store_borrow

Stores the value ``%0`` to a stack location ``%1``, which must be an
``alloc_stack $T``.
The stack location must not be modified by other instructions than
``store_borrow``.
Copy link
Contributor

Choose a reason for hiding this comment

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

The stack location must not be modified by other instructions than
store_borrow.

This is a type-level semantic restriction. So you're saying that we infer type information from the existence of a store_borrow somewhere on the same address (obvious IR design fail). Where do we check that a store_borrow's address is always derived from an alloc_stack, and that for the same alloc_stack all uses end in a known read-only operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's even stricter: the destination address of a store_borrow must be an alloc_stack (not just derived from). That's verified in the SILVerifier. I was considering added a flag to alloc_stack to indicate a store-borrow location, but given that it's really easy to derive and verify, I think a flag is not really needed.
Alternatively we could also combine store_borrow and alloc_stack into a single instruction.

, and that for the same alloc_stack all uses end in a known read-only operation?

That's verified in the MemoryLifetimeVerifier

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think an alloc_stack flag helps. It's just that the entire concept of a "borrow-only location" was buried in the memory verifier, so it just seemed like a shortcut to avoid doing stronger verification. I didn't see any separate logic that does: check all uses of a borrow-only location to prove they are read-only. I bet ownership verification would be simpler if we could assume that invariant.

@eeckstein eeckstein merged commit 2d2a56f into swiftlang:main Jun 13, 2022
@eeckstein eeckstein deleted the fix-store-borrow-verification branch June 13, 2022 07: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