Skip to content

Fix mark_dependence [nonescaping] ownership #79177

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 3 commits into from
Feb 6, 2025

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Feb 6, 2025

Temporarily introduce AnyInteriorPointer operand ownership.

This is necessary to fix a recent OSSA bug that breaks common occurrences on mark_dependence [nonescaping]. Rather than reverting that change above, we make forward progress toward implicit borrows scopes, as was the original intention.

This fixes an OSSA verification bug:

rdar://144199759 (Assert: mark_dependence [nonescaping]: ownership incompatible with an owned value)

introduced here:

commit 79b649854b0a39b5aa0f79d826553004bd460c92
Date:   Wed Jan 22 01:24:49 2025

    Fix operand ownership of mark_dependence [nonescaping] of address values

The bug only showed up with mark_dependence [nonescaping], which mainly affected ~Escapable types. Adddressors happened to work because SILGen was emitting a borrow scope around them.

Rather than reverting the change above, this fix migrates mark_dependence [nonescaping] to an implicit borrow scope.

In the near future, all InteriorPointer instructions will create an implicit borrow scope. This means we have the option of not emitting extraneous begin/end_borrow instructions around intructions like ref_element_addr, open_existential, and project_box. After that, we can also migrate GuaranteedForwarding instructions like tuple_extract and struct_extract

The only reason to introduce the special case: AnyInteriorPointer, is timing. We are currently trying to enable OSSA modules. We don't want to simultaneously change the representation of OSSA, because, in the short term, that will make it harder to screen bugs and migrate projects.

As soon as OSSA modules is enabled, instead of this temporary change, we should make the single-line change to allow InteriorPointer to accept owned values. That will significantly affect SIL, because a side effect will be to stop emitting extraneous begin_borrow instructions in some cases. Our OSSA utilities should fully support elimination of extraneous borrow scopes--we already rely on InteriorPointer traversal in key places. This is especially important for lifetime completion, which we are rapidly adopting throughout the pipeline. So any problem with InteriorPointer traversal is an existing bug that will surface eventually, regardless whether we have extraneous borrow scopes.

This test case would always pass, even without the fix it was intending to test:

commit 79b6498
Author: Meghana Gupta <[email protected]>
Date:   Wed Jan 22 01:24:49 2025

    Fix operand ownership of mark_dependence [nonescaping] of address values
This is necessary to fix a recent OSSA bug that breaks common occurrences on
mark_dependence [nonescaping]. Rather than reverting that change above, we make
forward progress toward implicit borrows scopes, as was the original intention.

In the near future, all InteriorPointer instructions will create an implicit
borrow scope. This means we have the option of not emitting extraneous
begin/end_borrow instructions around intructions like ref_element_addr,
open_existential, and project_box. After that, we can also migrate
GuaranteedForwarding instructions like tuple_extract and struct_extract.
This fixes an OSSA verification bug introduced here:

    commit 79b6498
    Author: Meghana Gupta <[email protected]>
    Date:   Wed Jan 22 01:24:49 2025

        Fix operand ownership of mark_dependence [nonescaping] of address values

The bug only showed up with mark_dependence [nonescaping], which means mainly
affects `~Escapable` types. Adddressors happened to work because SILGen was
emitting a borrow scope around them.

Rather than reverting the change above, this fix migrates mark_dependence
[nonescaping] to an implicit borrow scope.

Fixes rdar://144199759 (Assert: mark_dependence [nonescaping]:
ownership incompatible with an owned value)
@atrick atrick requested a review from meg-gupta February 6, 2025 00:30
@atrick atrick enabled auto-merge February 6, 2025 00:31
@meg-gupta
Copy link
Contributor

LGTM!

@atrick
Copy link
Contributor Author

atrick commented Feb 6, 2025

@swift-ci test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

lgtm

@atrick atrick merged commit a54a23a into swiftlang:main Feb 6, 2025
4 of 5 checks passed
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