From 1fe8f33fce5aaaaea82fc54b6d198ffc9d7e1eeb Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Wed, 7 Mar 2018 15:42:24 +0000 Subject: Make union types consistent in the AST 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 --- src/spec_analysis.ml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/spec_analysis.ml') diff --git a/src/spec_analysis.ml b/src/spec_analysis.ml index 371acfdc..74312d9b 100644 --- a/src/spec_analysis.ml +++ b/src/spec_analysis.ml @@ -289,9 +289,7 @@ let init_env s = Nameset.singleton s let typ_variants consider_var bound tunions = List.fold_right - (fun (Tu_aux(t,_)) (b,n) -> match t with - | Tu_id id -> Nameset.add (string_of_id id) b,n - | Tu_ty_id(t,id) -> Nameset.add (string_of_id id) b, fv_of_typ consider_var b n t) + (fun (Tu_aux(Tu_ty_id(t,id),_)) (b,n) -> Nameset.add (string_of_id id) b, fv_of_typ consider_var b n t) tunions (bound,mt) -- cgit v1.2.3