Commit Graph

268 Commits

Author SHA1 Message Date
Rob Dockins
74cc36ce50 Implement the Field operations on Z p in the concrete simulator
and the What4 symbolic simulator.

We use the EGCD algorithm to compute inverses for concrete values.
For symbolic values, we posit a multiplicitive inverse via a defining
equation.  To get this to work, we needed to fix a bug in the
equation definition code for What4; it was asserting definitions
with the wrong polarity for "prove" calls.
2020-09-29 14:55:05 -07:00
Rob Dockins
b5bdd0fa80 Add basic support for primality checking in the type system. 2020-09-29 14:55:05 -07:00
Rob Dockins
e8f7fa9435 Add a basic implementation of AES to the SuiteB module.
This implementation is taken fairly directly from the SBV
tutorial module.  It is a Word32-oriented implementation using
TBoxes.  We make the implementation avalible via Cryptol primitives
that are similar to the AESNI instructions, with primitives for
the individual rounds and some utility primitives for performing
key expansion.
2020-09-21 14:54:28 -07:00
Rob Dockins
44dae69012 Add a Haskell-native implementation of the SHA256 and SHA512
block functions, ripped out of the SHA package, and expose
it via new Cryptol primitives.

Using these primitives in place of the defined reference implementations
leads to approx 100x speed-up in larger protocols that do a lot of hashing.

I don't know if this is the implementation we'll actually end up using,
but this verifies the overall idea and helps design the API.
2020-09-21 14:54:28 -07:00
Brian Huffman
f35fe36219 Set an upper bound of sbv < 8.8.
In version 8.8 the type of `svMkSymVar` has changed, and so cryptol
cannot currently be compiled with sbv-8.8.

Fixes #879.
2020-09-11 10:59:59 -07:00
Rob Dockins
d26da1ad0c Rework the thunk lifecycle to remove race conditions.
Thunk state is now controlled using transational memory variables
instead of IORefs, and the thunk likecycle is made more explicit
in the relevant datatypes.  Threads will now properly block and wait
when forcing a thunk that is already under evaluation by a different
thread.  Hopefully, using optimistic concurrency (transactional memory)
will help reduce concurrency contention. The reworked lifecycle
datastructures hopefully will release closures related to evaluation
faster, which should reduce memory pressure somewhat.

Fixes #856
2020-09-02 09:09:21 -07:00
Aaron Tomb
3cfb3a45bd Bump version 2020-08-31 19:45:12 -07:00
Aaron Tomb
5100132e4c
Tweak a few things for 2.9.0 (#833)
* Fix Dockerfile

* Include version number in CHANGES.md

* Update copyright dates

* Don't include cryptol-specs in release archives

* Remove duplicate copy of Programming Cryptol
2020-07-28 08:41:27 -07:00
Rob Dockins
98ee00742f Remove What4 submodule and depend on hackage-relased What4 instead. 2020-07-21 23:21:21 -07:00
Rob Dockins
1be435c67a Set SBV bounds to >= 8.6
This is consistent with our current testing, and
fixes #795
2020-07-02 14:44:47 -07:00
Rob Dockins
a9e2eed755 Add any solver support to the What4 backend.
This turned out to be relatively straightforward.  Using
a simliar strategy to SBV, we simply spawn off all the solvers
in separate threads and wait using the `async` package.
Some minor fixes in `What4` allow the threads to respond properly
to being interrupted.

Some care is required to install the necessary solver options
_before_ spawning off the threads to avoid race conditions
in the configuration datastructure itself; such race conditions should
be fixed in What4 at some point.
2020-07-02 14:44:47 -07:00
Iavor Diatchki
332450ebb2 Switch to using libBF from hackage 2020-07-01 11:35:45 -07:00
Rob Dockins
6c6cb94d46 Implement and use a new RecordMap type.
This type stores records as a finite map from field names to
values, while also remembering the original order of the fields
from when the record was generated (usually, from the program source).
For all "semantic" purposes, the fields are treated as appearing in
a canoical order (in sorted order of the field names).  However, for
user display purposes, records are presented in the order in which
the fields were originally stated.

In the course of implementing this, I discovered that we were not
previously checking for repeated fields in the parser or typechecker,
which would result in some rather strange situations and could probably
be used to break the type safety. This is now fixed and repeated fields
will result in either a parse error or a panic (for records generated
internally).

Fixes #706
2020-06-30 12:34:50 -07:00
Iavor Diatchki
0047eaf77a Initial support for floating point computation 2020-06-29 15:31:34 -07:00
Ben Selfridge
22d98c72b8 update to bv-sized branch of what4 2020-06-04 15:51:35 -07:00
Rob Dockins
dcbd70bf2b Update CHANGES and bumb version number 2020-05-15 10:42:45 -07:00
Kevin Quick
393451681b
Updates for haskeline 0.8 and use of exceptions package. 2020-05-06 14:16:53 -07:00
Rob Dockins
922350ff7a Put together enough of the framework required to run :sat and :prove
queries via What4.  We still need to support configuring the solver to use,
multisat queries, and portfolio solving.
2020-04-27 14:19:44 -07:00
Rob Dockins
44a2b8e236 Very basic scaffolding for using what4 as a symbolic backend 2020-04-27 14:19:44 -07:00
Rob Dockins
1e1f7af812 Fix the haskeline package upper bound 2020-04-23 17:37:53 -07:00
robdockins
87ad864185
Merge pull request #684 from GaloisInc/eval-refactor
Evaluator refactor
2020-04-02 09:42:04 -07:00
Rob Dockins
bdfd4e6bc0 Add INLINE and SPECIALIZE pragmas to generate better code for the
concrete evaluator.
2020-03-30 13:01:06 -07:00
Rob Dockins
058847f138 Break the symbolic query description datatypes into a separate
module, moving SBV specific code into `Cryptol.Symbolic.SBV`
2020-03-26 09:23:00 -07:00
Rob Dockins
71b2f8ce70 Rename the BitWord class into Backend, and split into a separate
module.  Push primitive type if/then/else operations into the `Backend`
class, and promote `iteValue` and `mergeValue` to operations
on generic values.
2020-03-13 12:04:27 -07:00
Rob Dockins
be45b4ea29 Move definitions specific to the concrete evaluator in to separate
modules.  The module structure needs to be a bit more cut up than
I would like to avoid module import cycles.
2020-03-11 10:26:22 -07:00
Rob Dockins
bdb8f49143 Refactor Cryptol.Symbolic.Prims and Cryptol.Symbolic.Value into
a single new module `Crypol.Eval.SBV`.
2020-03-09 14:32:07 -07:00
Rob Dockins
0341fd0480 Split out the primitive definitions used by multiple evalautors
into a `Generic` module.  Refactor the `EvalPrims` class away,
pusing the `iteValue` operation into `BitWord` and demoting
the `evalPrim` operation into an ordinary (non-typeclass)
operation.
2020-03-09 14:09:19 -07:00
Rob Dockins
fbbaed8c83 Rename module Cryptol.Prims.Eval into Cryptol.Eval.Concrete.
This fits better into the current module structure, and is a lot
less confusing.
2020-03-09 11:29:08 -07:00
Kevin Quick
fcff91714b
Bump base-compat upper bound. 2020-02-29 22:12:39 -08:00
Rob Dockins
918040f682 Add cabal bounds to the haskeline package. Apparently
version 0.8 contains some breaking changes.
2020-01-06 11:34:47 -08:00
Brian Huffman
330d4dd2d9 Refactor Fixity module so Cryptol.Utils.PP can import it.
Also make some other parts of the code less dependent on the
internal representation of the Fixity datatype.
2019-12-16 18:05:30 -08:00
Aaron Tomb
ce0365fb80 Bump master Cryptol version to 2.8.1 2019-09-17 10:08:42 -07:00
Iavor Diatchki
72068cb961 Move type-level primitives to the Prelude.
For the time being, there is still some information about them that
is duplicated in Cryptol.TypeCheck.TCon, but we at least the parsed syntax
does not depend on the typechecked syntax.
2019-07-02 17:34:36 -07:00
Aaron Tomb
2ce982ab49 Update copyright dates 2019-04-30 09:13:37 -07:00
Aaron Tomb
6276cc6afb Add CHANGES.md file 2019-04-30 09:13:37 -07:00
Aaron Tomb
4db158eafb Bump Cryptol version to 2.7.1 (next release) 2019-04-26 09:14:54 -07:00
Levent Erkok
cbdf7c696a Make cryptol compile with SBV 8.1 2019-03-09 13:26:41 -08:00
Eric Mertens
5786fcf190 Track file content fingerprints alongside loaded modules 2019-02-28 09:40:21 -08:00
Levent Erkok
8d09c79198 Make Cryptol compile with SBV 8.0
SBV 8.0 is now on hackage, with several backwards compatibility breaking changes. You'll need this patch to compile cryptol against it.
2019-01-14 16:49:19 -08:00
Kevin Quick
0616c72017
Raise base-compat upper constraint to < 0.11. 2018-08-24 16:45:28 -07:00
Aaron Tomb
45ee929b2d Bump Cabal version to 2.6.1 now that 2.6.0 is out 2018-08-01 14:39:56 -07:00
Aaron Tomb
6b926b1b3c Update Cabal file copyright 2018-08-01 09:05:39 -07:00
Aaron Tomb
70fa2033d5 Update Cabal file for Hackage acceptance 2018-08-01 09:01:30 -07:00
Brian Huffman
2e1dbad005 Improve tab completion for :set command. Fixes #154.
Tab now completes option names after `:help :set`.

Tab also completes `:help` with names of primitive types
and type classes (cf. #504).
2018-07-30 18:11:14 -07:00
Aaron Tomb
e42500e706 Update version to 2.6.0 in preparation for release
After the release, let's update the version to 2.6.1 immediately.
2018-07-30 13:24:33 -07:00
Brian Huffman
d5c9a030da Split new modules Fixity and Selector from Cryptol.Parser.AST. 2018-06-11 14:28:49 -07:00
Aaron Tomb
99f3fdbf37 Merge Cryptol/Extras.cry with Cryptol.cry
Closes #427.
2018-05-23 15:55:05 -07:00
Iavor Diatchki
a0c15874e2 Factor out panic code into its own little package. 2018-05-22 14:27:03 -07:00
Brian Huffman
62dfa1d58f Use sbv version 7.7. Fixes #486.
Also add regression test for #486.
2018-04-30 09:54:26 -07:00
Aaron Tomb
126c384ff6 Avoid most recent version of base-compat
The latest version causes build failures. Ultimately, we should be able
to fix the code to work with newer base-compat versions on various GHC
verions, but this gets builds to work for now.
2018-04-18 10:07:08 -07:00
Brian Huffman
2e4fa35209 Remove unused package dependencies. 2018-03-21 11:15:46 -07:00
Aaron Tomb
7f27ed592d Remove unnecessary dependency on old-time 2018-03-12 12:53:27 -07:00
Max Orhai
1c2996610d Use blaze for HTML generation 2018-03-05 17:07:19 -08:00
Iavor Diatchki
989e5734ef Move defaulting code to a separate module. 2017-12-22 16:01:19 -08:00
Iavor Diatchki
9c06f07223 Move errors to their own module. 2017-12-21 13:59:53 -08:00
Iavor Diatchki
2d3e146766 Allow evaluation in parameterized module, as long as parameters are not used. 2017-10-27 14:59:32 -07:00
Iavor Diatchki
5c51d32a4e Fix up html syntax highlighting. 2017-10-25 11:12:37 -07:00
Iavor Diatchki
07c5e1fcb8 Bump language standard to 2010. We're beyond '98 anyway... 2017-10-24 11:59:34 -07:00
Iavor S. Diatchki
095a7718d9 Add a pass to rewrite a param. module, into a non-param module
All definitions are parameterized by all parameters.
2017-10-19 13:45:40 -07:00
Iavor S. Diatchki
7dc7be45bb Merge remote-tracking branch 'origin/master' into abstract-types
# Conflicts:
#	src/Cryptol/REPL/Monad.hs
2017-10-13 10:45:35 -07:00
Iavor S. Diatchki
933e2cd2ee Merge branch 'abstract-types' of github.com:GaloisInc/cryptol into abstract-types
# Conflicts:
#	src/Cryptol/ModuleSystem/InstantiateModule.hs
2017-10-05 12:45:11 -07:00
Brian Huffman
a9de74ed5d Implement module-name completion and validation for :browse.
Fixes #396.
2017-10-04 19:17:42 -07:00
Iavor Diatchki
5208739653 Don't print directly to stdout. Fixes #166 2017-10-04 15:50:31 -07:00
Iavor Diatchki
2ef0a67d9b Merge branch 'master' into abstract-types 2017-10-03 13:35:57 -07:00
Rob Dockins
f02a3c783b Bump simple-smt version bounds to pull in a bug fix.
Fixes #457
2017-10-03 10:20:15 -07:00
Iavor Diatchki
498b99cda3 Split out exports specs; add some parsing for functor instances. 2017-10-02 15:01:45 -07:00
Iavor Diatchki
7135284f80 Basics of sort of module instantiation 2017-09-29 16:27:13 -07:00
Iavor Diatchki
60523d5986 Delete old solver stuff.
The main user visible effect of this might be that sometime things on
the Cryptol command line are instantiated in a slightly different way:
we get `inf` sometimes when we got a finite example before.

We could work around this if it is an issue, but I am not sure which
behavior is more reasonable.
2017-09-26 14:02:52 -07:00
Aaron Tomb
c05281d390 Fix spurious failures due to lazy I/O
Regression test check31 was failing somewhat unpredictably due to the
use of lazy I/O when loading the Z3 prelude for the type checker. Using
the `strict` package seems to fix it.
2017-09-13 15:31:43 -07:00
Eric Mertens
28bc4f81de Work around happy bug by adding type signature on ipat 2017-09-11 10:36:59 -07:00
Eric Mertens
bf571569fa Add upper bound on happy
A bug introduced in happy-1.19.6 causes incorrect type signatures
to be generated in the parser source file which lead to type
checker errors
2017-09-11 10:20:22 -07:00
Iavor S. Diatchki
ca2136fab9 Merge pull request #440 from sliverdragon37/master
Adds the :ast and :extract-coq commands for printing out a parseable AST
2017-08-15 10:25:08 -07:00
Eric Mullen
05b8f0f3c1 more polished 2017-08-14 15:45:37 -07:00
Aaron Tomb
010540c4b4 Comment out cryptol-server from Cabal file 2017-07-24 15:26:49 -07:00
Aaron Tomb
69e49d4245 Bump version to 2.5.0 2017-07-24 09:16:40 -07:00
Aaron Tomb
de80a9c2f5 Update copyright dates in Cabal file 2017-07-24 09:01:34 -07:00
Levent Erkok
5857477ab2 Modifications to make cryptol compile with SBV 7.0
Also, bumped up the version to 2.4.1
2017-07-18 10:25:00 -07:00
Aaron Tomb
d76f21f89e Update benchmarks to find Prelude and CryptolTC.z3
Since they don’t run in the normal REPL environment, they need to know
about where to find the Prelude and CryptolTC.z3 more directly.
2017-03-21 12:31:04 -07:00
Iavor S. Diatchki
41131fe7ed Redo the export to SMT story in a much simpler way. 2017-02-16 16:46:38 -08:00
Iavor S. Diatchki
3c15d086d1 Merge branch 'master' into wip/solver 2017-02-08 16:24:46 -08:00
Iavor S. Diatchki
710355176a More rules and things; external solver disabled; we can at least load ChaCha 2017-02-08 15:08:50 -08:00
Brian Huffman
140ab21f11 Add new unoptimized reference interpreter; use in REPL with ":eval <expr>" 2017-02-03 09:02:25 -08:00
Iavor S. Diatchki
f3db823f3e Checkpoint: (broken, but builds) 2017-02-01 11:43:01 -08:00
Iavor S. Diatchki
b788079244 More aggressive goal simplification. 2017-01-31 14:12:53 -08:00
Iavor S. Diatchki
12bb2c30c8 Merge branch 'master' into wip/solver 2017-01-31 10:15:49 -08:00
Iavor S. Diatchki
ee1c8c796b Switch to using the official sbv release. 2017-01-31 10:04:34 -08:00
Iavor S. Diatchki
baa19ce362 Checkpoint. 2017-01-30 18:14:10 -08:00
Iavor S. Diatchki
c3ce33f5a6 Remove old stuff 2017-01-30 10:54:45 -08:00
Robert Dockins
dae3ab11b1 Change the representation and caching of sequences for better performance.
There are two major changes in this patch.  The first is that sequence maps
now have special representations for point updates, of the sort produced by
the 'update' and 'updateEnd' primtives.  These updates are stored in a
finite map, rather than as a functional-update thunk using lambdas; this
reduces memory usage and improves time efficecy of sequences defined by
sequences of updates.

The second change is that the caching policy for sequences is changed
to retain all previously-calculated values.  This is a change from the
previous LRU policy, which retained only a small finite number of previous
values.  Benchmarking showed that unbounded memoization was better for
performance in essentially all cases over both an LRU and an adaptive
caching strategy.  The potential downside is that we may retain values
longer than necessary.  If this becomes a problem, we may need to revisit
this decision.
2016-08-12 12:10:49 -07:00
Robert Dockins
2e15d4f443 Increase the size of the garbage collector nursery to 64m.
This greatly increases mutator productivity, and thus provides
significant speedups on some examples.  The tradeoff with
larger nurseries is the potential for long GC pause times.
This is probably acceptable tradeoff for a tool like Cryptol,
despite the potential for unresponsiveness at the REPL.
2016-07-20 15:55:05 -07:00
Robert Dockins
998bddc7a7 Merge remote-tracking branch 'origin/master' into new-eval
Fix some minor conflicts in the test suite.
Conflicts:
	tests/issues/issue002.icry.fails
	tests/issues/issue148.icry.stdout
	tests/issues/issue198.icry.stdout
	tests/issues/issue214.icry.stdout
	tests/issues/issue290v2.icry.stdout
	tests/issues/issue312.icry.fails
2016-07-12 14:58:53 -07:00
Adam C. Foltzer
3c25c096a7 clean up build a bit 2016-07-06 16:20:01 -07:00
Adam C. Foltzer
78cacc4d3e Merge pull request #333 from RyanGlScott/master
Put bench/data/*.cry in extra-source-files
2016-07-05 08:49:53 -07:00
Robert Dockins
c3c1bb2c74 Merge branch 'master' into new-eval-merge 2016-06-13 16:29:36 -07:00
Robert Dockins
b95b734b74 Refactoring of how bits and words are handled in the interpreters.
The major change in this patch is to add a new type of 'WordValue'
which is always used to represent finite sequences of bits.  A word
value is either a packed word, or a sequence of lazy bits.  The 'VSeq'
constructor, in constrast, is now never used for a finite sequence of
bits.

This avoids certain thorny problems that arise when trying to faithfully
implement the lazy semantics of Cryptol.  We now do not have to commit
to a value at type '[n]' being represented as a packed word or as an
unpacked word until relatively late.  This allows us to perform type-directed
eta-expansion at every recursive call before we know how words will be represented.

This patch fixes all the outstanding strictness bugs that I know of.

Unfortunately, we seem to lose some ground on performance.  The new evaluator
is now about 5% slower than the old one on the AES benchmark, and quite a bit
slower on the SHA1 benchmark.  Fortunately, the use if LRU caches for memoization
of sequences seems to keep heap usage to manageable levels; so programs generally
complete, even if they take a long time.
2016-06-09 08:31:23 -04:00
Adam C. Foltzer
76be770d83 clean up 7.8-isms 2016-06-07 13:40:15 -07:00
Robert Dockins
99526f5700 Merge branch 'master' of github.com:GaloisInc/cryptol into new-eval 2016-06-01 15:22:09 -07:00
Thomas M. DuBuisson
363651c907 Fixes #320 Use -N1, not -N, as the default RTS option. 2016-05-31 10:38:13 -07:00
Rob Dockins
bdcfdd39a1 Update benchmarks for new interpreters 2016-05-30 23:07:05 -07:00
Rob Dockins
b518336885 Merge branch 'master' of cryptol into new-eval 2016-05-30 17:25:10 -07:00