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

doc(book): architecture of hax #1120

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

doc(book): architecture of hax #1120

wants to merge 6 commits into from

Conversation

W95Psp
Copy link
Collaborator

@W95Psp W95Psp commented Nov 18, 2024

This PR adds a page to the book, documenting the high-level architecture of hax.

Fixes #752

Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

Thanks. Generally looks good with a couple nits.

Hax is a software pipeline designed to transform Rust code into various formal verification backends such as **F\***, **Coq**, **ProVerif**, and **EasyCrypt**. It comprises two main components:

1. **The Frontend** (written in Rust)
2. **The Engine** (written in OCaml)
Copy link
Member

Choose a reason for hiding this comment

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

So far there has always been a distinction between the engine and the backends. Do you intend to drop that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think we should drop that.
For me, the engine contains the backends.

Copy link
Member

Choose a reason for hiding this comment

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

This is a bigger change than just this document. We are using three parts everywhere so far, including your blog post. And I'm not sure I agree with dropping it. There should be a distinction between transformations and printing. Not doing that just mushes everything into one big module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mmh, I see what you mean, but in terms of software architecture, the engine does contain the backends. So, in this architecture document, I think we should not see backends as an artifact outside of the engine. Maybe I can detail that the engine is composed of a library (the phases, the AST), n backends, and a binary that wraps everything together?
I could also add a small diagram for the whole architecture. That'd make things very clear.
WDYT?

book/src/contributing/architecture.md Outdated Show resolved Hide resolved

This library mirrors the internal types of the Rust compiler (`rustc`) that constitute the **HIR** (High-Level Intermediate Representation), **THIR** (Typed High-Level Intermediate Representation), and **MIR** (Mid-Level Intermediate Representation) ASTs. It extends them with additional information such as attributes, trait implementations, and removes IDs indirections.

**`SInto` Trait:** The library defines an entry point for translating a given `rustc` value to its mirrored hax version using the `SInto` trait (stateful `into`). For a value `x` of type `T` from `rustc`, if `T` is mirrored by hax, then `x.sinto(s)` produces an augmented and simplified "hax-ified" AST for `x`. Here, `s` represents the state holding information about the translation process.
Copy link
Member

Choose a reason for hiding this comment

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

The title says Trait but then you say library. I'm not sure I understand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The SInto is the entrypoint for the library hax-frontend-exporter. How can I word that better?


## The Frontend (Rust)

The frontend is responsible for extracting and exporting Rust code's abstract syntax trees (ASTs) in a format suitable for processing by the engine (or by other tools).
Copy link
Member

Choose a reason for hiding this comment

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

You start describing pieces below without putting them into relation. The section up here should tell what's coming and how they are related. The same goes for the top level section.

It should also contain what's public things and what are internal things.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a paragraph just before "The Frontend"

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I don't see a new paragraph here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, messed up with the history, I re-commited, that's commit afff4b3 now


**Workflow:**

1. **Custom Build Execution:** Runs `cargo build`, instructing Cargo to use `hax-driver` instead of `rustc`.
Copy link
Member

Choose a reason for hiding this comment

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

This kind of description is great but we should make sure that it doesn't go out of date when changes are done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, but I don't see how we could enforce that here (since it's a structural description)

Copy link
Member

Choose a reason for hiding this comment

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

This is a process question. I'll add this to the new processes we are implementing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. So nothing to do in this PR, right? Let's resolve if we agree on this being "future work" (outside of this PR)

book/src/contributing/architecture.md Outdated Show resolved Hide resolved
book/src/contributing/architecture.md Outdated Show resolved Hide resolved
1. **Input:** Takes a list of items from an AST with specific feature constraints.
2. **Output:** Transforms these items into a new AST type, potentially enabling or disabling features through type-level changes.

The phases can be found in the `engin/lib/phases/` folder.
Copy link
Member

Choose a reason for hiding this comment

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

Link

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be good now

book/src/contributing/architecture.md Outdated Show resolved Hide resolved
Copy link
Member

@franziskuskiefer franziskuskiefer left a comment

Choose a reason for hiding this comment

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

Why are there code changes in here now?

Hax is a software pipeline designed to transform Rust code into various formal verification backends such as **F\***, **Coq**, **ProVerif**, and **EasyCrypt**. It comprises two main components:

1. **The Frontend** (written in Rust)
2. **The Engine** (written in OCaml)
Copy link
Member

Choose a reason for hiding this comment

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

This is a bigger change than just this document. We are using three parts everywhere so far, including your blog post. And I'm not sure I agree with dropping it. There should be a distinction between transformations and printing. Not doing that just mushes everything into one big module.


## The Frontend (Rust)

The frontend is responsible for extracting and exporting Rust code's abstract syntax trees (ASTs) in a format suitable for processing by the engine (or by other tools).
Copy link
Member

Choose a reason for hiding this comment

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

Hm, I don't see a new paragraph here.


**Workflow:**

1. **Custom Build Execution:** Runs `cargo build`, instructing Cargo to use `hax-driver` instead of `rustc`.
Copy link
Member

Choose a reason for hiding this comment

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

This is a process question. I'll add this to the new processes we are implementing.

@W95Psp
Copy link
Collaborator Author

W95Psp commented Nov 28, 2024

Huh, sorry, while doing something else I messed with this branch (I think I rebased that branch with a local main behind origin)... that thing is fixed now

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.

Book: document the architecture of hax
2 participants