-
Notifications
You must be signed in to change notification settings - Fork 62
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
Sim refactor #1298
Sim refactor #1298
Conversation
VToNat (VVector v) -> fromIntegral (V.length v) | ||
VToNat (VWord w) -> fromIntegral (bpBvSize bp w) | ||
VBVToNat n _ -> fromIntegral n -- TODO, remove this fromIntegral | ||
VIntToNat _ -> error "natSize: symbolic integer" |
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.
Is there a better alternative to calling error
here?
@@ -455,9 +457,9 @@ natToWord :: (VMonad l, Show (Extra l)) => BasePrims l -> Int -> Value l -> MWor | |||
natToWord bp w val = | |||
case val of | |||
VNat n -> bpBvLit bp w (toInteger n) | |||
VToNat v -> | |||
VIntToNat _i -> error "natToWord of VIntToNat TODO!" |
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.
What needs to be done here?
_ -> panic "atOp: expected vector" | ||
|
||
VIntToNat _i -> | ||
error "atWithDefault: symbolic integer TODO" |
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.
We'll probably need to implement a proper indexing operation with symbolic integer index.
do let update i = return (VVector (xv V.// [(i, y)])) | ||
iv' <- V.mapM (liftM toBool . force) iv | ||
selectV (lazyMuxValue bp) (fromIntegral n - 1) update iv' -- FIXME dangerous fromIntegral | ||
|
||
VIntToNat _ -> error "updOp: symbolic integer TODO" |
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 symbolic-integer-index update should be implementable by putting an equality-test if-then-else in each array position
@@ -808,6 +816,8 @@ expByNatOp bp = | |||
|
|||
loop one . V.toList =<< toBits (bpUnpack bp) w | |||
|
|||
VIntToNat _ -> error "expByNat: symbolic integer" |
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.
I guess exponentiation by a symbolic integer will never be supported, as it's not in the SMT-Lib theory. We should throw a catchable user-error exception.
VWord xw -> do | ||
zb <- toBool <$> force z | ||
VWord <$> wordOp zb xw iw | ||
_ -> panic $ "shiftOp: " ++ show xs | ||
|
||
VIntToNat _i -> error "shiftOp: symbolic integer TODO" |
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 should be implementable; we will need to produce a big chain of nested if-then-else expressions with index equality tests.
| VVector !(Vector (Thunk l)) | ||
| VBool (VBool l) | ||
| VWord (VWord l) | ||
| VToNat (Value l) | ||
| VBVToNat !Int (Value l) -- TODO: don't use @Int@ for this, use @Natural@ |
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.
Is there anything tricky about changing this to Natural
?
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.
Mainly that vectors and the concrete bitvector representations use Int
for their lengths.
Commit d17926a "Improve scAbstractExts and scGeneralizeExts" seems like it's fixing a separate bug; maybe it would make more sense as a separate PR |
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.
Make sure to open tickets for the unimplemented Integer operations.
This distinguishes the two different coercions that can occur, and allows us to track the width of the bitvector type in `VBVToNat`.
where they can be reused more easily.
The main techincal change here is to allow "recursors" to be value forms in their own right at the AST level, conceptually separate from recursor applications. This simplifies a variety of things relating to the implementation of recursors; in particular, the terms representing iota reductions require fewer free variables and have simpler types. The "recursor" value is specified by giving: the data type, the parameters to that data type, the elimination motive, and the constructor eliminator functions. The data defining a recursor are constant throughout the execution of recursive elimination. A "recursor application" takes a recursor value, values for the indices of the data type being eliminated, and the argument to be eliminated. Although this change allows recursor values to be abstracted by lambdas and for recursor applications to be built separately from a concrete recursor value, there is currently no surface syntax for building such a "partially applied" recursor, nor for the new type of recursor values. As before, only fully-applied recursors are allowed by the parser/typechecker front-end.
Split the collection of arguments to data constructors to keep parameters separate from regular arguments.
`PrimName` values instead of just `Ident` and register their names in the naming environment so they participate in pretty printing name resolution.
This really only properly handles pretty narrow situations regarding constructors. Muxing data type values will only succeed if the same constructor is used in both values, and if the constructor forms a non-dependent function on its regular (non-parameter) arguments. However, this is similar to the prior situation, where the constructors were required to be the same, and muxing arguments would panic if they differed in shape.
on opaque values.
Minor other fixes.
It is a context-dependent keyword and causes problems with some syntax highlighting systems.
This PR implements a variety of refactorings, mostly to the saw-core simulator. These refactorings are aimed toward implementing a new evaluation mode for saw-core which does evaluation and simplification directly on saw-core terms, without passing first through what4, or some other term representation. The goal of this is to make the term evaluator a total function
on well-typed terms, so that terms are reconstructed as necessary when an external variable or opaque constant is encountered.
In order to enable the term evaluator, a number of improvements to the generic evaluator code are necessary. First, the environment that binds de Bruijn variables to values must also keep track of the types of variables, because the term reconstruction procedure is type-directed. Achieving this required a relatively extensive detour into reworking some aspects related to the implementation of datatype recursors. The end result is that it is now possible to lambda-abstract over recursor values and later apply them to data type arguments (although no concrete syntax exists for this). Secondly, the evaluator needs a way to gracefully handle the situation where evaluation gets "stuck" on a term that isn't in canonical form for an eliminator. These "neutral" terms represent places where evaluation would proceed into external variables, opaque constants, or other forms that don't immediately evaluate. The simulator would mostly
panic
before in these situations.Along the way, a number of other, smaller, improvements have been made. There are some situations involving the new
VIntToNat
constructor that still need to be handled, but they were already non-working cases before.This PR consists entirely of internal changes that I expect to have minimal user-facing impact.