Skip to content

Commit

Permalink
bug-reports: add tests for #2894 and #2895
Browse files Browse the repository at this point in the history
  • Loading branch information
mtzguido committed May 7, 2023
1 parent e0d394c commit 9128afb
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
10 changes: 10 additions & 0 deletions tests/bug-reports/Bug2894.fst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Bug2894

#set-options "--warn_error -328" // unused let rec

type comparator_for (t:Type) = x:t -> y:t -> int

val term_eq : comparator_for int
let rec term_eq t1 t2 = 0

let t = term_eq
41 changes: 41 additions & 0 deletions tests/bug-reports/Bug2895.fst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Bug2895

// let rec not used
#set-options "--warn_error -328"

(* Recursive functions must be literals, but the annotated type
can be an _abbreviation_ of an arrow type, as in the examples that
follow. See issue #2895. *)

type foo (t:Type) = t -> bool
val f : foo string
let rec f (u : string) : bool = false
let test = f "123"

(* From the issue *)
type comparator_for (t:Type) = t -> t -> bool
val univ_eq : comparator_for int
let rec univ_eq (u1 u2 : int) : bool = false

(* A more involved variant, that could fail to extract due to coercions.
*)

type cmpres #t (x y : t) = bool
type comparator_for' (t:Type) = x:t -> y:t -> cmpres x y

let string_eq : comparator_for' string = fun x y -> x = y
let bool_eq : comparator_for' bool = fun x y -> x = y

type sb = | S of string | B of bool
val sb_eq : comparator_for' sb

(* The body of this function gets a coercion, as the branches
are of seemingly different types (due to the refinement). Extraction
must make sure to push that coercion in, or we otherwise define
an ocaml let rec where the body is an Obj.magic call (and not
a literal fun), which fails to compile. *)
let rec sb_eq (sb1 sb2 : sb) : cmpres sb1 sb2 =
match sb1, sb2 with
| S s1, S s2 -> string_eq s1 s2
| B b1, B b2 -> bool_eq b1 b2
| _ -> false
29 changes: 29 additions & 0 deletions tests/bug-reports/Bug2895.ml.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
open Prims
type 't foo = 't -> Prims.bool
let rec (f : Prims.string foo) = fun u -> false
let (test : Prims.bool) = f "123"
type 't comparator_for = 't -> 't -> Prims.bool
let rec (univ_eq : Prims.int comparator_for) = fun u1 -> fun u2 -> false
type ('t, 'x, 'y) cmpres = Prims.bool
type 't comparator_for' = 't -> 't -> ('t, unit, unit) cmpres
let (string_eq : Prims.string comparator_for') = fun x -> fun y -> x = y
let (bool_eq : Prims.bool comparator_for') = fun x -> fun y -> x = y
type sb =
| S of Prims.string
| B of Prims.bool
let (uu___is_S : sb -> Prims.bool) =
fun projectee -> match projectee with | S _0 -> true | uu___ -> false
let (__proj__S__item___0 : sb -> Prims.string) =
fun projectee -> match projectee with | S _0 -> _0
let (uu___is_B : sb -> Prims.bool) =
fun projectee -> match projectee with | B _0 -> true | uu___ -> false
let (__proj__B__item___0 : sb -> Prims.bool) =
fun projectee -> match projectee with | B _0 -> _0
let rec (sb_eq : sb comparator_for') =
Obj.magic
(fun sb1 ->
fun sb2 ->
match (sb1, sb2) with
| (S s1, S s2) -> Obj.repr (string_eq s1 s2)
| (B b1, B b2) -> Obj.repr (bool_eq b1 b2)
| uu___ -> Obj.repr false)
14 changes: 11 additions & 3 deletions tests/bug-reports/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SHOULD_VERIFY_CLOSED=Bug022.fst Bug024.fst Bug025.fst Bug026.fst Bug026b.fst Bug
Bug2635.fst Bug2637.fst Bug2641.fst Bug1486.fst PropProofs.fst \
Bug2684a.fst Bug2684b.fst Bug2684c.fst Bug2684d.fst Bug2659b.fst\
Bug2756.fst MutualRecPositivity.fst Bug2806a.fst Bug2806b.fst Bug2806c.fst Bug2806d.fst Bug2809.fst\
Bug2849a.fst Bug2849b.fst Bug2045.fst Bug2876.fst Bug2882.fst
Bug2849a.fst Bug2849b.fst Bug2045.fst Bug2876.fst Bug2882.fst Bug2895.fst Bug2894.fst

SHOULD_VERIFY_INTERFACE_CLOSED=Bug771.fsti Bug771b.fsti
SHOULD_VERIFY_AND_WARN_CLOSED=Bug016.fst
Expand Down Expand Up @@ -112,7 +112,7 @@ SHOULD_NOT_VERIFY_NOT_WORKING=Bug186.fst Bug397b.fst
SHOULD_EXTRACT_CLOSED=Bug086.fst Bug314.fst Bug540.fst Bug541.fst Bug589.fst \
ExtractionBug2.fst Bug1101.fst Bug1485.fst Bug734.fst Bug310.fst \
Bug2058.fst RemoveUnusedTypars.B.fst RemoveUnusedTyparsIFace.B.fst \
PushPopProjectors.fst Bug2412.fst Bug2595.fst Bug2699.fst
PushPopProjectors.fst Bug2412.fst Bug2595.fst Bug2699.fst Bug2895.fst
#ExtractionBug03.fst

# Bug1479.fst Crashes when in CI with "Error: Unbound module FStar_Tactics_Effect"
Expand Down Expand Up @@ -192,6 +192,12 @@ Bug2699.ml:
Bug2699.extract: Bug2699.ml
diff -u --strip-trailing-cr Bug2699.ml Bug2699.ml.expected

Bug2895.ml:
$(FSTAR) $(FSTAR_DEFAULT_ARGS) --extract Bug2895 --codegen OCaml Bug2895.fst

Bug2895.extract: Bug2895.ml
diff -u --strip-trailing-cr Bug2895.ml Bug2895.ml.expected


RemoveUnusedTypars.B.extract: RemoveUnusedTypars.A.fst RemoveUnusedTypars.B.fst
$(FSTAR) $(FSTAR_DEFAULT_ARGS) --cache_checked_modules RemoveUnusedTypars.A.fst
Expand All @@ -213,10 +219,12 @@ RemoveUnusedTyparsIFace.B.extract: RemoveUnusedTyparsIFace.A.fst RemoveUnusedTyp
PushPopProjectors.extract: PushPopProjectors.fst
$(FSTAR) $(FSTAR_DEFAULT_ARGS) --odir out_$* --codegen FSharp $^

output-accept: Bug310.ml Bug2058.ml Bug2595.ml
output-accept: Bug310.ml Bug2058.ml Bug2595.ml Bug2699.ml Bug2895.ml
cp Bug310.ml Bug310.ml.expected
cp Bug2058.ml Bug2058.ml.expected
cp Bug2595.ml Bug2595.ml.expected
cp Bug2699.ml Bug2699.ml.expected
cp Bug2895.ml Bug2895.ml.expected

%.extract: %.fst
$(Q)mkdir -p out_$*
Expand Down

0 comments on commit 9128afb

Please sign in to comment.