summaryrefslogtreecommitdiff
path: root/src/rewrites.ml
AgeCommit message (Collapse)Author
2019-03-11Improve ocamldoc commentsAlasdair Armstrong
Check in a slightly nicer stylesheet for OCamldoc generated documentation in etc. Most just add a maximum width and increase the font size because the default looks absolutely terrible on high-DPI monitors. Move val_spec_ids out of initial_check and into ast_util where it probably belongs. Rename some functions in util.ml to better match the OCaml stdlib.
2019-03-08Rewriter: Cleanup old sizeof rewritesAlasdair Armstrong
Shouldn't affect anything as this is done by the typechecker now. Also remove some unfinished tracing code from c_backend.ml
2019-03-07Also remove impossible if-branchesThomas Bauereiss
2019-03-07Add a rewrite to remove impossible cases on integer literalsBrian Campbell
(e.g., for the dual 32/64 bit RISC-V model) Apply this rewrite in Coq backend.
2019-03-04Fix aarch64_small test XML for jenkinsAlasdair Armstrong
Rename rewrite_split_fun_constr_pats to rewrite_split_fun_ctor_pats as constr is commonly used as an abbreviation for constraint rather than constructor, and add a more descriptive comment.
2019-03-04Fix execute splitting to work when constructors have constraints.Alasdair Armstrong
Previously any constraints on constructors were just outright dropped when splitting the execute function in Lem generation. Now we get the constraints and type signature for each execute clause from the type given by Env.get_union_constructor, rather than by inferring the type of the pattern in each function clause. Currently this can still fail in the case where we have union U('x: Int), C1('x) = { ctor: {'y. C2('x, 'y), T('x, 'y)} } and val execute : forall 'z, C3('z). U('z) -> unit when C3 implies C1, and the body of an excute clause relies on the fact that C3 is stronger than C1, as each split function execute_ctor is only guaranteed to be constrained by some subset of C1. This seems unlikely to happen in practice though. Also fix a bug when binding P as int('T) against int('T) and similar cases, where the new type variable would cause the old type variable to become shadowed, but the constraint that the bound type variable and the old type variable are equal would not take this into account.
2019-02-27Tweaks to C compilation to make it more usable for embedding into other programsAlasdair Armstrong
Can now set a prefix for generated C functions with -c_prefix so -c_prefix sail_ would give sail_execute_CGetPerm over zexecute_CGetPerm. We still have to use our standard name-mangling scheme to avoid possible collisions within the name. Can build C that doesn't expect the standard runtime, which leaves operations like read_memory, write_memory etc to be stubbed in by another C program including the generated Sail. Things like letbindings are still an issue because we rely on a very small runtime to initialize global letbindings and similar. -c_separate_execute splits the execute function apart in the generated C
2019-02-21Allow monomorphisation with C generationAlasdair
Run C tests with -O -Oconstant_fold -auto_mono
2019-02-21Fix specialization bug involving function annotations not matching valspecsAlasdair
Perhaps suprisingly to some, this did not mean that Sail was unable to typecheck the identify function. While doing this rename Effect_opt_pure to Effect_opt_none - as Effect_opt_pure was the effect equivalent of Typ_annot_opt_none, and actually means that the function definition lacks an effect annnotation, not that the function is actually pure, so this was *extremely* misleading. The effect_opt that actually indicated a function is pure was (and still is) the succinct: Effect_opt_aux (Effect_opt_effect (Effect_aux (Effect_set [], _)), _) In fact because in the grammar we only specify effects on valspecs (they can always be inferred for fundefs in the absence of a valspec) effect_opts are basically vestigial and are always Effect_opt_none. What might actually be super nice would be to remove rec_opt, effect_opt and typ_annot_opt from fundefs in ast.ml altogether and if we want them in the syntax just have them in parse_ast.ml and pull them into a valspec during the initial check.
2019-02-18Make sure we remove bitvector patterns within guardsAlasdair Armstrong
Fixes #34
2019-02-15Tweak intermediate language names for loop combinators to allow reparsingBrian Campbell
This should produce identical Lem and Coq output, but allow dumped Sail ASTs from the final stages of rewriting to be reread with -dmagic_hash.
2019-02-14Don't do any rewrites when checking files for EmacsAlasdair Armstrong
This makes sure we don't do any kind of re-writing or de-scatter any definitions when loading files into emacs. The difference here is that normally all files are processed together, but the emacs mode loads each file one by one. This is probably what we want to be doing anyway, so location information stays accurate for scattered functions for things like type-at-cursor commands and similar. Also fix some warnings. Fixes #32
2019-02-08Add missing functions to HOL monad wrapperThomas Bauereiss
Also make the rewriter keep failed assertions in output when pruning blocks.
2019-02-08Rewrite type definitions in rewrite_nexp_idsThomas Bauereiss
For example, in type xlen : Int = 64 type xlenbits = bits(xlen) rewrite the 'xlen' in the definition of 'xlenbits' to the constant 64 in order to simplify Lem generation. In order to facilitate this, pass through the global typing environment to the rewriting steps (in the AST itself, type definitions don't carry annotations with environments).
2019-02-08Remove dead code from type-checkerAlasdair
add_num_def and get_num_def are no longer used. The rewrite pass that used them would fail on Nexp_ids because of this, but seeing as that never happened we can probably assume that particular line of code is simply never touched by any of our models or test suite?
2019-02-07Monomorphisation tweaks for v8.5Thomas Bauereiss
Various tweaks to the monomorphisation rewrites. Disable old sizeof rewriting for Lem backend and rely on the type checker rewriting implicit arguments. Also avoid unifying nexps with sums, as this can easily fail due to commutativity and associativity.
2019-02-06Fix some testsAlasdair Armstrong
2019-02-06Remove all sizeof rewriting from C compilationAlasdair
All sizeof expressions now removed by the type-checker, so it's now properly a type error if they cannot be removed rather than a bizarre re-write error. This also greatly improves compilation speed overall, at the expense of the first type-checking pass.
2019-02-05Use more general types for lexps in the internal lets rewriting passBrian Campbell
This reduces the amount of unnecessary complex existentials that appear during rewriting.
2019-02-02Merge remote-tracking branch 'origin/sail2' into asl_flow2Alasdair
2019-02-01Fix missing typedef cases in OCaml outputAlasdair
2019-01-31Turn on cast insertion for -lem_mwords and revert b826df25Brian Campbell
now that cast insertion can handle RISC-V Also inserts specs for casts in they're not present
2019-01-29Merge branch 'sail2' into asl_flow2Thomas Bauereiss
2019-01-24Make recheck_defs_without_effects restore old flag properlyBrian Campbell
2019-01-23Make rewriting of E_assign a bit more robustThomas Bauereiss
2019-01-22Add a pragma for unrolling recursive functionsAlasdair Armstrong
For example in RISC-V for the translation table walk: $optimize unroll 2 val walk32 ... function walk32 ... would create two extra copies of the walk_32 function, walk_32_unroll_1 and walk_32_unroll_2, with only walk_32_unroll_2 being recursive. Currently we only support the case where we have $optimize unroll, directly followed by a valspec, then a function, but this should be generalised in future. This optimization nearly doubles the performance of RISC-V It is implemented using a new Optimize.recheck rewrite that replaces the ordinary recheck_defs pass. It uses a new typechecker check_with_envs function that allows re-writes to utilise intermediate typechecking environments to minimize the amount of AST checking that occurs, for performance reasons. Note that older Sail versions including the current OPAM release will complain about the optimize pragma, so this cannot be used until they become up to date with this change.
2019-01-17Fix bug in letbind_effects rewriteThomas Bauereiss
Don't wrap effectful expressions in E_internal_return
2019-01-14Add a function to perform re-writes in parallelAlasdair
rewrite_defs_base_parallel j is the same as rewrite_defs_base except it performs the re-writes in j parallel processes. Currently only the trivial_sizeof re-write is parallelised this way with a default of 4. This works on my machine (TM) but may fail elsewhere. Because 2019 OCaml concurrency support is lacking, we use Unix.fork and Marshal.to_channel to send the info from the child processes performing the re-write back to the parent. Also fix a missing case in pretty_print_lem
2019-01-14Make rewriting of foreach loops for Lem more robustThomas Bauereiss
Bind loop bounds to type variables, and don't pull existential variables out of context
2019-01-14Merge remote-tracking branch 'origin/sail2' into asl_flow2Alasdair
2019-01-11Updates for sail-arm releaseAlasdair Armstrong
We want to ensure that no_devices.sail and devices.sail have the same effect footprint, because with a snapshot-type release in sail-arm, we can't rebuild the spec with asl_to_sail every time we switch from running elf binaries to booting OS's. This commit allows registers to have arbitrary effects, so registers that are really representing memory-mapped devices don't have to have the wmem/rmem effect.
2019-01-10Fixes so 8.5 with vector instructions compiles to CAlasdair Armstrong
2019-01-08Improvements for v85Alasdair Armstrong
2019-01-02Coq: tweak recently introduced type check to ignore effectsBrian Campbell
2018-12-31Last rewrite reordering needs more typecheckingBrian Campbell
2018-12-31Coq: move function clause merging to keep measure argument intactBrian Campbell
2018-12-30Sort dependencies of termination measures properlyBrian Campbell
2018-12-29Add separate termination_measure declarationsBrian Campbell
2018-12-26More cleanupAlasdair Armstrong
Remove unused name schemes and DEF_kind
2018-12-26Some cleanupAlasdair Armstrong
2018-12-22Improve error messages and debuggingAlasdair Armstrong
Work on improving the formatting and quality of error messages When sail is invoked with sail -i, any type errors now drop the user down to the interactive prompt, with the interactive environment being the environment at the point the type error occurred, this means the typechecker state can be interactively queried in the interpreter to help diagnose type errors.
2018-12-21Expand synonyms in generated mapping val-specsAlasdair Armstrong
This ensures that mappings round-trip through the pretty-printer and parser unchanged Remove guarded_pats rewrite from C compilation. It causes a large increase in compilation time due to how it interacts with flow typing/pattern literal re-writing/and sizeof-rewriting
2018-12-20Fix monomorpisation tests with typechecker changesAlasdair Armstrong
Add an extra argument for Type_check.prove for the location of the prove call (as prove __POS__) to help debug SMT related issues
2018-12-18Fix rewriter issuesAlasdair Armstrong
Fixes some re-writer issues that was preventing RISC-V from building with new flow-typing constraints. Unfortunately because the flow typing now understands slightly more about boolean variables, the very large nested case statements with matches predicates produced by the string-matching end up causing a huge blowup in the overall compilation time.
2018-12-18Store function instantiation information within annotations, so we don'tAlasdair
have to recompute it, which can be very expensive for very large specifications Also additional flow typing and fixes for boolean type variables
2018-12-13Merge remote-tracking branch 'origin/sail2' into asl_flowAlasdair
2018-12-12Move much of recursive function termination to a rewriteBrian Campbell
It now includes updating the effects so that morally pure recursive functions can be turned into this impure termination-by-assertion form.
2018-12-12Add a test case for various simple boolean propertiesAlasdair Armstrong
test/typecheck/pass/tautology.sail constaints tests of various boolean properties, e.g. // de Morgan _prove(constraint(not('p | 'q) <--> not('p) & not('q))); _prove(constraint(not('p & 'q) <--> not('p) | not('q))); introduce a new _not_prove case which allows us to assert in tests that a constraint is not provable. This test essentially tests that constraints map to sensible problems in the SMT solver, without testing flow typing or any other features. Add a script test/typecheck/update_errors.sh, which regenerates the expected error messages. Testing that type-checking failures is important, but can be brittle when the error messages change for inconsequential reasons. This script automates fixing this. Also ensure that this test case works correctly in Lem
2018-12-12Generalise existentials for non-integer type variablesAlasdair
2018-12-11Initial attempt at using termination measures in CoqBrian Campbell
This only applies to recursive functions and uses the termination measure merely as a limit to the recursive call depth, rather than proving the measure correct.