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

Structured assertions #151

Merged
merged 60 commits into from
Mar 4, 2019

Conversation

langston-barrett
Copy link
Contributor

@langston-barrett langston-barrett commented Feb 8, 2019

Motivation

Execution of syntax extensions produces values whose validity depends on the
truth of certain (symbolic) predicates (call such predicates "safety
assertions"). The values are often operated on further, compounding and
combining their paired safety assertions. When these safety assertions are
actually discharged, it would be nice to be able to explain to users why
symbolic simulation failed.

The current state of affairs

Assertions arise both at runtime, when instructions are being executed, and
as expressions at translation time. The way these are dealt with right now
is:

  • Runtime: use What4's PartExpr datatype (isomorphic to
    Maybe (Value, Predicate)) with the predicate summing up all the
    assertions made
  • Translation time: use the AddSideCondition constructor of Crucible's
    Expr with a pair of (Predicate, Explanation)

The downsides of this approach are:

  • these are totally disparate approaches, even though the same kinds of
    assertions are being made
  • the information contained in the error messages varies widely
  • there is no ability to programatically select which assertions should
    be made

Design

There are a few observations that influce the design here:

  1. The type of safety assertions is specific to the syntax extension in
    operation. Java and LLVM have different things to assert.
  2. Some operations on safety assertions can be shared between extensions,
    and so should go in Crucible proper.
  3. Assertions need to be constructed both at CFG-building time and at
    symbolic execution time.

These lead to the following design decisions:

  1. The open type family AssertionClassifier, keyed on the syntax extension
  2. The implementation of the HasStructuredAssertions class

For runtime assertions, the new idea is that partial values should be
(isomorphic to) a pair (Value sym, AssertionTree sym) where
AssertionTree sym is a tree which has boolean connectives (and, or, ite)
as non-leaf vertices and predicates together with classifiers and
explanations as leaves.

Since assertions can also come up at translation time, the type family is
parameterized over a type of expressions e :: CrucibleType -> Type that gets
converted from Expr ext s f at translation time to RegValue sym ty at
runtime. This allows for predicates to be constructed using Crucible syntax at
translation time. The safety assertions will participate in the translation
process so they can be asserted at runtime.

Possible next steps

  • Allow for programatic filtering of exceptions in the HasStructuredAssertions class
  • Simplify assertion trees using asConstantPred
  • Allow for a sliding scale of verbosity
  • Merge the modes of expression-level and statement-level assertions
  • Implement in other syntax extensions (JVM, Macaw)
    • More highly structured assertions for JVM
  • Implement some kind of flag around whether the value has the semantics of undef
    or poison when the assertion fails

@langston-barrett langston-barrett changed the title Structured assertions [WIP] Structured assertions Feb 8, 2019
@langston-barrett
Copy link
Contributor Author

I think this would be most useful (and reduce most duplication) if I try to get rid of What4.PartExpr altogether (at least in crucible-llvm). I'm going to look into doing that in this PR.

GT -> GTF
EQ -> -- This is safe as long as the 'compareC' is doing a nontrivial
-- comparison, i.e. actually using 'subterms'
unsafeCoerce EQF
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid this unsafeCoerce? I don't understand the correctness argument you're making here in this comment, and it seems like it depends on the OrdC instance in a nontrivial way that makes me uneasy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the issue is that we don't have the type-level evidence we need in this branch, but we can't say these things are unequal. This is a pretty fundamental issue because of the shift from PartExr p v ~= Maybe (p, v) to a type more like (p, Maybe v). I wonder if we can get rid of the Maybe altogether, there should be reasonable "zero" values for each type... I'll look into that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done away with the Maybe here, see "What4.Partial". This actually led me to combine the ideas from a few different types expressing partiality, and I think leads to a better overall solution.

@robdockins
Copy link
Contributor

FYI, I did a merge with master and pushed into branch partllvmval, you'll probably want to pull from there

@langston-barrett
Copy link
Contributor Author

langston-barrett commented Feb 11, 2019

I think this is generally ready for review, with the caveat that it might be hard to get Crucible to exhibit these structured messages, because the way memory reads work is to calll a "fallback" function readPrev whenever what you're currently trying fails. It's sort of a backtracking algorithm

@langston-barrett langston-barrett changed the title [WIP] Structured assertions Structured assertions Feb 12, 2019
@robdockins
Copy link
Contributor

There's a pretty big merge conflict with the refactoring related to registering intrinsics. Can you take a look @siddharthist? I can't tell if there are changes that need to be preserved.

@langston-barrett
Copy link
Contributor Author

Yep!

@langston-barrett
Copy link
Contributor Author

@robdockins This is current again.

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.

2 participants