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

Add normalization step for tactics. #3460

Merged
merged 4 commits into from
Sep 11, 2024
Merged

Add normalization step for tactics. #3460

merged 4 commits into from
Sep 11, 2024

Conversation

gebner
Copy link
Contributor

@gebner gebner commented Sep 10, 2024

#1969 added normalization for impure lets in tactic execution, but this was gated on the reify step. The reify step is however also enabled in extraction, and then this heuristic can incorrectly remove effectful lets.

This PR adds a new tactics step in the normalizer, which is only enabled in tactic execution. The heuristic from #1969 is only enabled when this step is set, and no longer applies during extraction.

@mtzguido did pretty much all the work here, thank you!

@gebner gebner force-pushed the gebner_tactics_step branch from efe306e to bd44049 Compare September 10, 2024 22:57
@mtzguido
Copy link
Member

I thought this maybe only happened since we were bypassing the typechecker with the terms we were creating, but this was actually terrible:

$ cat X.fst
module X

let rec g () : Dv nat = g ()

let f () : Dv nat =
  let y = g () in
  42
$ ./bin/fstar.exe X.fst --codegen OCaml
Extracted module FStar.Pervasives.Native
Extracted module X
Verified module: X
All verification conditions discharged successfully

$ cat X.ml
open Prims
let rec (g : unit -> Prims.nat) = fun uu___ -> g ()
let (f : unit -> Prims.nat) = fun uu___ -> (Prims.of_int (42))

I'll add a bunch of tests for this later, it's a pretty serious mistake to not notice.

@gebner
Copy link
Contributor Author

gebner commented Sep 10, 2024

Wow, this was even happening in F* itself (see last commit--I did another bootstrapping round):

-let rec unexpected : 'a . Prims.string -> 'a = fun s -> unexpected s
-let rec unreachable : 'a . Prims.string -> 'a = fun s -> unreachable s
+let rec unexpected : 'a . Prims.string -> 'a =
+  fun s ->
+    let uu___ =
+      FStar_IO.debug_print_string
+        (Prims.strcat "Platform.Error.unexpected: " s) in
+    unexpected s
+let rec unreachable : 'a . Prims.string -> 'a =
+  fun s ->
+    let uu___ =
+      FStar_IO.debug_print_string
+        (Prims.strcat "Platform.Error.unreachable: " s) in
+    unreachable s

@mtzguido
Copy link
Member

mtzguido commented Sep 10, 2024

I added a test to check that a thing like the snippet above actually diverges (== reaches a 1s timeout).

@mtzguido mtzguido enabled auto-merge September 10, 2024 23:46
@mtzguido mtzguido merged commit 309b2d6 into master Sep 11, 2024
3 checks passed
@mtzguido mtzguido deleted the gebner_tactics_step branch September 11, 2024 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants