Skip to content
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

Soundness test "fix": work around nightly change of -Zpolonius #16

Merged

Conversation

danielhenrymantilla
Copy link
Owner

@danielhenrymantilla danielhenrymantilla commented Nov 8, 2024

Fixes the "future-proofing CI" failures caused by a "false positive regression" in nightly rustc's semantics of -Zpolonius.

This crate tries to justify its usage of unsafe by offering a way to disable it when -Zpolonius is used, via its Cargo --feature polonius.

Indeed, when -Zpolonius is being used, there is no need to used any of the API of this crate, which, in fact, includes the very implementation of this crate. So we do precisely that, thereby avoiding the need for any unsafe, and thus "proving" that our branch API is sound, even beyond a -Zpolonius context, since it is proven to be sound there.

However, around June, the semantics of -Zpolonius changed a bit in rustc (nightly), and this non-unsafe--Zpolonius-vetted implementation was actually being rejected by it.

There is, in fact, an issue about this very thing:

It is unclear whether the rejection is fully legitimate; in this case, and also in the minimization I wrote on that issue, it is a false positive: in the non-dependent branch, there is nothing dependent being dropped "after" our return "starts". Still, it may be difficult for the compiler maintainer(s) working on this areä to properly identify and distinguish this legitimate case from one where the drop could have been problematic (in such cases, the change of -Zpolonius semantics was actually a soundness fix!).

We thus decide to just work around this tiny "false positive regression" issue by making sure our "drop" of the remainders of the non-dependent value (which happen to be a silly empty ZST (Placeholder)) clearly happen, syntactically, before our re-access to the initially (re)borrowed value occurs, when we "start" our return.

Fixes the "future-proofing CI" failures caused by a "false positive regression" in nightly rustc's semantics of `-Zpolonius`.

This crate tries to justify its usage of `unsafe` by offering a way to disable it when `-Zpolonius` is used, _via_ its Cargo `--feature polonius`.

Indeed, when `-Zpolonius` is being used, there is no need to used any of the API of this crate, which, in fact, includes the very implementation of this crate. So we do precisely that, thereby avoiding the need for any `unsafe`, and thus "proving" that our branch API is sound, _even beyond a `-Zpolonius` context_, since it is proven to be sound there.

However, around June, the semantics of `-Zpolonius` changed a bit in `rustc` (nightly), and this non-`unsafe`-`-Zpolonius`-vetted implementation was actually being rejected by it.

There is, in fact, an issue about this very thing:

  - rust-lang/rust#126520

It is unclear whether the rejection is fully legitimate; in this case, and also in the minimization I wrote on that issue, it is a false positive: in the non-dependent branch, there is nothing _dependent_ being dropped "after" our `return` "starts". Still, it may be difficult for the compiler maintainers to properly identify and distinguish this legitimate case from one where the drop could have been problematic (in such cases, the change of `-Zpolonius` semantics was actually a soundness fix!).

We thus decide to just work around this tiny "false positive regression" issue by making sure our "drop" of the remainders of the non-dependent value (which happen to be a silly empty ZST (`Placeholder`)) clearly happen, syntactically, before our re-access to the initially (re)borrowed value occurs, when we "start" our `return`.
@danielhenrymantilla danielhenrymantilla self-assigned this Nov 8, 2024
@danielhenrymantilla danielhenrymantilla merged commit 3b85eb1 into master Nov 8, 2024
13 checks passed
@danielhenrymantilla danielhenrymantilla deleted the zpolonius-test-nightly-change-workaround branch November 8, 2024 12:05
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.

1 participant