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

Book: document the architecture of hax #752

Open
W95Psp opened this issue Jul 8, 2024 · 6 comments · May be fixed by #1120
Open

Book: document the architecture of hax #752

W95Psp opened this issue Jul 8, 2024 · 6 comments · May be fixed by #1120
Labels
documentation Improvements or additions to documentation

Comments

@W95Psp
Copy link
Collaborator

W95Psp commented Jul 8, 2024

We changed hax to use 'haxmeta' files recently, we need to document that.
Ideally, we should have both a diagram that explains the interactions between the different Rust crates and the engine, with some explanations.

@W95Psp W95Psp added the documentation Improvements or additions to documentation label Jul 8, 2024
@W95Psp W95Psp changed the title Book: explain the architecture Book: document the architecture of hax Jul 8, 2024
Copy link

github-actions bot commented Sep 7, 2024

This issue has been marked as stale due to a lack of activity for 60 days. If you believe this issue is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

@github-actions github-actions bot added the stale label Sep 7, 2024
Copy link

This issue has been closed due to a lack of activity since being marked as stale. If you believe this issue is still relevant, please reopen it with an update or comment.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2024
@github-project-automation github-project-automation bot moved this to Done in hax Sep 14, 2024
@W95Psp
Copy link
Collaborator Author

W95Psp commented Sep 16, 2024

Still relevant.

@W95Psp W95Psp reopened this Sep 16, 2024
@W95Psp W95Psp removed the stale label Sep 16, 2024
Copy link

This issue has been marked as stale due to a lack of activity for 60 days. If you believe this issue is still relevant, please provide an update or comment to keep it open. Otherwise, it will be closed in 7 days.

@github-actions github-actions bot added the stale label Nov 16, 2024
@W95Psp
Copy link
Collaborator Author

W95Psp commented Nov 18, 2024

Still relevant

@W95Psp W95Psp removed the stale label Nov 18, 2024
@W95Psp
Copy link
Collaborator Author

W95Psp commented Nov 18, 2024

Draft:

Hax is a pipeline that transforms Rust code into various backends (F*, Coq, ProVerif, EasyCrypt...). It consists of the following components:

The Frontend (written in Rust)

The hax-frontend-exporter Library

Mirrors the internal types of the Rust compiler (rustc) that constitutes the HIR, THIR and MIR ASTs, extending them with extra informations (i.e. attributes, where to find implementations for traits, removing indirecitons via IDs, etc.).

That library defines a entrypoint for translating a given rustc value to its mirrored hax version: SInto.
SInto is a trait that stands for "stateful into".
Given x a value of type T comming from rustc, if the type is mirrored by hax, then x.sinto(s) will produce an augmented and simplified "hax-ified" AST for x. Note that s is a state that holds information about how to translate x.

The hax-driver Binary

This binary is a custom rustc driver: it behaves like the rustc binary, but hooks into the compiler to do something a bit different.

Instead of compiling Rust, this custom driver:

  1. Lists the items of a crate
  2. Calls sinto on each items
  3. Output the mirrored items in a haxmeta file in the target directory

The cargo-hax Binary

The cargo-hax binary provides a "hax" subcommand for cargo, that you can call with cargo hax –-help.

This binary defines a command line interface for hax, both the frontend (the deriver) and the engine (will be defined later on).

It essentially:

  1. run cargo build but asking cargo to use hax-driver in place of rustc
  2. cargo-build runs hax-driver several times with various options
  3. hax-driver communicates with cargo-hax on stderr via JSON lines
  4. this produces some haxmeta files
  5. if the user asked for that, runs the engine, putting options and haxmeta informations on stdin, serialized as JSON
  6. communicates interactively with the engine
  7. report to the user

The Engine (written in OCaml)

The engine consumes a JSON in stdin that contains the ASTs of
items to be processed, and options.

It first imports "hax-ified" Rust THIR AST and converts it into a simplified and opinionated internal AST.

This internal AST is a functor that takes a list of type-level
booleans we call features, and output the types of the AST.

Features are for instance mutation, loops, unsafe, etc. On
various nodes of the AST, there are witnesses of those features:
e.g. on the loop constructor for expressions, we have a
witness of type F.loop, with F the current feature set.
Morally, F.loop is either set to an empty type or to unit.
When F.loop is an empty type, we cannot construct a loop
expression, but we can prove to OCaml that an expression in this
AST cannot (by type) be a loop.

The engine then runs a sequence of phases. This sequence is
decided on a per-backend basis. Each phase takes a list of items
that belongs to an AST whose features are possibly constrained,
and converts to items of a different AST type, possibly turning
on or off various features, by type.

After applying the phases, the engine calls the printer of the
backend, that produces a map from file names to contents. Then,
the engine prints this file map, along with various informations
such as errors, as JSON, to stderr.

The engine also communicates asyncrhonously with the frontend
using a simple protocol (defined in
hax_types::engine_api::protocol) to send diagnostic data,
profiling data, ask for pretty printing of Rust sources or
diagnostics, etc.

@W95Psp W95Psp linked a pull request Nov 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant