-
Notifications
You must be signed in to change notification settings - Fork 691
[rfc] Introduce a new ERASEcast kind for evaluation using verified erasure … #20503
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
base: master
Are you sure you want to change the base?
Conversation
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.
I guess the checker would install the identity function as a "reduction"? we could also have a checker version linked with the plugin
| Result.Ok newexp -> pretype (mk_tycon (EConstr.of_constr newexp)) env sigma c, tval | ||
| Result.Error () -> user_err ?loc Pp.(str"Erasure evaluation failed for type" ++ spc () ++ | ||
quote (Termops.Internal.print_constr_env !!env sigma tval))) | ||
| None -> user_err ?loc Pp.(str"Erasure casts do not support evars in the expected type:" ++ |
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 check is incomplete, the env may contain evars too
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.
Yup, and we should check for a closed env as well.
(** The erase evaluation function can either return an evaluated term or an error if the | ||
evaluated term cannot be read back *) | ||
type erase_evaluation_function = | ||
Environ.env -> Constr.t -> types -> (Constr.t, unit) result |
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.
how about allow returning a message (Pp.t) in the error 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.
Indeed that will be done :)
For sure one could install the identity without endangering anything |
I am very excited about this PR both because of the progress on verified extraction and also because it is giving me ideas related to casts in general. I suppose the amount of For example, people could experiment with casts that perform limited reduction (with blacklists of whitelists for specific constants), or even manually traverse If this needs to go in without being delayed by discussions about a more generic mechanism I can move my suggestion into a separate RFC. Footnotes
|
…(to be linked to the kernel)
Just FTR, the nix CI for MetaRocq/rocq-verified-extraction#34 is green, using a slightly patched metarocq that handles ERASEcast. E.g. |
let () = aux (List.rev ctx) 0 in | ||
newargs | ||
|
||
let erase_eval env expected_type = |
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.
I don't see the point in having this function here instead of in the plugin. Why not call the cast eg CustomCast and directly install custom_conv : conv_pb -> types kernel_conversion_function
?
Before, to produce a proof of False, a plugin had to corrupt memory somehow. Now, it can just invoke Since you write that you would be able to make a standalone plugin that would embed the generated malfunction code, why not go a step further? Just push this generated code directly to this repository, so that it gets statically linked to Rocq. Sure, having some generated code in a repository is frowned upon, but there is some prior art, e.g., OCaml's |
not true, there are much easier ways to prove False from plugins |
I agree this is very unsafe in the current presentation. We could explicitly taint definitions requiring a
That's possible indeed, I don't know what @ppedrot and @SkySkimmer would say about this. That's basically adding a dependency on |
I think we want some agreed upon customCast interface anyway before we merge this, unless we directly integrate it as @silene proposes. Anyway, +1 for a separate RFC on that interface. |
…(to be linked to the kernel through the rocq-verified-extraction plugin)
For Rocq proper, this just adds a new parsing rule for
c <<<: t
which binds to a new cast kind.kernel/eraseconv.ml
is then in charge of transmitting the values to evaluate to a plugin whichprovides a
Environ.env -> Constr.t -> (Constr.t, unit) result
. This is what thePR MetaRocq/rocq-verified-extraction#34 provides.
The interface might seem a bit convoluted but the typing rule is the following, informally:
When typechecking
c <<<: t
, we infer the typec : cty
and call eraseconv withcty
andt
.t
has to be an inductive type applied to parameters and indices. We evaluate all the indices usingerasure evaluation and then call back regular conversion betwee
cty
and the newt
. If this succeeds,it is dimmed type correct. Outside this fragment, it is a type error. For pretyping, we can hence allow
cty
to still contain metavariables and fall back to regular evarconv for the finalcty ~= t'
test, henceone does not need to know the value computed by erased evaluation beforehand, it can just be used to fill
an evar.
We could work on making this plugin more standalone. Right now it needs all of MetaRocq + Malfunction/VerifiedExtraction to produce the .cmxs but we could also make a standalone plugin based on the generated (verified) .mlf file and wrapper ML files.
Without an installed erasure function,
x <<<: t
is an error.make doc_gram_rsts
.