-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3563 from mtzguido/tac_refactor
Tactics: refactor a bit to avoid a cycle
- Loading branch information
Showing
28 changed files
with
992 additions
and
965 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,3 @@ | ||
module FStar.Tactics.MApply | ||
|
||
open FStar.Reflection.V2 | ||
open FStar.Reflection.V2.Formula | ||
|
||
open FStar.Tactics.Effect | ||
open FStar.Stubs.Tactics.V2.Builtins | ||
open FStar.Tactics.NamedView | ||
open FStar.Tactics.V2.SyntaxHelpers | ||
open FStar.Tactics.V2.Derived | ||
open FStar.Tactics.V2.SyntaxCoercions | ||
|
||
open FStar.Tactics.Typeclasses | ||
let push1 #p #q f u = () | ||
let push1' #p #q f u = () | ||
|
||
(* | ||
* Some easier applying, which should prevent frustration | ||
* (or cause more when it doesn't do what you wanted to) | ||
*) | ||
val apply_squash_or_lem : d:nat -> term -> Tac unit | ||
let rec apply_squash_or_lem d t = | ||
(* Before anything, try a vanilla apply and apply_lemma *) | ||
try apply t with | _ -> | ||
try apply (`FStar.Squash.return_squash); apply t with | _ -> | ||
try apply_lemma t with | _ -> | ||
|
||
// Fuel cutoff, just in case. | ||
if d <= 0 then fail "mapply: out of fuel" else begin | ||
|
||
let ty = tc (cur_env ()) t in | ||
let tys, c = collect_arr ty in | ||
match inspect_comp c with | ||
| C_Lemma pre post _ -> | ||
begin | ||
let post = `((`#post) ()) in (* unthunk *) | ||
let post = norm_term [] post in | ||
(* Is the lemma an implication? We can try to intro *) | ||
match term_as_formula' post with | ||
| Implies p q -> | ||
apply_lemma (`push1); | ||
apply_squash_or_lem (d-1) t | ||
|
||
| _ -> | ||
fail "mapply: can't apply (1)" | ||
end | ||
| C_Total rt -> | ||
begin match unsquash_term rt with | ||
(* If the function returns a squash, just apply it, since our goals are squashed *) | ||
| Some rt -> | ||
// DUPLICATED, refactor! | ||
begin | ||
let rt = norm_term [] rt in | ||
(* Is the lemma an implication? We can try to intro *) | ||
match term_as_formula' rt with | ||
| Implies p q -> | ||
apply_lemma (`push1); | ||
apply_squash_or_lem (d-1) t | ||
|
||
| _ -> | ||
fail "mapply: can't apply (2)" | ||
end | ||
|
||
(* If not, we can try to introduce the squash ourselves first *) | ||
| None -> | ||
// DUPLICATED, refactor! | ||
begin | ||
let rt = norm_term [] rt in | ||
(* Is the lemma an implication? We can try to intro *) | ||
match term_as_formula' rt with | ||
| Implies p q -> | ||
apply_lemma (`push1); | ||
apply_squash_or_lem (d-1) t | ||
|
||
| _ -> | ||
apply (`FStar.Squash.return_squash); | ||
apply t | ||
end | ||
end | ||
| _ -> fail "mapply: can't apply (3)" | ||
end | ||
|
||
(* `m` is for `magic` *) | ||
let mapply0 (t : term) : Tac unit = | ||
apply_squash_or_lem 10 t | ||
(* This file just here to trigger extraction. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
module FStar.Tactics.MApply0 | ||
|
||
open FStar.Reflection.V2 | ||
open FStar.Reflection.V2.Formula | ||
|
||
open FStar.Tactics.Effect | ||
open FStar.Stubs.Tactics.V2.Builtins | ||
open FStar.Tactics.NamedView | ||
open FStar.Tactics.V2.SyntaxHelpers | ||
open FStar.Tactics.V2.Derived | ||
open FStar.Tactics.V2.SyntaxCoercions | ||
|
||
let push1 #p #q f u = () | ||
let push1' #p #q f u = () | ||
|
||
(* | ||
* Some easier applying, which should prevent frustration | ||
* (or cause more when it doesn't do what you wanted to) | ||
*) | ||
val apply_squash_or_lem : d:nat -> term -> Tac unit | ||
let rec apply_squash_or_lem d t = | ||
(* Before anything, try a vanilla apply and apply_lemma *) | ||
try apply t with | _ -> | ||
try apply (`FStar.Squash.return_squash); apply t with | _ -> | ||
try apply_lemma t with | _ -> | ||
|
||
// Fuel cutoff, just in case. | ||
if d <= 0 then fail "mapply: out of fuel" else begin | ||
|
||
let ty = tc (cur_env ()) t in | ||
let tys, c = collect_arr ty in | ||
match inspect_comp c with | ||
| C_Lemma pre post _ -> | ||
begin | ||
let post = `((`#post) ()) in (* unthunk *) | ||
let post = norm_term [] post in | ||
(* Is the lemma an implication? We can try to intro *) | ||
match term_as_formula' post with | ||
| Implies p q -> | ||
apply_lemma (`push1); | ||
apply_squash_or_lem (d-1) t | ||
|
||
| _ -> | ||
fail "mapply: can't apply (1)" | ||
end | ||
| C_Total rt -> | ||
begin match unsquash_term rt with | ||
(* If the function returns a squash, just apply it, since our goals are squashed *) | ||
| Some rt -> | ||
// DUPLICATED, refactor! | ||
begin | ||
let rt = norm_term [] rt in | ||
(* Is the lemma an implication? We can try to intro *) | ||
match term_as_formula' rt with | ||
| Implies p q -> | ||
apply_lemma (`push1); | ||
apply_squash_or_lem (d-1) t | ||
|
||
| _ -> | ||
fail "mapply: can't apply (2)" | ||
end | ||
|
||
(* If not, we can try to introduce the squash ourselves first *) | ||
| None -> | ||
// DUPLICATED, refactor! | ||
begin | ||
let rt = norm_term [] rt in | ||
(* Is the lemma an implication? We can try to intro *) | ||
match term_as_formula' rt with | ||
| Implies p q -> | ||
apply_lemma (`push1); | ||
apply_squash_or_lem (d-1) t | ||
|
||
| _ -> | ||
apply (`FStar.Squash.return_squash); | ||
apply t | ||
end | ||
end | ||
| _ -> fail "mapply: can't apply (3)" | ||
end | ||
|
||
(* `m` is for `magic` *) | ||
let mapply0 (t : term) : Tac unit = | ||
apply_squash_or_lem 10 t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module FStar.Tactics.MApply0 | ||
|
||
open FStar.Stubs.Reflection.Types | ||
open FStar.Tactics.Effect | ||
|
||
(* Used by mapply, must be exposed, but not to be used directly *) | ||
private val push1 : (#p:Type) -> (#q:Type) -> | ||
squash (p ==> q) -> | ||
squash p -> | ||
squash q | ||
private val push1' : (#p:Type) -> (#q:Type) -> | ||
(p ==> q) -> | ||
squash p -> | ||
squash q | ||
|
||
(* `m` is for `magic` *) | ||
[@@plugin] | ||
val mapply0 (t : term) : Tac unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.