From 21a26461caf237783d93dacfad933fc6ef0fe0c0 Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Fri, 5 Apr 2019 17:03:33 +0100 Subject: Fix: Don't remove uncalled polymorphic constructors if they are matched upon Previously the specialization would remove any polymorphic union constructor that was never created anywhere in the specification. While this wasn't usually problematic, it does leave an edge case where such a constructor could be matched upon in a pattern, and then the resulting match would fail to compile as it would be matching on a constructor kind that doesn't exists. This should fix that issue by chaging the V_ctor_kind value into an F_ctor_kind fragment. Previously a polymorphic constructor-kind would have been represented by its mangled name, e.g. V_ctor_kind "zSome_unit" would now be represented as V_ctor_kind ("Some", unifiers, ty) where ty is a monomorphic version of the original constructor's type such that ctyp_unify original_ty ty = unifiers and the mangled name we generate is zencode_string ("Some_" ^ string_of_list "_" string_of_ctyp unifiers) --- test/c/unused_poly_ctor.expect | 1 + test/c/unused_poly_ctor.sail | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/c/unused_poly_ctor.expect create mode 100644 test/c/unused_poly_ctor.sail (limited to 'test/c') diff --git a/test/c/unused_poly_ctor.expect b/test/c/unused_poly_ctor.expect new file mode 100644 index 00000000..e55551e8 --- /dev/null +++ b/test/c/unused_poly_ctor.expect @@ -0,0 +1 @@ +y = 0xFFFF diff --git a/test/c/unused_poly_ctor.sail b/test/c/unused_poly_ctor.sail new file mode 100644 index 00000000..c752cb33 --- /dev/null +++ b/test/c/unused_poly_ctor.sail @@ -0,0 +1,18 @@ +default Order dec + +$include + +val "print_endline" : string -> unit + +union U('a: Type) = { + Err : 'a, + Ok : bits(16) +} + +function main((): unit) -> unit = { + let x : U(unit) = Ok(0xFFFF); + match x { + Err() => print_endline("error"), + Ok(y) => print_bits("y = ", y) + } +} -- cgit v1.2.3