Skip to content

Commit 6508d15

Browse files
committed
Guard exponentially slow bounds analysis with a flag
With `--fancy-and-powerful-but-exponentially-slow-bounds-analysis` Idk how to implement a non-exponential PHOAS passe for this.
1 parent 69f8538 commit 6508d15

16 files changed

+7127
-3466
lines changed

src/AbstractInterpretation/AbstractInterpretation.v

+40-589
Large diffs are not rendered by default.

src/AbstractInterpretation/Bottomify/AbstractInterpretation.v

+594
Large diffs are not rendered by default.

src/AbstractInterpretation/Bottomify/Proofs.v

+1,559
Large diffs are not rendered by default.

src/AbstractInterpretation/Bottomify/Wf.v

+1,188
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Require Import Rewriter.Language.Language.
2+
Require Import Rewriter.Language.Wf.
3+
Require Import Crypto.Language.API.
4+
Require Import Crypto.Language.WfExtra.
5+
Require Import Crypto.AbstractInterpretation.Bottomify.AbstractInterpretation.
6+
Require Import Crypto.AbstractInterpretation.Bottomify.Wf.
7+
8+
Module Compilers.
9+
Import Language.Compilers.
10+
Import Language.Inversion.Compilers.
11+
Import Language.Wf.Compilers.
12+
Import Language.API.Compilers.
13+
Import Language.WfExtra.Compilers.
14+
Import AbstractInterpretation.Bottomify.AbstractInterpretation.Compilers.
15+
Import AbstractInterpretation.Bottomify.Wf.Compilers.
16+
Import Compilers.API.
17+
18+
Import AbstractInterpretation.Bottomify.AbstractInterpretation.Compilers.partial.
19+
Import AbstractInterpretation.Bottomify.Wf.Compilers.partial.
20+
21+
#[global]
22+
Hint Resolve Wf_Eval Wf_EvalWithBound Wf_EtaExpandWithBound Wf_EtaExpandWithListInfoFromBound Wf_StripAnnotations Wf_StripAllAnnotations : wf_extra.
23+
#[global]
24+
Hint Opaque partial.Eval EvalWithBound EtaExpandWithBound EtaExpandWithListInfoFromBound StripAnnotations StripAllAnnotations : wf_extra interp_extra.
25+
26+
#[global]
27+
Hint Resolve Wf_PartialEvaluateWithListInfoFromBounds : wf_extra.
28+
#[global]
29+
Hint Opaque PartialEvaluateWithListInfoFromBounds : wf_extra interp_extra.
30+
31+
#[global]
32+
Hint Resolve Wf_PartialEvaluateWithBounds : wf_extra.
33+
#[global]
34+
Hint Opaque PartialEvaluateWithBounds : wf_extra interp_extra.
35+
End Compilers.

src/AbstractInterpretation/Fancy/AbstractInterpretation.v

+612
Large diffs are not rendered by default.

src/AbstractInterpretation/Fancy/Proofs.v

+1,627
Large diffs are not rendered by default.

src/AbstractInterpretation/Fancy/Wf.v

+1,367
Large diffs are not rendered by default.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Require Import Rewriter.Language.Language.
2+
Require Import Rewriter.Language.Wf.
3+
Require Import Crypto.Language.API.
4+
Require Import Crypto.Language.WfExtra.
5+
Require Import Crypto.AbstractInterpretation.Fancy.AbstractInterpretation.
6+
Require Import Crypto.AbstractInterpretation.Fancy.Wf.
7+
8+
Module Compilers.
9+
Import Language.Compilers.
10+
Import Language.Inversion.Compilers.
11+
Import Language.Wf.Compilers.
12+
Import Language.API.Compilers.
13+
Import Language.WfExtra.Compilers.
14+
Import AbstractInterpretation.Fancy.AbstractInterpretation.Compilers.
15+
Import AbstractInterpretation.Fancy.Wf.Compilers.
16+
Import Compilers.API.
17+
18+
Import AbstractInterpretation.Fancy.AbstractInterpretation.Compilers.partial.
19+
Import AbstractInterpretation.Fancy.Wf.Compilers.partial.
20+
21+
#[global]
22+
Hint Resolve Wf_Eval Wf_EvalWithBound Wf_EtaExpandWithBound Wf_EtaExpandWithListInfoFromBound Wf_StripAnnotations Wf_StripAllAnnotations : wf_extra.
23+
#[global]
24+
Hint Opaque partial.Eval EvalWithBound EtaExpandWithBound EtaExpandWithListInfoFromBound StripAnnotations StripAllAnnotations : wf_extra interp_extra.
25+
26+
#[global]
27+
Hint Resolve Wf_PartialEvaluateWithListInfoFromBounds : wf_extra.
28+
#[global]
29+
Hint Opaque PartialEvaluateWithListInfoFromBounds : wf_extra interp_extra.
30+
31+
#[global]
32+
Hint Resolve Wf_PartialEvaluateWithBounds : wf_extra.
33+
#[global]
34+
Hint Opaque PartialEvaluateWithBounds : wf_extra interp_extra.
35+
End Compilers.

src/AbstractInterpretation/Proofs.v

+25-1,534
Large diffs are not rendered by default.

src/AbstractInterpretation/Wf.v

+8-1,331
Large diffs are not rendered by default.

src/AbstractInterpretation/WfExtra.v

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@ Require Import Crypto.Language.API.
44
Require Import Crypto.Language.WfExtra.
55
Require Import Crypto.AbstractInterpretation.AbstractInterpretation.
66
Require Import Crypto.AbstractInterpretation.Wf.
7+
Require Import Crypto.AbstractInterpretation.Fancy.WfExtra.
8+
Require Import Crypto.AbstractInterpretation.Bottomify.WfExtra.
79

810
Module Compilers.
9-
Import Language.Compilers.
10-
Import Language.Inversion.Compilers.
11-
Import Language.Wf.Compilers.
12-
Import Language.API.Compilers.
13-
Import Language.WfExtra.Compilers.
11+
Export AbstractInterpretation.Fancy.WfExtra.Compilers.
12+
Export AbstractInterpretation.Bottomify.WfExtra.Compilers.
1413
Import AbstractInterpretation.AbstractInterpretation.Compilers.
1514
Import AbstractInterpretation.Wf.Compilers.
1615
Import Compilers.API.
1716

17+
(*
1818
Import AbstractInterpretation.AbstractInterpretation.Compilers.partial.
1919
Import AbstractInterpretation.Wf.Compilers.partial.
20+
*)
2021

22+
(*
2123
#[global]
2224
Hint Resolve Wf_Eval Wf_EvalWithBound Wf_EtaExpandWithBound Wf_EtaExpandWithListInfoFromBound Wf_StripAnnotations Wf_StripAllAnnotations : wf_extra.
2325
#[global]
2426
Hint Opaque partial.Eval EvalWithBound EtaExpandWithBound EtaExpandWithListInfoFromBound StripAnnotations StripAllAnnotations : wf_extra interp_extra.
25-
27+
*)
2628
#[global]
2729
Hint Resolve Wf_PartialEvaluateWithListInfoFromBounds : wf_extra.
2830
#[global]

src/AbstractInterpretation/ZRange.v

+14-2
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,30 @@ Module Compilers.
2020
Class shiftr_avoid_uint1_opt := shiftr_avoid_uint1 : bool.
2121
#[global]
2222
Typeclasses Opaque shiftr_avoid_uint1_opt.
23+
Class fancy_and_powerful_but_exponentially_slow_bounds_analysis_opt := fancy_and_powerful_but_exponentially_slow_bounds_analysis : bool.
24+
#[global]
25+
Typeclasses Opaque fancy_and_powerful_but_exponentially_slow_bounds_analysis_opt.
2326
Module AbstractInterpretation.
2427
Local Set Primitive Projections.
2528
Class Options
2629
:= { shiftr_avoid_uint1 : shiftr_avoid_uint1_opt
30+
; fancy_and_powerful_but_exponentially_slow_bounds_analysis : fancy_and_powerful_but_exponentially_slow_bounds_analysis_opt
2731
}.
2832
Definition default_Options : Options
29-
:= {| shiftr_avoid_uint1 := false |}.
33+
:= {| shiftr_avoid_uint1 := false
34+
; fancy_and_powerful_but_exponentially_slow_bounds_analysis := false
35+
|}.
3036
Module Export Exports.
3137
Global Existing Instance Build_Options.
3238
Global Existing Instance shiftr_avoid_uint1.
33-
Global Hint Cut [ ( _ * ) shiftr_avoid_uint1 ( _ * ) Build_Options ] : typeclass_instances.
39+
Global Existing Instance fancy_and_powerful_but_exponentially_slow_bounds_analysis.
40+
Global Hint Cut [ ( _ * )
41+
( shiftr_avoid_uint1
42+
| fancy_and_powerful_but_exponentially_slow_bounds_analysis
43+
)
44+
( _ * ) Build_Options ] : typeclass_instances.
3445
Global Coercion shiftr_avoid_uint1 : Options >-> shiftr_avoid_uint1_opt.
46+
Global Coercion fancy_and_powerful_but_exponentially_slow_bounds_analysis : Options >-> fancy_and_powerful_but_exponentially_slow_bounds_analysis_opt.
3547
End Exports.
3648
End AbstractInterpretation.
3749
Export AbstractInterpretation.Exports.

src/BoundsPipeline.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ Module Pipeline.
13751375
let e' := fresh "e" in
13761376
destruct v as [e'|e'] eqn:H;
13771377
cbv beta iota in Hrv;
1378-
[ apply CheckedPartialEvaluateWithBounds_Correct_first_order in H;
1378+
[ apply CheckedPartialEvaluateWithBounds_Correct in H;
13791379
[ let Hwf' := fresh "Hwf" in
13801380
rewrite (correct_of_final_iff_correct_of_initial Hinterp) in H by assumption;
13811381
destruct H as [? Hwf']; split_and;

src/CLI.v

+7
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ Module ForExtraction.
417417
:= ([Arg.long_key "cmovznz-by-mul"], Arg.Unit, ["Use an alternative implementation of cmovznz using multiplication rather than bitwise-and with -1."]).
418418
Definition shiftr_avoid_uint1_spec : named_argT
419419
:= ([Arg.long_key "shiftr-avoid-uint1"], Arg.Unit, ["Avoid uint1 types at the output of (>>) operations."]).
420+
Definition fancy_and_powerful_but_exponentially_slow_bounds_analysis_spec : named_argT
421+
:= ([Arg.long_key "fancy-and-powerful-but-exponentially-slow-bounds-analysis"],
422+
Arg.Unit,
423+
["Use a more powerful bound analysis implementation that is unfortunately exponentially slow in the number of lines of code. If you know how to implement PHOAS passes of type [expr var -> var * expr var] or if you want to reimplement our bounds analysis pass in a first-order expression representation instead of PHOAS, please contact us! See https://github.com/mit-plv/fiat-crypto/pull/1761 for more details."]).
420424
Definition tight_bounds_multiplier_default := default_tight_upperbound_fraction.
421425
Definition tight_bounds_multiplier_spec : named_argT
422426
:= ([Arg.long_key "tight-bounds-mul-by"],
@@ -712,6 +716,7 @@ Module ForExtraction.
712716
; relax_primitive_carry_to_bitwidth_spec
713717
; cmovznz_by_mul_spec
714718
; shiftr_avoid_uint1_spec
719+
; fancy_and_powerful_but_exponentially_slow_bounds_analysis_spec
715720
; only_signed_spec
716721
; hint_file_spec
717722
; output_file_spec
@@ -769,6 +774,7 @@ Module ForExtraction.
769774
, relax_primitive_carry_to_bitwidthv
770775
, cmovznz_by_mulv
771776
, shiftr_avoid_uint1v
777+
, fancy_and_powerful_but_exponentially_slow_bounds_analysisv
772778
, only_signedv
773779
, hint_file_namesv
774780
, output_file_namev
@@ -849,6 +855,7 @@ Module ForExtraction.
849855
; use_mul_for_cmovznz := to_bool cmovznz_by_mulv
850856
; abstract_interpretation_options :=
851857
{| AbstractInterpretation.shiftr_avoid_uint1 := to_bool shiftr_avoid_uint1v
858+
; AbstractInterpretation.fancy_and_powerful_but_exponentially_slow_bounds_analysis := to_bool fancy_and_powerful_but_exponentially_slow_bounds_analysisv
852859
|}
853860
; emit_primitives := negb (to_bool no_primitivesv)
854861
; output_options :=

src/SlowPrimeSynthesisExamples.v

+7-3
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,15 @@ Module debugging_21271_from_bytes.
468468
vm_compute in e.
469469
set (k'' := CheckedPartialEvaluateWithBounds _ _ _ _ _ _ _) in (value of k).
470470
cbv [CheckedPartialEvaluateWithBounds] in k''.
471+
cbv [AbstractInterpretation.fancy_and_powerful_but_exponentially_slow_bounds_analysis Pipeline.AbstractInterpretation_opts Primitives.Options.absint_opts Primitives.Options.default_PipelineOptions Pipeline.AbstractInterpretation_opts Pipeline.default_BoundsPipelineOptions AbstractInterpretation.default_Options] in k''.
472+
cbv [Bottomify.AbstractInterpretation.Compilers.CheckedPartialEvaluateWithBounds] in k''.
471473
clear -k''.
472474
cbv [Rewriter.Util.LetIn.Let_In] in k''.
473475
set (e' := (GeneralizeVar.FromFlat (GeneralizeVar.ToFlat e))) in (value of k'').
474476
vm_compute in e'; clear e; rename e' into e.
475-
set (b := (partial.Extract _ _ _)) in (value of k'').
477+
set (b := (Bottomify.AbstractInterpretation.Compilers.partial.Extract _ _ _)) in (value of k'').
476478
clear -b.
477-
cbv [partial.Extract partial.ident.extract partial.extract_gen type.app_curried partial.extract] in b.
479+
cbv [Bottomify.AbstractInterpretation.Compilers.partial.Extract partial.ident.extract partial.extract_gen type.app_curried partial.extract] in b.
478480
subst e.
479481
cbv beta iota zeta in b.
480482
Import Rewriter.Util.LetIn.
@@ -1961,6 +1963,8 @@ Module debugging_p256_uint1.
19611963
=> set (k' := e) in (value of k)
19621964
end; vm_compute in k'; subst k'.
19631965
cbv [CheckedPartialEvaluateWithBounds] in k.
1966+
cbv [AbstractInterpretation.fancy_and_powerful_but_exponentially_slow_bounds_analysis Pipeline.AbstractInterpretation_opts Primitives.Options.absint_opts Primitives.Options.default_PipelineOptions Pipeline.AbstractInterpretation_opts Pipeline.default_BoundsPipelineOptions AbstractInterpretation.default_Options] in k.
1967+
cbv [Bottomify.AbstractInterpretation.Compilers.CheckedPartialEvaluateWithBounds] in k.
19641968
cbv [Rewriter.Util.LetIn.Let_In] in k.
19651969
set (k' := GeneralizeVar.FromFlat (GeneralizeVar.ToFlat _)) in (value of k).
19661970
vm_compute in k'.
@@ -1987,7 +1991,7 @@ Module debugging_p256_uint1.
19871991
cbv [split_multiret_to should_split_multiret should_split_multiret_opt_instance_0] in k.
19881992
vm_compute ZRange.type.base.option.is_tighter_than in k.
19891993
cbv beta iota zeta in k.
1990-
set (k' := PartialEvaluateWithBounds _ _ _ _ _ _) in (value of k) at 1.
1994+
set (k' := Bottomify.AbstractInterpretation.Compilers.PartialEvaluateWithBounds _ _ _ _ _ _) in (value of k) at 1.
19911995
vm_compute in k'.
19921996
Abort.
19931997
End __.

0 commit comments

Comments
 (0)