Skip to content

Commit

Permalink
Merge pull request #3341 from mtzguido/resugar
Browse files Browse the repository at this point in the history
Resugar: improve resugaring for projectors
  • Loading branch information
mtzguido authored Jul 3, 2024
2 parents a3fb0f5 + d2c3235 commit c061239
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 22 deletions.
52 changes: 34 additions & 18 deletions ocaml/fstar-lib/generated/FStar_Syntax_Resugar.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/syntax/FStar.Syntax.Resugar.fst
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,19 @@ let rec resugar_term' (env: DsEnv.env) (t : S.term) : A.term =
else None
| _ -> None
in
if Some? (is_projector e) && List.length args = 1 then
(* We have a projector, applied to at least one argument, and the first argument
is explicit (so not one of the parameters of the type). In this case we resugar nicely. *)
if Some? (is_projector e) && List.length args >= 1 && None? (snd (List.hd args)) then
let arg1 :: rest_args = args in
let (_, fi) = Some?.v (is_projector e) in
let arg = resugar_term' env (fst (List.hd args)) in
mk <| Project (arg, Ident.lid_of_ids [fi])
let arg = resugar_term' env (fst arg1) in
let h = mk <| Project (arg, Ident.lid_of_ids [fi]) in
(* Add remaining args if any. *)
rest_args |> List.fold_left (fun acc (a, q) ->
let aa = resugar_term' env a in
let qq = resugar_aqual env q in
mk (A.App (acc, aa, qq)))
h
else
let unsnoc (#a:Type) (l : list a) : (list a & a) =
let rec unsnoc' acc = function
Expand Down
14 changes: 13 additions & 1 deletion tests/error-messages/Bug3227.fst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ let proj (b : box (box (box int))) : int = b.x.x.x

type box2 (a:Type) = | Box2 : x:a -> box2 a

let test (b : box2 (box2 int)) = Box2? b && Box2? (Box2?.x b)
let test (b : box2 (box2 int)) = Box2? b && Box2? (Box2?.x b)

noeq
type boxf (a:Type) = { ff : a -> a }

let test2 (r : boxf int) = r.ff 5

noeq
type boxfi (a:Type) = { ff : (#_:a -> a) }

let test3 (r : boxfi int) = r.ff #5

let test4 (#a:Type) (r : boxf a) (x:a) : a = r.ff x
58 changes: 58 additions & 0 deletions tests/error-messages/Bug3227.fst.expected
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ type box2 (a: Type) = | Box2 : x: a -> Bug3227.box2 a


let test b = Box2? b && Box2? b.x
noeq
type boxf (a: Type) = { }

let test2 r = ff r 5
noeq
type boxfi (a: Type) = { }

let test3 r = ff r
let test4 r x = ff r x <: a
]
Exports: [
type box (a: Type) = { }
Expand All @@ -19,6 +28,15 @@ type box2 (a: Type) = | Box2 : x: a -> Bug3227.box2 a


let test b = Box2? b && Box2? b.x
noeq
type boxf (a: Type) = { }

let test2 r = ff r 5
noeq
type boxfi (a: Type) = { }

let test3 r = ff r
let test4 r x = ff r x <: a
]

Module before type checking:
Expand All @@ -32,6 +50,15 @@ type box2 (a: Type) = | Box2 : x: a -> Bug3227.box2 a


let test b = Box2? b && Box2? b.x
noeq
type boxf (a: Type) = { }

let test2 r = ff r 5
noeq
type boxfi (a: Type) = { }

let test3 r = ff r
let test4 r x = ff r x <: a
]
Exports: [
type box (a: Type) = { }
Expand All @@ -42,6 +69,15 @@ type box2 (a: Type) = | Box2 : x: a -> Bug3227.box2 a


let test b = Box2? b && Box2? b.x
noeq
type boxf (a: Type) = { }

let test2 r = ff r 5
noeq
type boxfi (a: Type) = { }

let test3 r = ff r
let test4 r x = ff r x <: a
]

Module after type checking:
Expand All @@ -61,6 +97,17 @@ val box2__uu___haseq: forall (a: Type). {:pattern Prims.hasEq (Bug3227.box2 a)}


let test b = Box2? b && Box2? b.x
noeq
type boxf (a: Type) = { ff:_: a -> a }


let test2 r = r.ff 5
noeq
type boxfi (a: Type) = { ff:a }


let test3 r = r.ff
let test4 r x = r.ff x <: a
]
Exports: [
type box (a: Type) = { x:a }
Expand All @@ -77,6 +124,17 @@ val box2__uu___haseq: forall (a: Type). {:pattern Prims.hasEq (Bug3227.box2 a)}


let test b = Box2? b && Box2? b.x
noeq
type boxf (a: Type) = { ff:_: a -> a }


let test2 r = r.ff 5
noeq
type boxfi (a: Type) = { ff:a }


let test3 r = r.ff
let test4 r x = r.ff x <: a
]

Verified module: Bug3227
Expand Down

0 comments on commit c061239

Please sign in to comment.