-
Notifications
You must be signed in to change notification settings - Fork 233
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
Restricting well-foundedness on inductives function-typed fields #2954
Conversation
…ed fields to functions returning an element of one of the mutual inductives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Maybe we can add this test in the same file, as a reminder:
noeq
type ind = | Mk : (int -> ind u#0) -> ind u#aa
which has to (and does) fail due to the variance in universe levels for ind
.
FYI, this breaks one of my former developments: open FStar.List.Pure
open FStar.FunctionalExtensionality
open FStar.Bytes
noeq type comb (n:nat) (ret_type:Type) =
| Comb: send: FStar.Bytes.bytes -> cont:((llist FStar.Bytes.bytes n) -> ret_type){is_restricted (llist FStar.Bytes.bytes n) cont} -> comb n ret_type
#push-options "--ifuel 1"
val fmap_comb_flip: #n:nat -> #b:Type -> #c:Type -> x:comb n b -> f:(y:b{y<<x} -> c) -> comb n c
let fmap_comb_flip #n x f =
let Comb xa fb = x in
let cont vb =
f (fb vb)
in
Comb xa (FStar.FunctionalExtensionality.on _ cont)
#pop-options
val fmap_comb: #n:nat -> #b:Type -> #c:Type -> (b -> c) -> comb n b -> comb n c
let fmap_comb #n f x =
fmap_comb_flip x f
noeq type comba (n:nat) (ret:Type) =
| Abort: comba n ret
| Ret: v:ret -> comba n ret
| Com: v:comb n (comba n ret) -> comba n ret
#push-options "--ifuel 1"
val join_comba: #n:nat -> #ret:Type -> comba n (comba n ret) -> comba n ret
let rec join_comba #n #ret x =
match x with
| Abort -> Abort
| Ret r -> r
| Com y ->
Com (fmap_comb_flip y join_comba)
#pop-options I guess the solution would be to inline |
Thanks for the comment @TWal. Is it possible for you to evaluate the impact? |
erring on the side of caution, inspired by FStarLang/FStar#2954
…al order (#570) * Replace height intrinsic with is_smaller_than, and in the SMT encoding, encode height as a Z3 partial order rather than an int to allow decreases on infinite maps. * Update .github/workflows/get-z3.sh to Z3 4.12.2 * Allow decreases on FnSpec fields * Add is_smaller_than_lexicographic and some comments * Add decreases_to macro * Split is_smaller_than handling into separate function * Restrict usage of decreases through FnSpec and Map, erring on the side of caution, inspired by FStarLang/FStar#2954
…e a deprecation warning when this option is used
@TWal : I added an option --ext 'compat:2954' to not break your code.
With this, your code works, while raising the warning:
|
This is related to #2205
The PR 2205 says: "this fix enhances the SMT encoding of inductives to include an additional property on f x << D f for data constructors D of an inductive t whose argument include a ghost or total function returning a t"
However, the PR was actually introducing this axiom for all ghost or total function-typed fields, not just those returning an element of the (mutual) inductive t.
This allows the following unsoundness (shown below), which @Chris-Hawblitzel found yesterday ... thanks Chris! Effectively, this example replays the older unsoundness described in #2069 using a boxed dependent function (my_fun_dep). This patch blocks this kind of example.
This PR actually restricts the axiom to function-typed fields returning one of the (mutual) inductives. I've added Chris' example to tests/micro-benchmarks/TestWellFoundedRecursion.fst and lemma_my_fun_dep and lemma_my_fun are no longer provable.
Note, this also means that examples like this are no longer provable, since we do not generate any well-foundedness axiom for Test1.f.
But, that this example worked was perhaps just a quirk, since similar examples also were never supported:
where the function in the second component of the pair in SCons' does not get a well-foundedness axiom.
I have an F* and Everest green with this patch.
Looking beyond this PR: The root cause of this class of issues is that F*'s encoding to SMT erases the universe annotations. Retaining universes in the SMT encoding is the right thing to do and I plan to revive the work in nik_smt_univs towards that end.