-
Notifications
You must be signed in to change notification settings - Fork 63
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
mir_unsafe_assume_spec
#1959
mir_unsafe_assume_spec
#1959
Conversation
b1a4a16
to
3a12af7
Compare
043b62d
to
a3635f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a large patch, but most of it is cargo-culted from the LLVM backend and is therefore not that interesting to review. I've left comments in the most interesting parts of the patch.
@@ -2416,6 +2414,295 @@ In this case, doing the verification compositionally doesn't save | |||
computational effort, since the functions are so simple, but it | |||
illustrates the approach. | |||
|
|||
### Compositional Verification and Mutable Allocations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation. Due to the way the SAW manual is set up, I describe compositional verification in both the LLVM and MIR backends here, although this patch doesn't change anything in the way that the LLVM backend works.
@@ -0,0 +1,159 @@ | |||
enable_experimental; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first test case, which doesn't involve mutable statics.
@@ -0,0 +1,55 @@ | |||
enable_experimental; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second test case, which does involve mutable statics. I kept this separate to avoid having to clutter the pre-/post-conditions of many specifications with extra statements involving the value of A
.
-- | When a specification is used as a composition override, this function | ||
-- checks that the postconditions of the specification fully specify (via | ||
-- @mir_points_to@ statements) the values of all local mutable allocations | ||
-- (which are declared in the preconditions via @mir_alloc_mut@) and all | ||
-- mutable static items. If not, this function will raise an appropriate error | ||
-- message. See @Note [MIR compositional verification and mutable allocations]@. | ||
checkMutableAllocPostconds :: | ||
Options -> | ||
SharedContext -> | ||
MIRCrucibleContext -> | ||
CrucibleMethodSpecIR -> | ||
OverrideMatcher MIR md () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A key function that checks if compositional MIR overrides are well-formed with respect to mutable allocations. This is the part of the implementation that is the most interesting, as it isn't simply cargo-culted from the LLVM backend.
(<<>>) = PC.joinOrderingF | ||
|
||
{- | ||
Note [MIR compositional verification and mutable allocations] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Note which describes the checkMutableAllocPostconds
function at a high level.
Sadly, this is still not quite right. Here is a very simple example that should work, but doesn't: pub fn inner(_x: &mut u32) {}
pub fn outer(x: &mut u32) {
inner(x)
}
Shockingly, this fails with:
Marking as a draft until I get to the bottom of this. |
a3635f4
to
d65c4f2
Compare
That bug has been fixed, so this is ready for a final review. |
f4ff18c
to
ff7bf47
Compare
This will prove useful in a subsequent commit where we add support for overrides in MIR, which make use of this `ConditionMetadata`.
These will need to be accessible from `SAWScript.Crucible.MIR.ResolveSetupValue` in a subsequent patch.
These previously existed as internal definitions in the LLVM and JVM backends, but nothing about these definitions are specific any particular backend. In a subsequent patch, I will make use of these definitions in the MIR backend, so it is nice to avoid having to duplicate them further.
ff7bf47
to
02db0d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, aside from the soundness question about interior mutability, which may be better left to a separate PR (we may need to improve mir-json so it exports some additional information).
This implements supports for compositional overrides in the SAW MIR backend, largely inspired by the existing implementation in the LLVM backend. I've added `test_mir_unsafe_assume_spec` and `test_mir_unsafe_assume_spec_statics` integration tests to kick the tires and ensure the basics work as expected. One place where the MIR backend meaningfully differs from the LLVM backend with respect to compositional overrides is in the treatment of mutable allocations. While the LLVM backend is content to simply invalidate the memory of underspecified mutable allocations that appear in the postconditions of overrides, the MIR backend is stricter and will outright reject any such underspecified mutable allocations, regardless of whether they are used or not. For further commentary on this, see the new sections of the SAW manual, as well as the `Note [MIR compositional verification and mutable allocations]` that describes the implementation. Checks off one box in #1859.
02db0d5
to
ac46b5b
Compare
This implements supports for compositional overrides in the SAW MIR backend, largely inspired by the existing implementation in the LLVM backend. I've added
test_mir_unsafe_assume_spec
andtest_mir_unsafe_assume_spec_statics
integration tests to kick the tires and ensure the basics work as expected.One place where the MIR backend meaningfully differs from the LLVM backend with respect to compositional overrides is in the treatment of mutable allocations. While the LLVM backend is content to simply invalidate the memory of underspecified mutable allocations that appear in the postconditions of overrides, the MIR backend is stricter and will outright reject any such underspecified mutable allocations, regardless of whether they are used or not. For further commentary on this, see the new sections of the SAW manual, as well as the
Note [MIR compositional verification and mutable allocations]
that describes the implementation.Checks off one box in #1859.