summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)Author
2017-06-29Rewrite bitvector patternsThomas Bauereiss
Seems to work for CHERI-MIPS, but still a few things to be done, e.g. collecting let bindings for variables bound in bitvector patterns
2017-06-29Added a large test case to the test-suiteAlasdair Armstrong
Commented out some buggy re-sugaring logic from pretty_print_common where it re-sugared vectors incorrectly Fixed a bug where the type checker forgot to preserve type signatures in top-level letbinds
2017-06-29Created prelude.sail for initial typing environmentAlasdair Armstrong
Other things: * Cleaned up several files a bit * Fixed a bug in the parser where (deinfix |) got parsed as (definfix ||) * Turned of the irritating auto-indent in sail-mode.el
2017-06-29Propagate type information from reducing case expressionsBrian Campbell
2017-06-29Ocamlbuild targets should always be remadeBrian Campbell
2017-06-29beginnings of a sail library test suite.Robert Norton
2017-06-29Added support for set constraintsAlasdair Armstrong
Also added some additional tests in test/typecheck
2017-06-29Various improvements to typecheckerAlasdair Armstrong
Added vector concatenation patterns. Currently slightly more restrictive than before as each subvector's length must be inferrable from just that particular subvector - this may require additional type annotations in certain vector patterns. How exactly weird vector patterns, such as incrementing and decrementing vectors appearing in the same pattern, as well as patterns with funny start indexes should be dealt with correctly is unclear. It's probably best to be as restrictive as possible to avoid unsoundness bugs. Added a new option -ddump_tc_ast which dumps the (new) typechecked AST to stdout. Also added a new option -dno_cast which disables implicit casting in the typechecker. These options can be used in conjunction to dump the typechecked ast (which has all implicit casts resolved), and then re-typecheck it as a way to check that the typechecker is indeed resolving all casts correctly, and is reconstructing a fully type correct AST. The run_tests.sh script in test/typecheck has been modified to do this. Removed the dependency on Type_internal.ml from pretty_print_sail.ml. This means that we can no longer pretty print certain internal constructs produced by the old typechecker, but on the plus side it means that the sail pretty printer is type system agnostic and works with any annotation AST, irregardless of the type of annotations. Also fixed a few bugs where certain constructs would be pretty printed incorrectly.
2017-06-28User defined overloaded operatorsAlasdair Armstrong
New typechecker has no builtin overloaded operators - instead can now write something in SAIL like: overload (deinfix +) [id1; id2; id3] to set up functions id1, id2, and id3 as overloadings for the + operator. Any identifier can be overloaded, not just infix ones. This is done in a backwards compatible way, so the old typechecker removes the DEF_overload nodes from the ast so the various backends never see it.
2017-06-28Improvements to implicit type castingAlasdair Armstrong
Added a new feature for implicit casts - now allowable implicit casts can be specified by the user via a valspec such as val cast forall Type 'a, Type 'b. 'a -> 'b effect pure cast_anything with a new AST constructor to represent this as VS_cast_spec. This constructor is removed and replaced with the standard val spec by the old typechecker for backwards compatability, so it's only used by the new typechecker, and won't appear in the ast once it reaches the backends. Also added Num as a synonym for the Nat kind in the parser, via the confusingly named NatNum token (Num by itself was already taken for a numeric constant).
2017-06-28Reduce simple enumeration cases during monomorphisationBrian Campbell
2017-06-28Use more plausible type for E_caseBrian Campbell
(Previously it used the last branch's type!)
2017-06-27More features in bi-directional typecheckerAlasdair Armstrong
Can now typecheck: * register fields in expressions, e.g. CP0Status.IM * register fields in l-expressions, e.g. CP0Cause.CE := 0b00 * functions without valspecs, provided their types are easily inferable Still need to be able to treat a register-typed register as a vector for most of mips model to typecheck, as well as bitvector patterns, but it's like 90% there.
2017-06-26Added register fields for l-values expressions, and enumerationsAlasdair Armstrong
2017-06-24Added implicit castingAlasdair Armstrong
Added support for implicit casting to the bi-directional type checker. The casts can be any user-specified function, and in princple don't have to be hardcoded. This allows us to typecheck definitions such as function bit[64] rGPR idx = { if idx == 0 then 0 else GPR[idx] } in the MIPS spec, which involves lots of casting from integers to bitvectors, as well as casting from a named register to it's value (implicit dereferencing).
2017-06-23Added support for overloaded operatorsAlasdair Armstrong
2017-06-23Support for more sail constructsAlasdair Armstrong
Added support for: * Register type declarations * Undefined literals * Exit statement * Toplevel let statements * Vector literals i.e. [a, b, c] * Binary bitvector literals * Hex bitvector literals Patched the parser so you can actually write 2**'n - 1 in a nexp. The parser rules for nexps are a bit strange, and there didn't seem to be anyway to write this before without it causing a parse error. Can now typecheck up to line 332 of mips_prelude in mips/, but need to add support for the implict passing of registers by names to go any further, which should be fun...
2017-06-23Get rid of bogus singleton pattern warningsBrian Campbell
2017-06-23Add option for monomorphisation splittingBrian Campbell
2017-06-23Basic constant propagation for partial monomorphisationBrian Campbell
2017-06-22Added basic if statements without flow constraintsAlasdair Armstrong
2017-06-22Added vector subrange support, and testsAlasdair Armstrong
2017-06-22Added support for vector append and indexingAlasdair Armstrong
2017-06-22Can now typecheck register declarations and assignmentsAlasdair Armstrong
Can now properly typecheck register declarations and assignments. Also better support for assignments to mutable variables. Assignment to immutable let bound variables is disallowed as it should be, and casts when assiging to existing bound variables should be handled properly. Added additional tests for these new features, and a new option -just_check that allows the new checker to be run without the old.
2017-06-22Added support for bitvectorsAlasdair Armstrong
Added basic support for vector types, and fixed various bugs. Also added some basic tests for these features in test/typecheck.
2017-06-22fix three different copies of the hardware_quot function to do proper ↵Robert Norton
trucation towards zero. Previous version was incorrect if result was exact and a<0 and b>0.
2017-06-22add a 'print' built-in function handy for writing sail tests.Robert Norton
2017-06-22Initial partial monomorphisation workBrian Campbell
Splits specified pattern matches on enumerations (other types to be added later); no constant propogation yet.
2017-06-21MergeThomas Bauereiss
2017-06-21Pretty-print bitvector expressionsThomas Bauereiss
- Add case distinctions between bitvector types and vectors of other element types (e.g. registers) and use the corresponding operations (i.e. "bvslice", "bvaccess", etc for the former, and "slice", "access", etc for the latter) when pretty-printing expressions - Add type annotations to expressions when the type includes bitvectors with concretely known length - Update state.lem to use bitvectors (in the interface, at least; internally, bitvectors are still stored as bit lists for now, since that makes it easier to support storing different registers with different lengths) This has been tested with the CHERI-MIPS model with some success, but some things are still missing: - Bitvector patterns are not handled yet - Some bitvector length monomorphisation is needed in a few places of the model - Some type annotations are missing, because the (old) Sail type checker does not infer bitvector lengths in some instances where one would hope it to do that; this should be checked with the new type checker
2017-06-19Fix Show on Lem bitvectorBrian Campbell
2017-06-16Some small changes to bi-directional checkerAlasdair Armstrong
2017-06-16Some Isabelle fixes for word version of sail_valuesBrian Campbell
2017-06-15Pretty-print bitvector typesThomas Bauereiss
Next up: Expressions, patterns
2017-06-15Added support for default order declarations.Alasdair Armstrong
2017-06-15Prototype Bi-directional type checking algorithm for sailAlasdair Armstrong
Started work on a bi-directional type checking algorithm for sail based on Mark and Neel's typechecker for minisail in idl repository. It's a bit different though, because we are working with the unmodified sail AST, and not in let normal-form. Currently, we can check a fragment of sail that includes pattern matching (in both function clauses and switch statements), numeric constraints (but not set constraints), function application, casts between numeric types, assignments to local mutable variables, sequential blocks, and (implicit) let expressions. For example, we can correctly typecheck the following program: val forall Nat 'n, Nat 'm. ([:'n + 20:], [:'m:]) -> [:'n + 20 + 'm:] effect pure plus val forall Nat 'n, 'n <= -10. [:'n:] -> [:'n:] effect pure minus_ten_id val forall Nat 'n, 'n >= 10. [:'n:] -> [:'n:] effect pure ten_id val forall Nat 'N, 'N >= 63. [|10:'N|] -> [|10:'N|] effect pure branch function forall Nat 'N, 'N >= 63. [|10:'N|] branch x = { switch x { case ([|10:30|]) y -> y case ([:31:]) _ -> sizeof 'N case ([|31:40|]) _ -> plus(60,3) } } and branch (([|51:63|]) _) = ten_id(sizeof 'N) The typechecker has been set up so it can produce derivation trees for the typing judgements and constraints, so for the above program we have: Checking function branch Adding local binding x :: range<10, 'N> | Check { switch x { case (range<10, 30>) y -> y case (atom<31>) _ -> sizeof 'N case (range<31, 40>) _ -> plus(60, 3)} } <= range<10, 'N> | | Check switch x { case (range<10, 30>) y -> y case (atom<31>) _ -> sizeof 'N case (range<31, 40>) _ -> plus(60, 3)} <= range<10, 'N> | | | Infer x => range<10, 'N> | | Subset 'N >= 63 |- {'fv1 | 10 <= 'fv1 & 'fv1 <= 30} {'fv0 | 10 <= 'fv0 & 'fv0 <= 'N} | | Adding local binding y :: range<10, 30> | | | Check y <= range<10, 'N> | | | | Infer y => range<10, 30> | | | Subset 'N >= 63 |- {'fv4 | 10 <= 'fv4 & 'fv4 <= 30} {'fv3 | 10 <= 'fv3 & 'fv3 <= 'N} | | Subset 'N >= 63 |- {'fv7 | 31 <= 'fv7 & 'fv7 <= 31} {'fv6 | 10 <= 'fv6 & 'fv6 <= 'N} | | | Check sizeof 'N <= range<10, 'N> | | | | Infer sizeof 'N => atom<'N> | | | Subset 'N >= 63 |- {'fv10 | 'N <= 'fv10 & 'fv10 <= 'N} {'fv9 | 10 <= 'fv9 & 'fv9 <= 'N} | | Subset 'N >= 63 |- {'fv13 | 31 <= 'fv13 & 'fv13 <= 40} {'fv12 | 10 <= 'fv12 & 'fv12 <= 'N} | | | Check plus(60, 3) <= range<10, 'N> | | | | | Infer 60 => atom<60> | | | | | Infer 3 => atom<3> | | | | Infer plus(60, 3) => atom<((60 - 20) + (20 + 3))> | | | Subset 'N >= 63 |- {'fv20 | ((60 - 20) + (20 + 3)) <= 'fv20 & 'fv20 <= ((60 - 20) + (20 + 3))} {'fv19 | 10 <= 'fv19 & 'fv19 <= 'N} Subset 'N >= 63 |- {'fv23 | 51 <= 'fv23 & 'fv23 <= 63} {'fv22 | 10 <= 'fv22 & 'fv22 <= 'N} | Check ten_id(sizeof 'N) <= range<10, 'N> | | | Infer sizeof 'N => atom<'N> | | Prove 'N >= 63 |- 'N >= 10 | | Infer ten_id(sizeof 'N) => atom<'N> | Subset 'N >= 63 |- {'fv28 | 'N <= 'fv28 & 'fv28 <= 'N} {'fv27 | 10 <= 'fv27 & 'fv27 <= 'N} Judgements are displayed in the order they occur - inference steps go inwards bottom up, while checking steps go outwards top-down. The subtyping rules from Mark and Neel's check_sub rule all are verified using the Z3 constraint solver. I have been a set of tests in test/typecheck which aim to exhaustively test all the code paths in the typechecker, adding new tests everytime I add support for a new construct. The new checker is turned on using the -new_typecheck option, and can be tested (from the toplevel sail directory) by running: test/typecheck/run_tests.sh -new_typecheck (currently passes 32/32) and compared to the old typechecker by test/typecheck/run_tests.sh (currently passes 21/32)
2017-06-15Replace sail_values.lem with Brian's machine word versionThomas Bauereiss
2017-06-14Add a work-in-progress version of sail_values.lemBrian Campbell
that uses the new Lem machine words library.
2017-06-05Attempt to make Lem-prettyprinting of function clauses more robustThomas Bauereiss
Instead of abusing patterns as expressions, bind patterns to names (if they are more complex than an identifier or literal and don't have a name already) and generate expressions referring to those names (which we then pass as arguments to the auxiliary functions).
2017-06-05Fix pretty-printing of function clauses with wildcards for LemThomas Bauereiss
Before, wildcards sometimes ended up in the arguments to the function call on the RHS, in particular when using vector patterns (which implicitly introduce wildcards for the order and index parameters).
2017-06-02Add tag memory to Lem shallow embeddingThomas Bauereiss
2017-05-28fixed exmemShaked Flur
2017-05-26fix run_with builds after build_context gained an extra argument.Robert Norton
2017-05-24fixed missing _tag bitsShaked Flur
2017-05-24Merge branch 'master' of bitbucket.org:Peter_Sewell/sailShaked Flur
# Conflicts: # src/lem_interp/interp.lem # src/lem_interp/interp_inter_imp.lem # src/lem_interp/interp_interface.lem # src/parser.mly # src/pretty_print_lem.ml
2017-05-24added the exmem effect for AArch64 store-exclusiveShaked Flur
2017-05-24Change types of MEMr_tag, MEMval_tag and co. so that tag is separate from ↵Robert Norton
data and invent rmemt and wmvt effects for them. Extend the interpreter context to include lists of tagged memory read and write functions. The memory model must round down the address to the nearest capability aligned address when reading/writing tags. Remove TAGw which is no longer needed as a result.
2017-05-24it turns out that Zarith has a divide function which does truncation towards ↵Robert Norton
zero but it is not exposed via Bit_int_Z. Use it instead of rolling our own. Also ocaml / and mod already do the right thing.
2017-05-10Build Cheri_embed_types.thy together with Cheri_embed_sequential.thyThomas Bauereiss
2017-05-08add make rules to (attempt to) build arm and power ml.Robert Norton