Skip to content

Commit 6433df9

Browse files
authored
Merge pull request #3981 from FStarLang/_taramana_prettify_types
Tactics.PrettifyTypes: some improvements on generated types
2 parents 6c8dc7f + df8c071 commit 6433df9

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

tests/tactics/Prettify.fst

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type myty =
1313
myty_pretty_right;
1414
Mkmyty_pretty0;
1515
Mkmyty_pretty1
16-
] (entry "_pretty" (`%myty))
16+
] (entry "myty_pretty" (`%myty))
1717

1818
(* Sanity check *)
1919
let right (x : myty) : r:myty_pretty{myty_pretty_right x == r} =
@@ -32,17 +32,17 @@ type named_ty =
3232
(named "Case1" ((named "x" int & int) & (named "y" int & string)))
3333
(named "Case2" (named "b" bool))
3434

35-
// bijection record disabled for now
36-
(*
3735
%splice[
3836
named_ty_pretty;
39-
Case1;
40-
Case2;
41-
named_ty_pretty_bij;
42-
] (entry "_pretty" (`%named_ty))
37+
Mknamed_ty_pretty_Case1;
38+
Mknamed_ty_pretty_Case2;
39+
// named_ty_pretty_bij; // bijection record disabled for now
40+
] (entry "named_ty_pretty" (`%named_ty))
4341

4442
// test bijection
4543

44+
// bijection record disabled for now
45+
(*
4646
let _ = assert (Inl ((1, 2), (3, "a")) >> named_ty_pretty_bij == Case1 1 2 3 "a")
4747
let _ = assert (Case2 false << named_ty_pretty_bij == Inr false)
4848
*)
@@ -51,22 +51,46 @@ let _ = assert (Case2 false << named_ty_pretty_bij == Inr false)
5151
type can't be called? *)
5252
// let test (i : named_ty_pretty) =
5353
// match i with
54-
// | Case1 _ _ _ _ ->
55-
// let _ = Case1?.x i in
56-
// let _ = Case1?.y i in
54+
// | Mknamed_ty_pretty_Case1 _ _ _ _ ->
55+
// let _ = Mknamed_ty_pretty_Case1?.x i in
56+
// let _ = Mknamed_ty_pretty_Case1?.y i in
5757
// ()
58-
// | Case2 _ ->
59-
// let _ = Case2?.b i in
58+
// | Mknamed_ty_pretty_Case2 _ ->
59+
// let _ = Mknamed_ty_pretty_Case2?.b i in
6060
// ()
6161

62+
let test_named_ty1 (i : named_ty_pretty) =
63+
match i with
64+
| Mknamed_ty_pretty_Case1 _ _ _ _
65+
| Mknamed_ty_pretty_Case2 _ ->
66+
()
67+
68+
(* Named test: *)
69+
type named_ty2 =
70+
either
71+
(named "Case1" ((named "x" int & int) & (named "y" int & string)))
72+
(named "Case2" (named "b" bool))
73+
74+
%splice[
75+
named_ty2_pretty;
76+
Mknamed_ty2_pretty_Case1;
77+
Mknamed_ty2_pretty_Case2;
78+
] (entry "named_ty2_pretty" (`%named_ty2))
79+
80+
let test_named_ty2 (i : named_ty2_pretty) =
81+
match i with
82+
| Mknamed_ty2_pretty_Case1 _ _ _ _
83+
| Mknamed_ty2_pretty_Case2 _ ->
84+
()
85+
6286
type t2 = tuple2 int int
63-
%splice[t2_pretty] (entry "_pretty" (`%t2))
87+
%splice[t2_pretty] (entry "t2_pretty" (`%t2))
6488

6589
type t3 = tuple2 int (either bool string)
66-
%splice[t3_pretty] (entry "_pretty" (`%t3))
90+
%splice[t3_pretty] (entry "t3_pretty" (`%t3))
6791

6892
type t4 = either t3 (tuple2 int (either bool string))
69-
%splice[t4_pretty; t4_pretty_left_right] (entry "_pretty" (`%t4))
93+
%splice[t4_pretty; t4_pretty_left_right] (entry "t4_pretty" (`%t4))
7094

7195
let inv (x:t4) = t4_pretty_left_right x
7296

@@ -79,7 +103,7 @@ type t5 =
79103
noextract
80104
noeq (* will only go to the generated type. *)
81105
unfold
82-
%splice[t5_quals; t5_quals_left_right] (entry "_quals" (`%t5))
106+
%splice[t5_quals; t5_quals_left_right] (entry "t5_quals" (`%t5))
83107

84108
type big =
85109
either int <|
@@ -126,4 +150,6 @@ type bigger =
126150
) bool
127151

128152
[@@no_auto_projectors] // makes it a bit faster
129-
%splice[] (entry "_pretty" (`%bigger))
153+
%splice[huger] (entry "huger" (`%bigger))
154+
155+
let _ = huger

ulib/FStar.Tactics.PrettifyType.fst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ let rec flatten_type (pretty_tynm : name) (ctr:nat) (t:parsed_type) : Tac (nat &
113113
ctr, Sum (aa @ bb)
114114
| Named s t ->
115115
let _, p = as_prod_type 0 t in
116-
ctr, Sum [(s, p)]
116+
assume (List.length pretty_tynm > 0);
117+
let _, s0 = unsnoc pretty_tynm in
118+
ctr, Sum [("Mk" ^ s0 ^ "_" ^ s, p)]
117119
| t ->
118120
let _, p = as_prod_type 0 t in
119121
assume (List.length pretty_tynm > 0);
@@ -451,7 +453,7 @@ let mk_bij cfg : Tac decls =
451453
[pack_sigelt sv]
452454

453455
[@@plugin]
454-
let entry (suf nm : string) : Tac decls =
456+
let entry (pretty_tynm nm : string) : Tac decls =
455457
// print ("ENTRY, n quals = " ^ string_of_int (List.length (splice_quals ())));
456458
// print ("ENTRY, n attrs = " ^ string_of_int (List.length (splice_attrs ())));
457459
let quals = splice_quals () in
@@ -462,7 +464,9 @@ let entry (suf nm : string) : Tac decls =
462464
// print ("def: " ^ term_to_string def);
463465
let at = parse_type def in
464466
// print ("at: " ^ parsed_type_to_string at);
465-
let pretty_tynm = add_suffix suf nm in
467+
assume (List.length nm > 0);
468+
let qns, _ = unsnoc nm in
469+
let pretty_tynm = qns @ [pretty_tynm] in
466470
let _, fat = flatten_type pretty_tynm 0 at in
467471
// print ("fat: " ^ flat_type_to_string fat);
468472

0 commit comments

Comments
 (0)