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

Easier prototyping of code #748

Open
tanyongkiam opened this issue Sep 7, 2020 · 7 comments
Open

Easier prototyping of code #748

tanyongkiam opened this issue Sep 7, 2020 · 7 comments
Labels
dev experience Makes tasks developing cakeml itself easier high effort low effort May still assume familiarity user experience Time needed to perform tasks not related to compiler development

Comments

@tanyongkiam
Copy link
Contributor

This issue is about speeding up prototyping of code that is (to be) verified using the translator and/or CF.

Currently, the process I used is roughly:

  1. write HOL definitions (to be translated)
  2. write CakeML code (to be verified by CF)
  3. do the standard boilerplate to extract a full program
  4. compile in the logic

Now, to optimize the resulting code, one does:

  1. Go back to Step 1 and/or 2, make changes, repeat.

Overall, this process is rather tedious because one has to wait for compilation in the logic for each prototype.

One way to speed this process is to use the binary compiler. However, this requires concrete syntax.

It would be nice to provide a facility/library so that Step 1-3 above can easily be made to dump the full program in concrete syntax using e.g.: astPP (https://github.com/CakeML/cakeml/blob/master/semantics/astPP.sml)

@tanyongkiam
Copy link
Contributor Author

Suggestion from @myreen for improving robustness of astPP:

  1. Given a CakeML program foo in HOL, call the sexpr generator on foo to get foo_sexpr_1
  2. Call astPP on foo to get foo_concrete
  3. Call the binary CakeML compiler on foo_concrete to get foo_sexpr_2
  4. Diff foo_sexpr_1 and foo_sexpr_2 and fail if they differ

@myreen
Copy link
Contributor

myreen commented Sep 7, 2020

I think this is a great idea!

I just want to add that I suspect one needs replace Step 4 with:

  1. Call the binary CakeML compiler on foo_sexpr_1 to get foo_sexpr_3
  2. Diff foo_sexpr_3 and foo_sexpr_2 and fail if they differ

because the sexpr generator from HOL might format its output slightly differently.

@mn200
Copy link
Contributor

mn200 commented Sep 7, 2020

How slow do you reckon an AST-to-sexp function in HOL would take to EVAL such things? If it was OK, you could then also think about attempting to verify that the parser and printer inverted each other.

@myreen
Copy link
Contributor

myreen commented Sep 10, 2020

@mn200 I'm confused by this:

you could then also think about attempting to verify that the parser and printer inverted each other.

I was under the impression that the sexp parser has been proved to invert the sexp printer. I suspect the relevant lines are:

Theorem decsexp_sexpdec:
∀s d. sexpdec s = SOME d ⇒ decsexp d = s
Proof

However, I think all of this is a bit beside the point. The point is that we want to quickly extract a first version of a program from HOL. The target of this extraction should be concrete syntax (normal SML syntax) that can easily be tweaked outside of HOL. Currently, the means to get this concrete syntax is through astPP, and we know that astPP a bit untested and, as a result, the focus of this issues it drifting towards improving astPP. One way to find bugs in it is make testing of its output part of the regression test.

@mn200
Copy link
Contributor

mn200 commented Sep 11, 2020

Well, then if those sexps can be consumed by the compiler, why not iterate over @tanyongkiam's process above going via sexps to get the ability to test the code. It sounded to me as if all the code-writing was being done with HOL functions and process_topdecs type things, not wanting to also edit concrete syntax outside of HOL.

@tanyongkiam
Copy link
Contributor Author

That makes sense! I guess the proposal is more if we'd want to prototype outside of HOL/process_topdecs by modifying concrete syntax right away.

@sorear
Copy link
Contributor

sorear commented Sep 19, 2020

A pretty-printed concrete syntax step for easy hack modifications? I like that. I did some similar surgery on the sexpr compiler to get the numbers in #774 but getting the sexpr into a state where I could edit it was not trivial.

@sorear sorear added dev experience Makes tasks developing cakeml itself easier high effort low effort May still assume familiarity user experience Time needed to perform tasks not related to compiler development labels Sep 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev experience Makes tasks developing cakeml itself easier high effort low effort May still assume familiarity user experience Time needed to perform tasks not related to compiler development
Projects
None yet
Development

No branches or pull requests

4 participants