Skip to content

Commit

Permalink
Merge pull request #3409 from mtzguido/tac_fix
Browse files Browse the repository at this point in the history
normalizer: a fix for a plugin returned by a function
  • Loading branch information
mtzguido authored Aug 26, 2024
2 parents a93d97f + 3e54ed5 commit f5de9de
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 20 deletions.
42 changes: 30 additions & 12 deletions ocaml/fstar-lib/generated/FStar_Syntax_Util.ml

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

8 changes: 5 additions & 3 deletions ocaml/fstar-lib/generated/FStar_TypeChecker_Normalize.ml

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

9 changes: 7 additions & 2 deletions src/syntax/FStar.Syntax.Util.fst
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,19 @@ let head_and_args t =
| Tm_app {hd=head; args} -> head, args
| _ -> t, []

let rec head_and_args_full t =
let rec __head_and_args_full unmeta t =
let t = compress t in
match t.n with
| Tm_app {hd=head; args} ->
let (head, args') = head_and_args_full head
let (head, args') = __head_and_args_full unmeta head
in (head, args'@args)
| Tm_meta {tm} when unmeta ->
__head_and_args_full unmeta tm
| _ -> t, []

let head_and_args_full t = __head_and_args_full false t
let head_and_args_full_unmeta t = __head_and_args_full true t

let rec leftmost_head t =
let t = compress t in
match t.n with
Expand Down
6 changes: 3 additions & 3 deletions src/typechecker/FStar.TypeChecker.Normalize.fst
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ let reduce_primops norm_cb cfg (env:env) tm : term & bool =
if not cfg.steps.primops
then tm, false
else begin
let head, args = U.head_and_args tm in
let head, args = U.head_and_args_full tm in
let head_term, universes =
let head = SS.compress head in
let head = SS.compress (U.unmeta head) in
match head.n with
| Tm_uinst(fv, us) -> fv, us
| _ -> head, []
Expand Down Expand Up @@ -2429,7 +2429,7 @@ and do_rebuild (cfg:cfg) (env:env) (stack:stack) (t:term) : term =
norm cfg env stack' e

| Tm_app _ when cfg.steps.primops ->
let hd, args = U.head_and_args t in
let hd, args = U.head_and_args_full_unmeta t in
(match (U.un_uinst hd).n with
| Tm_fvar fv ->
begin
Expand Down
31 changes: 31 additions & 0 deletions tests/tactics/PluginReturned.fst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module PluginReturned

open FStar.Tactics.V2

(* This used to trip the normalizer due to an extra Meta_monadic
node on the returned and_elim or inspect (which are plugins). *)

assume val p : prop
assume val q : prop

let foo (b:bool) : Tac (term -> Tac unit) =
if b
then and_elim
else fail "no"

let test (x : squash (p /\ q)) =
assert True by (
let f = foo true in
f (quote x);
dump ""
)

let bar () : Tac (term -> Tac term_view) =
inspect

let test2 () =
assert True by (
let f = bar () in
let tv = f (`1) in
dump ""
)

0 comments on commit f5de9de

Please sign in to comment.