diff options
| author | Alasdair Armstrong | 2018-03-07 15:42:24 +0000 |
|---|---|---|
| committer | Alasdair Armstrong | 2018-03-07 15:57:08 +0000 |
| commit | 1fe8f33fce5aaaaea82fc54b6d198ffc9d7e1eeb (patch) | |
| tree | 9b6f0b2cc5a1dae0884ca9634440d63a0d517487 /src/value.ml | |
| parent | 29686e8e3ce511b3c6834e797381b0724f1e27a1 (diff) | |
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 <option.sail>
Diffstat (limited to 'src/value.ml')
| -rw-r--r-- | src/value.ml | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/value.ml b/src/value.ml index 077ad883..f865fea1 100644 --- a/src/value.ml +++ b/src/value.ml @@ -434,6 +434,7 @@ let primops = ("sub_vec", value_sub_vec); ("read_ram", value_read_ram); ("write_ram", value_write_ram); + ("undefined_unit", fun _ -> V_unit); ("undefined_bit", fun _ -> V_bit Sail_lib.B0); ("undefined_int", fun _ -> V_int Big_int.zero); ("undefined_bool", fun _ -> V_bool false); |
