-
Notifications
You must be signed in to change notification settings - Fork 237
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
Injectivity of inductive types revisited #3253
Merged
Merged
Changes from 10 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
ead4864
restrict injectivity of inductives based on a simpler but more restri…
nikswamy 2c50dcd
a refinement of the injectivity constraint
nikswamy 92f768a
retain equations on indices even if parameters are in a universe too …
nikswamy ac07d58
snap
nikswamy fb34777
restrict the universe of type-function parameters when enabling injec…
nikswamy 773cdc3
snap
nikswamy df6fb0d
need to explicitly destruct Refl
nikswamy 13cb2d3
another explicit Refl destruction
nikswamy 3a4b518
snap
nikswamy 007ff20
Merge remote-tracking branch 'origin/master' into nik_restrict_inject…
nikswamy 2c6b4db
Merge branch 'master' into nik_restrict_injectivity
nikswamy 1057ff2
Merge branch 'master' into nik_restrict_injectivity
nikswamy 87e5d17
trying to simplify the handling of Tm_name
nikswamy bbdff51
merge master in
nikswamy 84d1251
simplify a counterexample; add it to the test suite
nikswamy ce14d27
merge
nikswamy 5c011d5
current check is not strict enough; can still break it using injectiv…
nikswamy 35380d3
refactoring encoding of inductive type and datacon to prepare for a r…
nikswamy 448857d
restrict injectivity for data constructor type parameters
nikswamy ab79318
a temporary compat in FStar.ModifiesGen
nikswamy e376ccc
for data constructors on types not injective on their params, add an …
nikswamy db285db
remove compat options in ModifiesGen
nikswamy 2aec69e
Merge remote-tracking branch 'origin/master' into nik_restrict_inject…
nikswamy 9d39962
revise the statement of inversion of data constructor typing to not r…
nikswamy 0d6bb6a
Merge remote-tracking branch 'origin/master' into nik_restrict_inject…
nikswamy ec1ed9d
remove projector function altogether if it is not injective
nikswamy d1508c8
try, never injective on params
nikswamy 8ac4ae5
disable compat:injectivity
nikswamy ae4521b
Merge remote-tracking branch 'origin/master' into nik_restrict_inject…
nikswamy 0ac8a71
remove duplicated guards
nikswamy ba8cb90
revert disabling compat options
nikswamy 95499af
Merge remote-tracking branch 'origin/master' into nik_restrict_inject…
nikswamy f97222b
revert disabling injectivity globally
nikswamy c117073
undo ulib changes
nikswamy 2a31bd0
reverting Bug3186; cleaning up BugBoxInjectivity
nikswamy 07b70f7
update a comment
nikswamy 89b83ab
Don't generate spurious declarations that rely on a projector of a ty…
nikswamy 34089dd
snap
nikswamy 8715862
Merge remote-tracking branch 'origin/master' into nik_restrict_inject…
nikswamy 46b6855
Merge branch 'nik_restrict_injectivity_wip' into nik_restrict_injecti…
nikswamy ab0ee5f
merging master in
nikswamy 630aadd
try revise pretyping axiom
nikswamy 600963d
temporary admits
nikswamy 68ad9ab
weaken pretype axiom for non-injective types
nikswamy 9979879
Revert "temporary admits"
nikswamy 9885844
refactor to provide an environment to eq_tm and NBETerm.eq_t
nikswamy a3ca82c
revise equality of data constructors to return unknown if the type pa…
nikswamy 03d1b17
adding an injective_type_params field to Sig_inductive and Sig_datacon
nikswamy 42bba1e
compute injective_type_params flag in phase2 only
nikswamy e023a9c
merging master in
nikswamy bcbff7c
snap
nikswamy d950b26
tweak a test; we seemt to run out of stack a bit sooner on unembeddin…
nikswamy 35f89bf
Merge remote-tracking branch 'origin/master' into nik_restrict_inject…
nikswamy 18b55b2
rlimit bump & retry on Lib.Vec.Lemmas
nikswamy ed0e430
snap
nikswamy 596cc5c
another test
nikswamy 0d8be16
Merge remote-tracking branch 'origin/master' into nik_restrict_inject…
nikswamy b85bee9
eq_tm and eq_t disregard non-injective type parameters in equality te…
nikswamy 3b730a9
merge master
nikswamy 3849844
Fix test
mtzguido File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1228,8 +1228,9 @@ and encode_sigelt' (env:env_t) (se:sigelt) : (decls_t * env_t) = | |
params=tps; | ||
t=k; | ||
ds=datas} -> | ||
let t_lid = t in | ||
let tcenv = env.tcenv in | ||
let is_injective = | ||
let is_injective_on_params = | ||
let usubst, uvs = SS.univ_var_opening universe_names in | ||
let env, tps, k = | ||
Env.push_univ_vars tcenv uvs, | ||
|
@@ -1267,22 +1268,48 @@ and encode_sigelt' (env:env_t) (se:sigelt) : (decls_t * env_t) = | |
| _ -> false | ||
in | ||
let u_leq_u_k u = | ||
universe_leq (N.normalize_universe env_tps u) u_k | ||
let u = N.normalize_universe env_tps u in | ||
universe_leq u u_k | ||
in | ||
let tp_ok (tp:S.binder) (u_tp:universe) = | ||
let t_tp = tp.binder_bv.sort in | ||
if u_leq_u_k u_tp | ||
then true | ||
else let formals, _ = U.arrow_formals t_tp in | ||
let _, _, _, u_formals = TcTerm.tc_binders env_tps formals in | ||
//List.iter (fun u -> BU.print1 "Universe of formal: %s\n" (Print.univ_to_string u)) u_formals; | ||
BU.for_all (fun u_formal -> u_leq_u_k u_formal) u_formals | ||
else ( | ||
let t_tp = | ||
N.normalize | ||
[Unrefine; Unascribe; Unmeta; | ||
Primops; HNF; UnfoldUntil delta_constant; Beta] | ||
env_tps t_tp | ||
in | ||
let formals, t = U.arrow_formals t_tp in | ||
let _, _, _, u_formals = TcTerm.tc_binders env_tps formals in | ||
let inj = BU.for_all (fun u_formal -> u_leq_u_k u_formal) u_formals in | ||
if inj | ||
then ( | ||
match (SS.compress t).n with | ||
| Tm_type u -> | ||
(* retain injectivity for parameters that are type functions | ||
from small universes (i.e., all formals are smaller than the constructed type) | ||
to a universe <= the universe of the constructed type. | ||
See BugBoxInjectivity.fst *) | ||
u_leq_u_k u | ||
| Tm_name _ -> (* this is a value of another type parameter in scope *) | ||
true | ||
| _ -> | ||
false | ||
) | ||
else ( | ||
false | ||
) | ||
|
||
) | ||
in | ||
List.forall2 tp_ok tps us | ||
in | ||
if Env.debug env.tcenv <| Options.Other "SMTEncoding" | ||
then BU.print2 "%s injectivity for %s\n" | ||
(if is_injective then "YES" else "NO") | ||
(if is_injective_on_params then "YES" else "NO") | ||
(Ident.string_of_lid t); | ||
let quals = se.sigquals in | ||
let is_logical = quals |> BU.for_some (function Logic | Assumption -> true | _ -> false) in | ||
|
@@ -1306,9 +1333,17 @@ and encode_sigelt' (env:env_t) (se:sigelt) : (decls_t * env_t) = | |
if List.length indices <> List.length vars | ||
then failwith "Impossible"; | ||
let eqs = | ||
if is_injective | ||
if is_injective_on_params | ||
|| Options.ext_getv "compat:injectivity" <> "" | ||
then List.map2 (fun v a -> mkEq(mkFreeV v, a)) vars indices | ||
else [] in | ||
else ( | ||
//only injectivity on indices | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, we always get injectivity on indices |
||
let num_params = List.length tps in | ||
let _var_params, var_indices = List.splitAt num_params vars in | ||
let _i_params, indices = List.splitAt num_params indices in | ||
List.map2 (fun v a -> mkEq(mkFreeV v, a)) var_indices indices | ||
) | ||
in | ||
mkOr(out, mkAnd(mk_data_tester env l xx, eqs |> mk_and_l)), decls@decls') (mkFalse, []) in | ||
let ffsym, ff = fresh_fvar env.current_module_name "f" Fuel_sort in | ||
let fuel_guarded_inversion = | ||
|
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,72 @@ | ||
module BugBoxInjectivity | ||
// #restart-solver | ||
// #push-options "--log_queries --query_stats --debug BugBoxInjectivity --debug_level SMTEncoding" | ||
module CC = FStar.Cardinality.Universes | ||
noeq | ||
type test (a:Type u#0 -> Type u#1) : Type u#1 = | ||
| Mk : test a | ||
|
||
let const (f:Type u#1) : Type u#0 -> Type u#1 = fun _ -> f | ||
let itest (f:Type u#1) : Type u#1 = test (const f) | ||
let itest_inhabited (f:Type u#1) : itest f = Mk | ||
let const_inversion (f0 f1:Type u#1) | ||
: Lemma | ||
(requires const f0 == const f1) | ||
(ensures f0 == f1) | ||
= let _f0 = const f0 int in | ||
let _f1 = const f1 int in | ||
assert (_f0 == _f1); | ||
() | ||
let itest_injective (f0 f1:Type u#1) | ||
: Lemma | ||
(ensures itest f0 == itest f1 ==> const f0 == const f1) | ||
= let x : test (const f0) = itest_inhabited f0 in | ||
let Mk #_ = x in | ||
() | ||
open FStar.Functions | ||
let itest_injective' : squash (is_inj itest) = | ||
introduce forall f0 f1. | ||
itest f0 == itest f1 ==> f0 == f1 | ||
with introduce _ ==> _ | ||
with _ . ( | ||
itest_injective f0 f1; | ||
const_inversion f0 f1 | ||
) | ||
[@@expect_failure [189]] //itest is not in the right universe to use this lemma | ||
let fals : squash False = | ||
CC.no_inj_universes itest | ||
|
||
|
||
#push-options "--ext 'compat:injectivity'" | ||
noeq | ||
type test2 (a:Type u#0 -> Type u#2) : Type u#1 = | ||
| Mk2 : test2 a | ||
#pop-options | ||
let const2 (f:Type u#2) : Type u#0 -> Type u#2 = fun _ -> f | ||
let itest2 (f:Type u#2) : Type u#1 = test2 (const2 f) | ||
let itest2_inhabited (f:Type u#2) : itest2 f = Mk2 | ||
let const2_inversion (f0 f1:Type u#2) | ||
: Lemma | ||
(requires const2 f0 == const2 f1) | ||
(ensures f0 == f1) | ||
= let _f0 = const2 f0 (FStar.Universe.raise_t int) in | ||
let _f1 = const2 f1 (FStar.Universe.raise_t int) in | ||
assert (_f0 == _f1); | ||
() | ||
let itest2_injective (f0 f1:Type u#2) | ||
: Lemma | ||
(ensures itest2 f0 == itest2 f1 ==> const2 f0 == const2 f1) | ||
= let x : test2 (const2 f0) = itest2_inhabited f0 in | ||
let Mk2 #_ = x in | ||
() | ||
open FStar.Functions | ||
let itest2_injective' : squash (is_inj itest2) = | ||
introduce forall f0 f1. | ||
itest2 f0 == itest2 f1 ==> f0 == f1 | ||
with introduce _ ==> _ | ||
with _ . ( | ||
itest2_injective f0 f1; | ||
const2_inversion f0 f1 | ||
) | ||
let fals () : squash False = | ||
CC.no_inj_universes itest2 |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This name is another (opened) type parameter? If that type parameter itself is a type in a higher universe, that's ok? As in, returning true here is ok in that case?
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.
Sorry, wrong branch.