Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flattening app/abs/arrow nodes in Reflection #3171

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 98 additions & 12 deletions ocaml/fstar-lib/generated/FStar_Reflection_V2_Builtins.ml

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

45 changes: 45 additions & 0 deletions src/reflection/FStar.Reflection.V2.Builtins.fst
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,47 @@ let rec pack_pat p : S.pat =
wrap <| Pat_var bv
| Pat_Dot_Term eopt -> wrap <| Pat_dot_term eopt

let rec canon_app (t:term) : term =
let t = t |> SS.compress_subst in
match t.n with
| Tm_app {hd; args} -> begin
let hd = canon_app hd in
match (SS.compress_subst hd).n with
| Tm_app {hd=hd'; args=args'} ->
S.mk (Tm_app {hd=hd'; args=args'@args}) t.pos
| _ -> t
end
| _ -> t

let rec canon_abs (t:term) : term =
let t = t |> SS.compress_subst in
match t.n with
| Tm_abs {bs; body; rc_opt=None} -> begin
let body = canon_abs body in
match (SS.compress_subst body).n with
| Tm_abs {bs=bs'; body=body'; rc_opt} ->
S.mk (Tm_abs {bs=bs@bs'; body=body'; rc_opt}) t.pos
| _ -> t
end
| _ -> t

let rec canon_arrow (t:term) : term =
let t = t |> SS.compress_subst in
match t.n with
| Tm_arrow {bs; comp} ->
begin match comp.n with
| Total t' -> begin
let t' = canon_arrow t' in
match (SS.compress_subst t').n with
| Tm_arrow {bs=bs'; comp=comp'} ->
S.mk (Tm_arrow {bs=bs@bs'; comp=comp'}) t.pos
| _ -> t
end
(* Two nested arrows *)
| _ -> t
end
| _ -> t

// TODO: pass in range?
let pack_ln (tv:term_view) : term =
match tv with
Expand All @@ -388,13 +429,17 @@ let pack_ln (tv:term_view) : term =
mk_Tm_uinst (S.fv_to_tm fv) us

| Tv_App (l, (r, q)) ->
canon_app <| (
let q' = pack_aqual q in
U.mk_app l [(r, q')]
)

| Tv_Abs (b, t) ->
canon_abs <|
mk (Tm_abs {bs=[b]; body=t; rc_opt=None}) t.pos // TODO: effect?

| Tv_Arrow (b, c) ->
canon_arrow <|
mk (Tm_arrow {bs=[b]; comp=c}) c.pos

| Tv_Type u ->
Expand Down
Loading