-
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
Extraction hooks to support custom extraction by extensions #3058
Conversation
…a mutable debug flag
…of coercions & polymorphism
…es like `Pulse.stt a p q` as if it were `Dv a`
…rivation, with corresponding proofs of typing
…t look at the top-most extension blob
| MLTY_Top -> "MLTY_Top" | ||
| MLTY_Erased -> "MLTY_Erased" | ||
|
||
let rec mlexpr_to_string (e:mlexpr) = |
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 are just some printers, useful for debugging extraction
@@ -153,50 +154,57 @@ let effect_as_etag = | |||
where PC.result_type is an arity | |||
|
|||
*) | |||
let rec is_arity env t = | |||
let rec is_arity_aux tcenv t = |
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.
Just a slight refactoring, since this function only needs tcenv
@@ -227,34 +235,52 @@ let rec is_type_aux env t = | |||
let t= U.ctx_uvar_typ u in | |||
is_arity env (SS.subst' s t) | |||
|
|||
| Tm_bvar ({sort=t}) | |||
| Tm_name ({sort=t}) -> | |||
| Tm_bvar ({sort=t}) -> |
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 is a fix to prevent the compiler from relying on the bv.sort field in Tm_name.
Instead, we now look it up in the environment and are careful to push binders in the environment they are traversed
else ( | ||
if has_extract_as_impure_effect g fv | ||
then let (a, _)::_ = args in | ||
translate_term_to_mlty g a |
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.
Just extract the first argument (the result type) in case fv has the "extract_as_impure_effect" attribute
let etag = effect_as_etag env (U.comp_effect_name c) in | ||
let etag = | ||
if etag = E_IMPURE then etag | ||
else if head_of_type_is_extract_as_impure_effect env codom |
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.
Interpret fv's with extract_as_impure_effect as E_IMPURE
@@ -620,6 +621,7 @@ type sig_metadata = { | |||
sigmeta_fact_db_ids:list string; | |||
sigmeta_admit:bool; //An internal flag to record that a sigelt's SMT proof should be admitted | |||
//Used in DM4Free | |||
sigmeta_extension_data: list (string & dyn) //each extension can register some data with a sig |
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.
In the extraction case, this would be a singleton list, right? Is there any other usage where this would be non-singleton?
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.
So far, yes, this is singleton when used in extraction. But, I could imagine that different phases could stash different information in here, e.g, some extension data is added after tosyntax, some after typechecking, etc. Also, could one conceivably have multiple extensions process a single sigelt ... maybe?
@@ -45,6 +45,7 @@ module FStar.Ghost | |||
|
|||
(** [erased t] is the computationally irrelevant counterpart of [t] *) | |||
[@@ erasable] | |||
new |
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.
Can you please comment on this change, just curious what was the trigger.
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.
Not sure why this is still in this PR. I already pushed it separately to master:
08d80b8
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.
the issue is that let test (x:erased int) (y:int) = x == y
would succeed phase 1 and fail in phase 2. Marking erased
as new (which it is) ensures that it also fails phase 1.
then arrows of the form `a -> stt b p q` will be extracted | ||
similarly to `a -> Dv b`. | ||
*) | ||
val extract_as_impure_effect : unit |
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 wonder if we should check this attribute, e.g., when typechecking a let definition, if it has the attribute, then allow only arrows whose codomain is impure effect?
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.
Claiming that something is PURE is risky and would require checking. But, claiming that it is IMPURE is conservative, no?
Thanks Nik, I have minor comments, we can discuss on the PR, but merging it since it is all green. |
This PR adds features in support of custom F* -> ML extraction by extension.
Tm_lazy { blob; lkind=Lazy_extension s}
, for some choice ofs
).The returned blob from the extension is stored in a new field
sigmeta_extension_data
associating the extension name with the blob that it returned.FStar.Extaction.ML.Modul exposes an extension hook:
When extracting a top-level let binding, if the Sig_letbinding contains a sigmeta_extension_data, we see if we can find an extension_extractor registered for that extension data and if so, call it with the blob stored in the extension data.
extract_as_impure_effect
in pervasives, which is interpreted in FStar.Extraction.ML.Term when extracting types.These features are used currently by steel/pulse to extract Pulse terms to F*'s ML AST, from where the rest of the extraction pipeline picks up to emit programs as either OCaml, or to C via krml (also relying there on pre-existing hooks to customize krml extraction)