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

Dereferencing GhostBox in pearlite: why is inner_logic needed? #1257

Open
arnaudgolfouse opened this issue Nov 27, 2024 · 0 comments
Open

Dereferencing GhostBox in pearlite: why is inner_logic needed? #1257

arnaudgolfouse opened this issue Nov 27, 2024 · 0 comments

Comments

@arnaudgolfouse
Copy link
Collaborator

arnaudgolfouse commented Nov 27, 2024

The issue

In pearlite, dereferencing a GhostBox can be used to access the inner value:

#[requires(*x == 1)]
fn foo(x: GhostBox<Int>) {}

But sometimes this fails, when using mutable borrows:

#[requires(^*x == 1)]
fn foo(x: GhostBox<&mut Int>) {}
error: unsupported logical reborrow UpvarRef { closure_def_id: DefId(0:10 ~ test[0630]::foo::{closure#0}), var_hir_id: LocalVarId(HirId(DefId(0:9 ~ test[0630]::foo).2)) }, only field projections and slice indexing are supported
 --> ./test.rs:1:14
  |
1 | #[requires(^*x == 1)]
  |

Explanation

That's because the function desugaring is:

fn foo(x: GhostBox<&mut Int>) {
    // #[requires(^*x == 1)] is desugared into:
    let _requires = || {
        fin(&mut *DerefMut::deref_mut(&mut x)) == 1
        //                            ^^^^-- error because of this
    };
}

And this borrow is unsupported in pearlite code. The code we wanted to generate was

fin(GhostBox::into_inner(x)) == 1

Unfortunately the handling of *x in pearlite is a hack, that does not work in this case.

Solution

... ?

Right now the workaround is to use inner_logic:

#[requires(^x.inner_logic() == 1)]
fn foo(x: GhostBox<&mut Int>) {}
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

No branches or pull requests

1 participant