summaryrefslogtreecommitdiff
path: root/src/specialize.ml
AgeCommit message (Collapse)Author
2019-01-29Add an option to crudely slice a function out of a Sail modelBrian Campbell
Not ideal because it keeps everything that's not a function, but good enough for quick tests extracted from arm.
2019-01-08Improvements for v85Alasdair Armstrong
2018-12-26More cleanupAlasdair Armstrong
Remove unused name schemes and DEF_kind
2018-12-26Some cleanupAlasdair Armstrong
2018-12-12Generalise existentials for non-integer type variablesAlasdair
2018-12-11Fix most remaining tests on branchAlasdair
2018-12-08Compiling againAlasdair
Change Typ_arg_ to A_. We use it a lot more now typ_arg is used instead of uvar as the result of unify. Plus A_ could either stand for argument, or Any/A type which is quite appropriate in most use cases. Restore instantiation info in infer_funapp'. Ideally we would save this instead of recomputing it ever time we need it. However I checked and there are over 300 places in the code that would need to be changed to add an extra argument to E_app. Still some issues causing specialisation to fail however. Improve the error message when we swap how we infer/check an l-expression, as this could previously cause the actual cause of a type-checking failure to be effectively hidden.
2018-12-04Simplify kinds in the ASTAlasdair Armstrong
Rather than having K_aux (K_kind [BK_aux (BK_int, _)], _) represent the Int kind, we now just have K_aux (K_int, _). Since the language is first order we have no need for fancy kinds in the AST.
2018-10-11Change the function type in the ASTAlasdair
Changes the representation of function types in the ast from Typ_fn : typ -> typ to Typ_fn : typ list -> typ to more accurately represent their use in the various backends, where we often compile functions to either their curried representations as in Lem and Isabelle, or just multiple argument functions in C. There's still some oddity because a single pattern in a function clause can bind against multiple arguments, and maybe we want to forbid this in the future. The syntax also hasn't changed (yet), so in theory this change shouldn't break anything (but it invariably will...). In the future we would ideally require that a function with N arguments has exactly N patterns in its declaration, one for each argument so f : (x, y) -> z f _ = ... would be disallowed (as _ matches both x and y), forcing f(_, _) = z this would simply quite a few things, Also we could have a different syntax for function argument lists and tuples, because it's rather hard to define a function that actually takes a tuple with the syntax how it is now. Some issues I noticed when doing this refactoring: Line 1926 of Coq translation. untuple_args_pat is maybe no longer needed? However there's still some funnyness where a pattern can be used to bind multiple function arguments so maybe it still is. Line 2306 of monomorphisation. I simplified the logic here. I think it's equivalent now, but I could be wrong. Line 4517 of rewrites. I'm not sure what make_cstr_mappings is doing here, but hopefully the simpler version is the same.
2018-08-28fix some compiler not-matched warnings about Typ_bidir and Typ_internal_unknownJon French
2018-08-18Correctly specialise type annotation in polymorphic functionsAlasdair
2018-08-13Remove old specialisation code in specialize.mlAlasdair
2018-08-02Start working on a solution for correctly monomorphising polymorphic variant ↵Alasdair Armstrong
types
2018-07-27Remove unused U_effect constructorAlasdair Armstrong
2018-06-28Add tagged memory to C rts to cheri can be compiled to CAlasdair Armstrong
2018-06-27RTS: Add support for __ListConfigAlastair Reid
2018-06-27Make sure __SetConfig gets included in generated codeAlasdair Armstrong
2018-06-06Some work on improving error messagesAlasdair Armstrong
We now store the location where type variables were bound, so we can use this information when printing error messages. Factor type errors out into type_error.ml. This means that Type_check.check is now Type_error.check, as it previously it handled wrapping the type_errors into reporting_basic errors. Type_check.check' has therefore been renamed to Type_check.check.
2018-05-31Fixes to get ARM u-boot working in Sail.Alasdair Armstrong
Also fixes to C backend for compiling MIPS spec to C - Fix an issue with const correctness in internal_vector_update functions generated by C backend - Add builtins for MIPS to sail.h - Fix an issue where reg_deref didn't work when called on pointers to large bitvectors, i.e. vectors containing references to large bitfields as in the MIPS TLB code - Various bug fixes and changes for running U-boot on ARM model, including for interpreter and OCaml compilation. - Fix memory leak issues and incorrect shadowing for foreach loops - Update C header file. Fixes memory leak in memory read/write builtins. - Add aux constructor to ANF representation to hold environment information. - Fix undefined behavior caused by optimisation left shifting uint64_t vectors 64 or more times. Unfortunately there's more issues because the same happens for X >> 64 right shifts. It would make sense for this to be zero, because that would guarantee the property that ((X >> n) >> m) == (X >> (n + m)) but we probably need to do (X >> (n - 1) >> 1) in the optimisation to ensure that we don't cause UB. Shifting by 63 and then by 1 is well-defined, but shifting by 64 in one go isn't according to the C standard. This issue with right-shifts only occurs for zero-length vectors, so it's not a huge deal, but it's still annoying. - Add versions of print_bits and print_int that print to stderr. Follows OCaml convention of print/prerr. Should make things more explicit. Different backends had different ideas about where print should output to, not every backend needs to have this (e.g. theorem prover backends don't need to print) but having both stderr and stdout seperate and clear is useful for executable models (UART needs to be stdout, debug messages should be stderr).
2018-04-18Rename BK_nat to BK_int to be consistent with source syntaxAlasdair Armstrong
2018-03-22Fix C compilation for CHERI and MIPSAlasdair Armstrong
First, the specialisation of option types has been fixed by allowing the specialisation of constructor return types - this essentially means that a constructor, such as Some : 'a -> option('a) can get specialised to int -> option(int), rather than int -> option('a). This means that these constructors are treated like GADTs internally. Since this only happens just before the C translation, I haven't put much effort into making this very robust so far. Second, there was a bug in C compilation for the typing of return expressions in non-unit contexts, which has been fixed. Finally support for vector literals that are non-bitvectors has been added.
2018-03-13Polymorphic option types now compile to CAlasdair Armstrong
Fixed an issue whereby an option constructor that was never constructed, but only matched on, would cause compilation to fail. Temporarily fixed an issue where union types that can be entirely stack-allocated were not being treated as such, by simply heap-allocating all unions. Need to adapt the code generator to handle this case properly. Fixed a further small issue whereby multiple union types would confuse the type specialisation pass. Added a test case for compiling option types. RISCV now generates C code, but there are still some bugs that need to be squashed before it compile and work.
2018-03-09Specialise constructors for polymorphic unionsAlasdair Armstrong
Also work on making C backend compile RISC-V
2018-03-05Fix specialisation pass to handle polymorphic substitutionsAlasdair Armstrong
Can now handle when an instantiation introduces more polymorphism. We can now deal with the case where, for example, a type variable gets specialised in two two steps, e.g. 'a => list('a) => list(int). Also handle the case where a Type-kinded type variable gets substituted with an Int-polymorphic type, e.g. 'a => atom('n). This also fixes an issue where specialisation would loop due to generated type variable names. This was fixed by ensuring that when we convert an instantiation to a string to name the newly specialised definition, we ensure that any alpha-equivalent instantiations map to the same name.
2018-02-19Have generic vectors working in C backendAlasdair Armstrong
2018-02-15List support in C backendAlasdair Armstrong
2018-02-07Have exceptions working in C backendAlasdair Armstrong
2018-01-23Started working on C backend for sailAlasdair Armstrong
Also updated some of the documentation in the sail source code
2018-01-22Added rewriter that specializes all function calls in a specification.Alasdair Armstrong
This removes all type polymorphism, so we can generate optimized bitvector code and compile to languages without parametric polymorphism.
2018-01-18Modified unification so Type_check.instantiation_of works after sizeof rewritingAlasdair Armstrong
This change allows the AST to be type-checked after sizeof re-writing. It modifies the unification algorithm to better support checking multiplication in constraints, by using division and modulus SMT operators if they are defined. Also made sure the typechecker doesn't re-introduce E_constraint nodes, otherwise re-checking after sizeof-rewriting will re-introduce constraint nodes.