Skip to content

Commit 3e63928

Browse files
authored
Merge branch 'main' into main
2 parents a1dc976 + d1e0d3c commit 3e63928

File tree

29 files changed

+828
-47
lines changed

29 files changed

+828
-47
lines changed

.github/workflows/clippy_rust_engine.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
- uses: actions/checkout@v4
1616
- name: Run clippy
1717
run: |
18-
cargo clippy -p rust-printer -- --no-deps
18+
cargo clippy -p hax-rust-engine -- --no-deps

Cargo.lock

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ members = [
1414
"engine/names",
1515
"engine/names/extract",
1616
"hax-types",
17-
"rust-printer",
18-
"rust-printer/macros",
17+
"rust-engine",
18+
"rust-engine/macros",
1919
]
20-
exclude = ["tests", "rustc-coverage-tests", "rust-printer/tests"]
20+
exclude = ["tests", "rustc-coverage-tests", "rust-engine/tests"]
2121
default-members = [
2222
"frontend/exporter",
2323
"frontend/exporter/options",
@@ -81,6 +81,7 @@ hax-lib-macros-types = { path = "hax-lib/macros/types", version = "=0.3.1" }
8181
hax-lib = { path = "hax-lib", version = "=0.3.1" }
8282
hax-engine-names = { path = "engine/names", version = "=0.3.1" }
8383
hax-types = { path = "hax-types", version = "=0.3.1" }
84+
hax-rust-engine = { path = "rust-engine" }
8485

8586
[workspace.metadata.release]
8687
owners = ["github:cryspen:tools"]

cli/subcommands/Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,21 @@ extension-traits = "1.0.1"
4848
serde.workspace = true
4949
serde_json.workspace = true
5050
hax-types.workspace = true
51+
hax-rust-engine.workspace = true
5152
schemars.workspace = true
5253
hax-frontend-exporter.workspace = true
53-
hax-lib-macros-types = {workspace = true, features = ["schemars"]}
54+
hax-lib-macros-types = { workspace = true, features = ["schemars"] }
5455
version_check = "0.9"
5556
toml = "0.8"
5657

5758
[package.metadata.release]
58-
pre-release-hook = ["dune", "build", "--root", "../../engine", "hax-engine.opam"]
59+
pre-release-hook = [
60+
"dune",
61+
"build",
62+
"--root",
63+
"../../engine",
64+
"hax-engine.opam",
65+
]
5966

6067
[[package.metadata.release.pre-release-replacements]]
6168
file = "../../engine/dune-project"

cli/subcommands/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn json_schema_static_asset() {
2424
hax_types::engine_api::protocol::FromEngine,
2525
hax_types::engine_api::protocol::ToEngine,
2626
hax_lib_macros_types::AttrPayload,
27+
hax_rust_engine::ast::Item,
2728
));
2829
schema.schema.metadata.get_or_insert_default().id = Some(hax_types::HAX_VERSION.into());
2930
serde_json::to_writer(

docs/frontend/evaluation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ These tests aim at increasing the confidence in the ability of hax frontend to h
149149

150150
### Rust printer testing
151151

152-
This method aims at testing the quality of hax frontend's output. It uses a tool that is under development that we call the Rust printer.
152+
This method aims at testing the quality of hax frontend's output. It uses the Rust hax engine.
153153

154154
This tool (written in Rust) takes the output of hax frontend (a json file describing the content of a Rust crate), it imports it as an AST (similar to the hax engine AST), and then prints this AST in Rust syntax.
155155

156156
If the Rust code we get out of this tool is equivalent to the Rust code it was given as input, then this means hax frontend correctly extracted the input code without losing or altering any information.
157157

158158
There is no easy way of testing the full input/output equivalence so the methodology here is to test that the resulting code behaves the same as the input code with respect to relevant test cases.
159159

160-
This work is available in the `rust-printer` folder. In the `tests` subfolder, an input file is available with tests for all Rust constructs supported by the printer (currently functions and expressions). For now these tests pass after extracting and printing the file with hax frontend and the Rust printer. This means that for the Rust constructs covered by the printer and the test file, hax frontend's extraction is correct. However this still needs to be extended to test more Rust constructs.
160+
This work is available in the `hax-rust-engine` folder. In the `tests` subfolder, an input file is available with tests for all Rust constructs supported by the printer (currently functions and expressions). For now these tests pass after extracting and printing the file with hax frontend and the Rust printer. This means that for the Rust constructs covered by the printer and the test file, hax frontend's extraction is correct. However this still needs to be extended to test more Rust constructs.

engine/lib/concrete_ident/concrete_ident.ml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ module Fresh_module : sig
2727

2828
val to_mod_path : t -> View.ModPath.t
2929
(** Compute a module path for a fresh module. *)
30+
31+
val to_rust_ast : t -> Rust_engine_types.fresh_module
32+
val from_rust_ast : Rust_engine_types.fresh_module -> t
3033
end = struct
3134
open View
3235

@@ -111,6 +114,21 @@ end = struct
111114
|> snd |> Option.value_exn
112115

113116
let get_path_hints { hints; _ } = hints
117+
118+
let to_rust_ast ({ id; hints; label } : t) : Rust_engine_types.fresh_module =
119+
{
120+
id = Int.to_string id;
121+
hints = List.map ~f:Explicit_def_id.to_rust_ast hints;
122+
label;
123+
}
124+
125+
let from_rust_ast ({ id; hints; label } : Rust_engine_types.fresh_module) : t
126+
=
127+
{
128+
id = Int.of_string id;
129+
hints = List.map ~f:Explicit_def_id.from_rust_ast hints;
130+
label;
131+
}
114132
end
115133

116134
type reserved_suffix = [ `Cast | `Pre | `Post ]
@@ -743,3 +761,27 @@ let matches_namespace (ns : Types.namespace) (did : t) : bool =
743761
| _ -> false
744762
in
745763
aux ns.chunks path
764+
765+
let to_rust_ast ({ def_id; moved; suffix } : t) : Rust_engine_types.concrete_id
766+
=
767+
let moved = Option.map ~f:Fresh_module.to_rust_ast moved in
768+
let suffix =
769+
Option.map
770+
~f:(fun s ->
771+
match s with
772+
| `Cast -> Rust_engine_types.Cast
773+
| `Pre -> Rust_engine_types.Pre
774+
| `Post -> Rust_engine_types.Post)
775+
suffix
776+
in
777+
{ def_id = Explicit_def_id.to_rust_ast def_id; moved; suffix }
778+
779+
let from_rust_ast ({ def_id; moved; suffix } : Rust_engine_types.concrete_id) :
780+
t =
781+
let moved = Option.map ~f:Fresh_module.from_rust_ast moved in
782+
let suffix =
783+
Option.map
784+
~f:(fun s -> match s with Cast -> `Cast | Pre -> `Pre | Post -> `Post)
785+
suffix
786+
in
787+
{ def_id = Explicit_def_id.from_rust_ast def_id; moved; suffix }

engine/lib/concrete_ident/concrete_ident.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ module ImplInfoStore : sig
104104
end
105105

106106
val matches_namespace : Types.namespace -> t -> bool
107+
val to_rust_ast : t -> Rust_engine_types.concrete_id
108+
val from_rust_ast : Rust_engine_types.concrete_id -> t

engine/lib/concrete_ident/explicit_def_id.ml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,46 @@ module ImplInfoStore = struct
125125
let lookup_raw (impl_def_id : t) : Types.impl_infos option =
126126
find (to_def_id impl_def_id)
127127
end
128+
129+
module ToRustAST = struct
130+
module A = Types
131+
module B = Rust_engine_types
132+
133+
let rec def_id_contents_to_rust_ast
134+
({ krate; path; parent; kind; _ } : A.def_id_contents) : B.def_id =
135+
let f (o : A.def_id) = def_id_contents_to_rust_ast o.contents.value in
136+
let parent = Option.map ~f parent in
137+
{ krate; path; parent; kind }
138+
139+
let to_rust_ast ({ is_constructor; def_id } : t) : B.explicit_def_id =
140+
{ is_constructor; def_id = def_id_contents_to_rust_ast def_id }
141+
end
142+
143+
module FromRustAST = struct
144+
module A = Rust_engine_types
145+
module B = Types
146+
147+
let rec def_id_contents_to_rust_ast
148+
({ krate; path; parent; kind; _ } : A.def_id) : B.def_id_contents =
149+
let f (o : A.def_id) : B.def_id =
150+
let contents : B.node_for__def_id_contents =
151+
{ value = def_id_contents_to_rust_ast o; id = Int64.of_int (-1) }
152+
in
153+
{ contents }
154+
in
155+
let parent = Option.map ~f parent in
156+
{
157+
krate;
158+
path;
159+
parent;
160+
kind;
161+
index = (Int64.of_int (-1), Int64.of_int (-1), None);
162+
is_local = false;
163+
}
164+
165+
let to_rust_ast ({ is_constructor; def_id } : A.explicit_def_id) : t =
166+
{ is_constructor; def_id = def_id_contents_to_rust_ast def_id }
167+
end
168+
169+
let to_rust_ast = ToRustAST.to_rust_ast
170+
let from_rust_ast = FromRustAST.to_rust_ast

engine/lib/concrete_ident/explicit_def_id.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ module ImplInfoStore : sig
8181
engine, this function may return [None] even though the supplied
8282
identifier points to an [Impl] block. *)
8383
end
84+
85+
val to_rust_ast : t -> Rust_engine_types.explicit_def_id
86+
val from_rust_ast : Rust_engine_types.explicit_def_id -> t

0 commit comments

Comments
 (0)