Skip to content

Cut delegation edges - #192

Merged
zgrannan merged 4 commits into
mainfrom
cut-delegations
Nov 2, 2026
Merged

zgrannan merged 4 commits into
mainfrom
cut-delegations

Conversation

@ThomasMayerl

Copy link
Copy Markdown
Contributor

Delegation edges have a problem as seen in the following example:

let mut x = 3;
let r_x = &mut x;
let p_x = r_x as *mut i32;
x = x + 1;
unsafe { *p_x = *p_x + 1 };

Here, the PCG will not drop the borrow r_x for the write to x, since a delegation edge with *r_x exists at this point, and we are still using *p_x (that the delegation edge is connected to) at a later point. Therefore, the PCG prints an error: PCG Assertion Failed : [main] No capability for x

However, we expect another error from Prusti: The write to x should be possible and drop the borrow r_x regardless. Therefore, Prusti will exhale the permission for r_x (and p_x) at that point, printing correctly an error in the last line that we do not have permission to access *p_x. Therefore, a delegation must generally stay alive as long as we use the raw pointer but it must forcefully be cut if we try to access a place that is lent out to another place that (nestedly) contains such a delegation. This PR fixes this issue by cutting the delegation edges appropriately.

Disclaimer: Claude Code was used to write the changes in this PR.

@ThomasMayerl
ThomasMayerl requested a review from zgrannan October 30, 2026 13:50
@JonasAlaif

Copy link
Copy Markdown
Contributor

This might be fixed by #190 also, but if that doesn't get merged soon we can just rebase that PR on top of this one

@zgrannan zgrannan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me!

@zgrannan
zgrannan merged commit d88bcb3 into main Nov 2, 2026
24 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