@@ -341,6 +341,14 @@ pub struct BackendOptions<E: Extension> {
341
341
#[ arg( long) ]
342
342
pub profile : bool ,
343
343
344
+ /// Prune Rust items that are not under the provided top-level module name.
345
+ /// This will effectively remove all items that don't match `*::<prune_haxmetadata>::**`.
346
+ /// This prunning occurs directly on the `haxmeta` file, in the frontend.
347
+ /// This is independent from any engine options.
348
+ #[ arg( long) ]
349
+ #[ clap( hide = true ) ]
350
+ pub prune_haxmeta : Option < String > ,
351
+
344
352
/// Enable engine debugging: dumps the AST at each phase.
345
353
///
346
354
/// The value of `<DEBUG_ENGINE>` can be either:
@@ -423,6 +431,29 @@ pub enum Command<E: Extension> {
423
431
include_extra : bool ,
424
432
} ,
425
433
434
+ /// Serialize to a `haxmeta` file, the internal binary format used by hax to
435
+ /// store the ASTs produced by the hax exporter.
436
+ #[ clap( hide = true ) ]
437
+ Serialize {
438
+ /// Whether the bodies are exported as THIR, built MIR, const
439
+ /// MIR, or a combination. Repeat this option to extract a
440
+ /// combination (e.g. `-k thir -k mir-built`). Pass `--kind`
441
+ /// alone with no value to disable body extraction.
442
+ #[ arg(
443
+ value_enum,
444
+ short,
445
+ long = "kind" ,
446
+ num_args = 0 ..=3 ,
447
+ default_values_t = [ ExportBodyKind :: Thir ]
448
+ ) ]
449
+ kind : Vec < ExportBodyKind > ,
450
+
451
+ /// When extracting to a given backend, the exporter is called with different `cfg` options.
452
+ /// This option allows to set the same flags as `cargo hax into` would pick.
453
+ #[ arg( short) ]
454
+ backend : Option < BackendName > ,
455
+ } ,
456
+
426
457
#[ command( flatten) ]
427
458
CliExtension ( E :: Command ) ,
428
459
}
@@ -431,7 +462,16 @@ impl<E: Extension> Command<E> {
431
462
pub fn body_kinds ( & self ) -> Vec < ExportBodyKind > {
432
463
match self {
433
464
Command :: JSON { kind, .. } => kind. clone ( ) ,
434
- _ => vec ! [ ExportBodyKind :: Thir ] ,
465
+ Command :: Serialize { kind, .. } => kind. clone ( ) ,
466
+ Command :: Backend { .. } | Command :: CliExtension { .. } => vec ! [ ExportBodyKind :: Thir ] ,
467
+ }
468
+ }
469
+ pub fn backend_name ( & self ) -> Option < BackendName > {
470
+ match self {
471
+ Command :: Backend ( backend_options) => Some ( ( & backend_options. backend ) . into ( ) ) ,
472
+ Command :: JSON { .. } => None ,
473
+ Command :: Serialize { backend, .. } => backend. clone ( ) ,
474
+ Command :: CliExtension ( _) => None ,
435
475
}
436
476
}
437
477
}
@@ -475,6 +515,12 @@ pub struct ExtensibleOptions<E: Extension> {
475
515
#[ arg( long = "deps" ) ]
476
516
pub deps : bool ,
477
517
518
+ /// Provide a precomputed haxmeta file explicitly.
519
+ /// Setting this option bypasses rustc and the exporter altogether.
520
+ #[ arg( long) ]
521
+ #[ clap( hide = true ) ]
522
+ pub haxmeta : Option < PathBuf > ,
523
+
478
524
/// By default, hax uses `$CARGO_TARGET_DIR/hax` as target folder,
479
525
/// to avoid recompilation when working both with `cargo hax` and
480
526
/// `cargo build` (or, e.g. `rust-analyzer`). This option disables
@@ -540,7 +586,7 @@ pub struct ExporterOptions {
540
586
}
541
587
542
588
#[ derive_group( Serializers ) ]
543
- #[ derive( JsonSchema , Debug , Clone , Copy ) ]
589
+ #[ derive( JsonSchema , ValueEnum , Debug , Clone , Copy ) ]
544
590
pub enum BackendName {
545
591
Fstar ,
546
592
Coq ,
@@ -570,22 +616,17 @@ impl fmt::Display for BackendName {
570
616
571
617
impl From < & Options > for ExporterOptions {
572
618
fn from ( options : & Options ) -> Self {
573
- let backend = match & options. command {
574
- Command :: Backend ( backend_options) => Some ( ( & backend_options. backend ) . into ( ) ) ,
575
- _ => None ,
576
- } ;
577
- let body_kinds = options. command . body_kinds ( ) ;
578
619
ExporterOptions {
579
620
deps : options. deps ,
580
621
force_cargo_build : options. force_cargo_build . clone ( ) ,
581
- backend,
582
- body_kinds,
622
+ backend : options . command . backend_name ( ) ,
623
+ body_kinds : options . command . body_kinds ( ) ,
583
624
}
584
625
}
585
626
}
586
627
587
- impl From < & Backend < ( ) > > for BackendName {
588
- fn from ( backend : & Backend < ( ) > ) -> Self {
628
+ impl < E : Extension > From < & Backend < E > > for BackendName {
629
+ fn from ( backend : & Backend < E > ) -> Self {
589
630
match backend {
590
631
Backend :: Fstar { .. } => BackendName :: Fstar ,
591
632
Backend :: Coq { .. } => BackendName :: Coq ,
0 commit comments