Skip to content
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

Reducing the amount of Tm_names in checked files #2845

Merged
merged 16 commits into from
Mar 29, 2023
Merged

Reducing the amount of Tm_names in checked files #2845

merged 16 commits into from
Mar 29, 2023

Conversation

mtzguido
Copy link
Member

@mtzguido mtzguido commented Mar 8, 2023

Following up on that gensym bug, this:

  • Introduces a visitor module for terms+sigelts. Just of the 'map' variety for now.
  • Reimplements deep_compress with it.
  • Adds a warning, only with --debug, when a Tm_name is being output into a checked file. I am hoping to remove all cases of this soon and make it into an error.
  • Tweaks the logic of the typechecker to call deep_compress after checking a module, instead of being called on each sigelt (indirectly, by elim_uvars). This is mostly due to the fact that it would have been hard to modify elim_uvars to properly detect escaping Tm_names. However we could still be more eager and compress each sigelt as we check them...
  • I also added a deep_compress pass on checked file loading time, to prevent loading any leaked name, but I'm not sure it makes sense
  • Change the representations of antiquotations to avoid Tm_names. We previously generated a fresh name for each antiquotation and kept a map into the actual antiquoted terms. This changes that into using indices and a list of terms. There is some shifting magic involved, which is explained in a note in FStar.Syntax.Syntax.

let tc_modul (env0:env) (m:modul) (iface_exists:bool) :(modul * env) =
let msg = "Internals for " ^ string_of_lid m.name in
//AR: push env, this will also push solver, and then finish_partial_modul will do the pop
let env0 = push_context env0 msg in
let modul, env = tc_partial_modul env0 m in
// Compress all sigelts so we write a good checked file, plus we make
// sure that we are not leaking uvars, names, etc.
let modul = deep_compress_modul modul in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this compression can happen after type checking each sigelt, so that even when we add them to the typechecking environment, we know they are sane.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, let me try that.

@@ -3305,7 +3304,7 @@ let rec elim_uvars (env:Env.env) (s:sigelt) =
| Sig_let((b, lbs), lids) ->
let lbs = lbs |> List.map (fun lb ->
let opening, lbunivs = Subst.univ_var_opening lb.lbunivs in
let elim t = Subst.deep_compress false (Subst.close_univ_vars lbunivs (remove_uvar_solutions env (Subst.subst opening t))) in
let elim t = Subst.close_univ_vars lbunivs (remove_uvar_solutions env (Subst.subst opening t)) in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deep_compress calls are not needed because remove_uvar already removes all the uvars?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but also, I would like to make deep_compress fail if it find a Tm_name as we are not supposed to write those to checked files. In the line removed above, the binders have been opened so that is not true, and we would could not raise an error then. Here the same applies for universe names.

@@ -180,10 +180,69 @@ and letbinding = { //let f : forall u1..un. M t = e
lbattrs:list attribute; //attrs
lbpos :range; //original position of 'e'
}
and antiquotations = list (bv * term)
and antiquotations = int * list term
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need a checked file version increment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks! Doing it now.


open FStar.Syntax.Syntax

val visit_term : (term -> term) -> term -> term
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some docs/comments here would be useful, especially if there are some parts of the syntax that are not covered here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

finish_partial_modul false iface_exists env modul

let load_checked_module (en:env) (m:modul) :env =
(* Another compression pass to make sure we are not loading a corrupt
module. *)
let m = deep_compress_modul m in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should it be guarded under a debug flag?

@aseemr
Copy link
Collaborator

aseemr commented Mar 28, 2023

Thanks @mtzguido, I added some minor comments, but looks good to me.

@mtzguido mtzguido merged commit 3cb6386 into master Mar 29, 2023
@mtzguido mtzguido deleted the guido_misc branch March 29, 2023 16:43
@mtzguido
Copy link
Member Author

The id_info_table should not be affected by this change (Nik mentioned to look at it today).

I've left the additional load-time check of the checked files for now.. I don't think it's a noticeable performance hit (just measured and it's pretty much 0ms every time), but we could revisit that whenever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants