summaryrefslogtreecommitdiff
path: root/src/monomorphise.ml
AgeCommit message (Collapse)Author
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-31fix some compiler warningsJon French
2018-08-28fix some compiler not-matched warnings about Typ_bidir and Typ_internal_unknownJon French
2018-08-28add __POS__ argument to Err_unreachable for better error reportingJon French
2018-08-07Improve cast introduction for LemBrian Campbell
Handles mutable variables and conditionals (there are still some corner cases that don't appear in Aarch64 to do). The pretty printer is now back to preferring to use concrete types, but has a special case for casts to print more general types.
2018-08-03Fix existential variable problems in monomorphisationBrian Campbell
One due to using raw types from the type checker in casts without trying to turn them into sane types, the other due to forgetting to use the constraint when trying to simplify sizes in existential types. Both triggered because the type checker now records more specific types.
2018-07-27Remove unused U_effect constructorAlasdair Armstrong
2018-07-27Make type annotations abstract in type_check.mliAlasdair Armstrong
Rather than exporting the implementation of type annotations as type tannot = (Env.t * typ * effect) option we leave it abstract as type tannot Some additional functions have been added to type_check.mli to work with these abstract type annotations. Most use cases where the type was constructed explicitly can be handled by using either mk_tannot or empty_tannot. For pattern matching on a tannot there is a function val destruct_tannot : tannot -> (Env.t * typ * effect) option Note that it is specifically not guaranteed that using mk_tannot on the elements returned by destruct_tannot re-constructs the same tannot, as destruct_tannot is only used to give the old view of a type annotation, and we may add additional information that will not be returned by destruct_tannot.
2018-07-26Some tweaks to not and or patternsAlasdair Armstrong
- Fix ambiguities in parser.mly - Ensure that no new identifiers are bound in or-patterns and not-patterns, by adding a no_bindings switch to the environment. These patterns shouldn't generate any bogus flow typing constraints because we just pass through the original environment without adding any possible constraints (although this does mean we don't get any flow typing from negated numeric literals right now, which is a TODO). - Reformat some code to match surrounding code. - Add a typechecking test case for not patterns - Add a typechecking test case for or patterns At least at the front end everything should work now, but we need to do a little bit more to rewrite these patterns away for lem etc.
2018-07-26Patterns: add or and not patternsAlastair Reid
These match the new ASL pattern constructors: - !p matches if the pattern p does not match - { p1, ... pn } matches if any of the patterns p1 ... pn match We desugar the set pattern "{p1, ... pn}" into "p1 | (p2 | ... pn)". ASL does not have pattern binding but Sail does. The rules at the moment are that none of the pattern can contain patterns. This could be relaxed by allowing "p1 | p2" to bind variables provided p1 and p2 both bind the same variables.
2018-07-25Remove unused internal AST nodesAlasdair Armstrong
E_internal_cast, E_sizeof_internal, E_internal_exp, E_internal_exp_user, E_comment, and E_comment_struc were all unused. For a lem based interpreter, we want to be able to compile it to iUsabelle, and due to slowness inherent in Isabelle's datatype package we want to remove unused constructors in our AST type. Also remove the lem_ast backend - it's heavily bitrotted, and for loading the ARM ast into the interpreter it's just not viable to use this approach as it just doesn't scale. We really need a way to be able to serialise and deserialise the AST efficiently in Lem.
2018-07-24Move monomorphisation after mapping rewritesBrian Campbell
Fixes monomorphisation on files using mappings. Also extended constant propagation to handle pattern matches on bitvector expressions (because an earlier rewrite replaces the literals). Also moved L_undef rewriting because monomorphisation can handle them but not the replacement functions.
2018-06-07Fix a small bug in monomorphisationThomas Bauereiss
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-22Fix one part of cast introduction, leave another for laterBrian Campbell
2018-05-11More builtin names in constant propagationBrian Campbell
2018-05-11Actually use the correct type for singleton rewriting this timeBrian Campbell
2018-05-11Be much more careful to introduce the right bitvector casts to the right sizesBrian Campbell
2018-05-11Handle automatic existential unpacking in function application in mono analysisBrian Campbell
2018-05-11Use type from funcl in singleton rewritingBrian Campbell
The pattern types may be subtypes, using those caused it to try rewriting int parameters and failing
2018-05-04Add support for top-level values to monomorphisation singleton rewriteBrian Campbell
2018-05-04Fix mono cast introduction to avoid a checking to inference changeBrian Campbell
Adds return type to pattern so that the original function body is still type checked, rather than switching to type inference which may fail.
2018-05-04Start updating monomorphisationBrian Campbell
+ add additional lexp + update aarch64 mono demo source - still needs support for tyvars from assignments in dependency analysis
2018-04-20Have sign_extend in common Sail Lem library, use it and zero_extend inBrian Campbell
mono rewrites
2018-04-19Gloss over UInt/unsigned name difference in monomorphisationBrian Campbell
2018-04-18Rename BK_nat to BK_int to be consistent with source syntaxAlasdair Armstrong
2018-04-17Fix slicing in constant propagationBrian Campbell
2018-04-12Fill in some minor missing cases in monomorphisationBrian Campbell
2018-04-11Use more robust method of finding deps of new tyvars in mono analysisBrian Campbell
2018-04-11Make the atom to singleton type rewriter replace literals with guardsBrian Campbell
(previously the typechecker did this for all literal patterns, but now it's only necessary for the rewritten arguments)
2018-04-10Avoid rejecting reasonable pattern matches in monomorphisationBrian Campbell
(when they're not relevant)
2018-04-10Add basic reference support to monomorphisationBrian Campbell
2018-04-09Remove unnecessary restriction on complex nexp rewritingBrian Campbell
2018-04-09Stop vector_typ_args_of from failing when order is a variableBrian Campbell
Now it just returns the actual arguments and a separate function calculates the start index when required.
2018-04-06Generate better tyvar names for complex nexps in monomorphisationBrian Campbell
2018-04-04Use solver properly to simplify nexps in mono analysis, Lem printingBrian Campbell
Turn on complex nexp rewriting for mono by default (NB: solving is currently quite slow, will optimise)
2018-04-04Instantiate type properly when introducing mono castsBrian Campbell
(also reorder the phases a little)
2018-04-04Use valspec equations in monomorphisation analysisBrian Campbell
2018-04-04Add bitvector casts to funcl bodies when necessaryBrian Campbell
2018-04-04Initial rewrite to move complex nexps in fn sigs into constraintsBrian Campbell
(for monomorphisation, off for now because the analysis needs extended). Also tighten up orig_nexp, make Lem backend replace # in type variables.
2018-04-04Improve location information in mono dependency errorsBrian Campbell
2018-03-14Remove unnecessary size_itself_int uses in guards (for Lem)Brian Campbell
Doesn't remove them from function bodies because that can produce more work for the sizeof rewriting.
2018-03-13Add test for mutual recursion and monomorphisationBrian Campbell
2018-03-13Support a few more set constraints in monoBrian Campbell
2018-03-07Make union types consistent in the ASTAlasdair Armstrong
Previously union types could have no-argument constructors, for example the option type was previously: union option ('a : Type) = { Some : 'a, None } Now every union constructor must have a type, so option becomes: union option ('a : Type) = { Some : 'a, None : unit } The reason for this is because previously these two different types of constructors where very different in the AST, constructors with arguments were used the E_app AST node, and no-argument constructors used the E_id node. This was particularly awkward, because it meant that E_id nodes could have polymorphic types, i.e. every E_id node that was also a union constructor had to be annotated with a type quantifier, in constrast with all other identifiers that have unquantified types. This became an issue when monomorphising types, because the machinery for figuring out function instantiations can't be applied to identifier nodes. The same story occurs in patterns, where previously unions were split across P_id and P_app nodes - now the P_app node alone is used solely for unions. This is a breaking change because it changes the syntax for union constructors - where as previously option was matched as: function is_none opt = match opt { Some(_) => false, None => true } it is now matched as function is_none opt = match opt { Some(_) => false, None() => true } note that constructor() is syntactic sugar for constructor(()), i.e. a one argument constructor with unit as it's value. This is exactly the same as for functions where a unit-function can be called as f() and not as f(()). (This commit also makes exit() work consistently in the same way) An attempt to pattern match a variable with the same name as a union-constructor now gives an error as a way to guard against mistakes made because of this change. There is probably an argument for supporting the old syntax via some syntactic sugar, as it is slightly prettier that way, but for now I have chosen to keep the implementation as simple as possible. The RISCV spec, ARM spec, and tests have been updated to account for this change. Furthermore the option type can now be included from $SAIL_DIR/lib/ using $include <option.sail>
2018-02-27Make constant propagation of slicing more generalBrian Campbell
2018-02-22Curtail at more false assertionsBrian Campbell
(plus some adjustments for the test case)
2018-02-21Implement more builtins in constant propagationBrian Campbell
2018-02-21Cut out dead if branches according to the type environment during monoBrian Campbell
const progagation. Needed to avoid negative bitvector sizes on aarch64 Also propagate values found from "if var = const ...", which is needed in aarch64
2018-02-20Remove temporary debugging messageBrian Campbell