@@ -140,7 +140,12 @@ let run (options : Types.engine_options) : Types.output =
140
140
| Fstar opts -> run (module Fstar_backend ) opts
141
141
| Coq -> run (module Coq_backend ) ()
142
142
| Ssprove -> run (module Ssprove_backend ) ()
143
- | Easycrypt -> run (module Easycrypt_backend ) () )
143
+ | Easycrypt -> run (module Easycrypt_backend ) ()
144
+ | Lean ->
145
+ failwith
146
+ " The OCaml hax engine should never be called for lean. The Lean \
147
+ backend uses the newer rust engine. Please report this issue on \
148
+ our GitHub repository: https://github.com/cryspen/hax." )
144
149
in
145
150
{
146
151
diagnostics = List. map ~f: Diagnostics. to_thir_diagnostic diagnostics;
@@ -181,34 +186,39 @@ let parse_id_table_node (json : Yojson.Safe.t) :
181
186
in
182
187
(table, value)
183
188
184
- let parse_options () =
189
+ let load_table ?( check_version = true ) : Yojson.Safe.t =
185
190
let table, json =
186
191
Hax_io. read_json () |> Option. value_exn |> parse_id_table_node
187
192
in
188
- let version =
189
- try Yojson.Safe.Util. (member " hax_version" json |> to_string)
190
- with _ -> " unknown"
191
- in
192
- if String. equal version Types. hax_version |> not then (
193
- prerr_endline
194
- [% string
195
- {|
193
+ (if check_version then
194
+ let version =
195
+ try Yojson.Safe.Util. (member " hax_version" json |> to_string)
196
+ with _ -> " unknown"
197
+ in
198
+ if String. equal version Types. hax_version |> not then (
199
+ prerr_endline
200
+ [% string
201
+ {|
196
202
The versions of `hax - engine` and of `cargo -hax ` are different :
197
203
- `hax -engine ` version : %{Types. hax_version}
198
204
- `cargo -hax ` version : %{version}
199
205
200
206
Please reinstall hax .
201
207
|}];
202
- Stdlib. exit 1 );
208
+ Stdlib. exit 1 ) );
203
209
table
204
210
|> List. iter ~f :(fun (id , json ) ->
205
211
Hashtbl. add_exn Types. cache_map ~key :id ~data :(`JSON json ));
212
+ json
213
+
214
+ let parse_options () =
215
+ let json = load_table ~check_version :true in
206
216
let options = [%of_yojson : Types. engine_options ] json in
207
217
Profiling. enabled := options .backend .profile ;
208
218
options
209
219
210
220
(* * Entrypoint of the engine. Assumes `Hax_io.init` was called. *)
211
- let main () =
221
+ let engine () =
212
222
let options = Profiling. profile (Other "parse_options" ) 1 parse_options in
213
223
Printexc. record_backtrace true ;
214
224
let result =
@@ -240,3 +250,41 @@ let main () =
240
250
| Error (exn , bt ) ->
241
251
Logs. info (fun m -> m "Exiting Hax engine (with an unexpected failure)" );
242
252
Printexc. raise_with_backtrace exn bt
253
+
254
+ module ExportRustAst = Export_ast. Make (Features. Rust)
255
+ module ExportFStarAst = Export_ast. Make (Fstar_backend. InputLanguage)
256
+
257
+ (* * Entry point for interacting with the Rust hax engine *)
258
+ let driver_for_rust_engine () : unit =
259
+ let query : Rust_engine_types. query =
260
+ (* TODO: support for table * )
261
+ (* let json = load_table ~check_version:false in *)
262
+ let json = Hax_io. read_json () |> Option. value_exn in
263
+ [%of_yojson : Rust_engine_types. query ] json
264
+ in
265
+ Concrete_ident.ImplInfoStore. init
266
+ (Concrete_ident_generated. impl_infos @ query .impl_infos );
267
+ match query .kind with
268
+ | Types. ImportThir { input } ->
269
+ let imported_items = import_thir_items [] input in
270
+ let imported_items =
271
+ (* TODO: this let binding is applying the phases from the F* backend * )
272
+ Fstar_backend. apply_phases
273
+ {
274
+ cli_extension = EmptyStructempty_args_extension ;
275
+ fuel = Int64. zero ;
276
+ ifuel = Int64. zero ;
277
+ interfaces = [] ;
278
+ line_width = 80 ;
279
+ z3rlimit = Int64. zero ;
280
+ }
281
+ imported_items
282
+ in
283
+ let rust_ast_items =
284
+ List. concat_map
285
+ ~f :(fun item -> ExportFStarAst. ditem item )
286
+ imported_items
287
+ in
288
+ let response = Rust_engine_types. ImportThir { output = rust_ast_items } in
289
+ Hax_io. write_json ([%yojson_of : Rust_engine_types.response] response );
290
+ Hax_io. write_json ([%yojson_of : Types.from_engine] Exit )
0 commit comments