Skip to content

Commit

Permalink
Merge pull request #3251 from FStarLang/gabriel_dont_normalize_domain…
Browse files Browse the repository at this point in the history
…_hnf

Do not normalize domains of arrows with HNF.
  • Loading branch information
mtzguido authored Apr 24, 2024
2 parents b5cb71b + 7e6fbe4 commit a1cb534
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
14 changes: 10 additions & 4 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.

2 changes: 1 addition & 1 deletion src/typechecker/FStar.TypeChecker.Env.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type step =
| ZetaFull //fixed points, even under blocked matches
| Exclude of step //the first three kinds are included by default, unless Excluded explicity
| Weak //Do not descend into binders
| HNF //Only produce a head normal form
| HNF //Only produce a head normal form: Do not descend into function arguments or into binder types
| Primops //reduce primitive operators like +, -, *, /, etc.
| Eager_unfolding
| Inlining
Expand Down
3 changes: 2 additions & 1 deletion src/typechecker/FStar.TypeChecker.Normalize.fst
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,8 @@ let rec norm : cfg -> env -> stack -> term -> term =
then rebuild cfg env stack (closure_as_term cfg env t)
else let bs, c = open_comp bs c in
let c = norm_comp cfg (bs |> List.fold_left (fun env _ -> dummy::env) env) c in
let t = arrow (norm_binders cfg env bs) c in
let bs = if cfg.steps.hnf then (close_binders cfg env bs)._1 else norm_binders cfg env bs in
let t = arrow bs c in
rebuild cfg env stack t

| Tm_ascribed {tm=t1; eff_opt=l} when cfg.steps.unascribe ->
Expand Down
23 changes: 23 additions & 0 deletions tests/tactics/WeakVsHNF.fst
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,26 @@ let _ = assert True
debug ("WHNF : " ^ term_to_string t);
guard (term_eq t (`(fun () -> W (1 + 1))))
)

let b = unit
let _ = assert True
by (let t0 = `(b -> b) in
debug "";
debug ("Term : " ^ term_to_string t0);

let t = norm_term [delta] t0 in
debug ("Full : " ^ term_to_string t);
guard (term_eq t (`(unit -> unit)));

let t = norm_term [delta; weak] t0 in
debug ("Weak : " ^ term_to_string t);
guard (term_eq t (`(b -> b)));

let t = norm_term [delta; hnf] t0 in
debug ("HNF : " ^ term_to_string t);
guard (term_eq t (`(b -> unit)));

let t = norm_term [delta; weak; hnf] t0 in
debug ("WHNF : " ^ term_to_string t);
guard (term_eq t (`(b -> b)))
)
2 changes: 1 addition & 1 deletion ulib/FStar.Pervasives.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ val simplify : norm_step
(** Weak reduction: Do not reduce under binders *)
val weak : norm_step

(** Head normal form *)
(** Head normal form: Do not reduce in function arguments or in binder types *)
val hnf : norm_step

(** Reduce primitive operators, e.g., [1 + 1 ~> 2] *)
Expand Down

0 comments on commit a1cb534

Please sign in to comment.