Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1a171e7
[lean backend] Basic pretty printing setup UNTESTED
clementblaudeau Jun 23, 2025
34f8000
[lean backend] Empty pretty printing traits boilerplate UNTESTED
clementblaudeau Jun 23, 2025
dd87793
[lean backend] IntKind UNTESTED
clementblaudeau Jun 23, 2025
742ab5d
[lean backend] Basic support for functions and identifiers (barrett)
clementblaudeau Jun 23, 2025
ff3f268
[lean backend] Remove spurious parens
clementblaudeau Jun 25, 2025
15bf14c
[lean backend] Added missing cases in raw printing of identifiers
clementblaudeau Jun 25, 2025
58d2692
[lean backend] Make the printing borrow the AST instead of consuming
clementblaudeau Jun 25, 2025
b041c5d
[lean backend] Cosmetic changes
clementblaudeau Jun 26, 2025
01f473b
[lean backend] Basic support for arrays
clementblaudeau Jun 26, 2025
692a31d
[lean backend] Improve alignment of output
clementblaudeau Jun 26, 2025
9f322c9
[lean backend] Use Crate name for file name (no modules yet)
clementblaudeau Jun 27, 2025
8763bdf
[lean backend] Add some unit tests + fix printing of single-line fn
clementblaudeau Jun 30, 2025
f059715
[lean backend] Add support for type aliases as abbreviations
clementblaudeau Jun 30, 2025
1b39969
[lean backend] Add printing of type parameters
clementblaudeau Jun 30, 2025
398c238
[lean backend] Add Lean export to Barrett + pre-review cleanup
clementblaudeau Jun 30, 2025
ef2f1c2
[lean backend] Replace todo! by printing a todo doc
clementblaudeau Jun 30, 2025
714e43b
[lean backend] Removed useless flat_alt layouts
clementblaudeau Jun 30, 2025
c5aadab
[lean backend] Add a POC library for Lean backend (in Barrett)
clementblaudeau Jun 30, 2025
8a0d3f9
[lean backend] Update test snapshot + disable profiling by default
clementblaudeau Jul 1, 2025
86ec8a1
fix(test-harness&ci): compile rust engine, add it to PATH
W95Psp Jul 1, 2025
d5e44d3
[lean backend] Address review comments
clementblaudeau Jul 2, 2025
beee4b9
[lean backend] Make the extraction import the prelude by default
clementblaudeau Jul 2, 2025
bcc0d4c
[lean backend] Update snapshot
clementblaudeau Jul 2, 2025
d91278e
Merge branch 'main' into lean-printer
franziskuskiefer Jul 2, 2025
9b57ab3
[lean backend] Rename functions to not use the get_ prefix
clementblaudeau Jul 2, 2025
41fe41a
[lean backend] Add HasKind for Ty instead of having a pub field
clementblaudeau Jul 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cli/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let
is-webapp-static-asset = path:
builtins.match ".*(script[.]js|index[.]html)" path != null;
buildInputs = lib.optionals stdenv.isDarwin [ libiconv libz.dev ];
binaries = [ hax hax-engine.bin rustc gcc ] ++ buildInputs;
binaries = [ hax hax-engine.bin rustc gcc hax_rust_engine ] ++ buildInputs;
commonArgs = {
version = "0.0.1";
src = lib.cleanSourceWith {
Expand Down Expand Up @@ -40,6 +40,12 @@ let
inherit cargoArtifacts pname;
doInstallCargoArtifacts = true;
});
hax_rust_engine = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
buildInputs = buildInputs ++ [ makeWrapper ];
pname = "hax-rust-engine";
cargoExtraArgs = "--manifest-path rust-engine/Cargo.toml --locked";
});
docs = craneLib.cargoDoc (commonArgs // {
# preBuildPhases = [ "addRustcDocs" ];
cargoDocExtraArgs = "--document-private-items";
Expand Down
2 changes: 1 addition & 1 deletion cli/subcommands/src/cargo_hax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const RUST_ENGINE_BINARY_NOT_FOUND: &str =
fn find_rust_hax_engine(message_format: MessageFormat) -> process::Command {
use which::which;

std::env::var("HAX_RUST_BINARY")
std::env::var("HAX_RUST_ENGINE_BINARY")
.ok()
.map(process::Command::new)
.or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion engine/lib/profiling.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Prelude

(** Is profiling enabled? *)
let enabled = ref true
let enabled = ref false

(** Profiles the function `f`, that operates in a given context over a given quantity of things it is processing. *)
let profile (type b) (context : Diagnostics.Context.t) (quantity : int)
Expand Down
8 changes: 4 additions & 4 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions examples/barrett/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.PHONY: default clean
default:
.PHONY: default lean clean
default: lean
make -C proofs/fstar/extraction

lean:
cargo hax into lean

clean:
rm -f proofs/fstar/extraction/.depend
rm -f proofs/fstar/extraction/*.fst
83 changes: 83 additions & 0 deletions examples/barrett/proofs/lean/extraction/Lib.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
abbrev u8 := Nat
abbrev u16 := Nat
abbrev u32 := Nat
abbrev u64 := Nat
abbrev usize := Nat
abbrev i8 := Nat
abbrev i16 := Nat
abbrev i32 := Nat
abbrev i64 := Nat
abbrev isize := Nat

-- Arithmetic
def hax_machine_int_add (x y: Nat) := x + y
def hax_machine_int_mul (x y: Nat) := x * y
def hax_machine_int_bitxor (x y: Nat) : Nat := sorry

def hax_machine_int_eq (x y: Nat) : Bool := x = y
def hax_machine_int_ne (x y: Nat) : Bool := x != y
def hax_machine_int_ge (x y: Nat) : Bool := x >= y
def hax_machine_int_gt (x y: Nat) : Bool := x > y
def hax_machine_int_le (x y: Nat) : Bool := x <= y
def hax_machine_int_lt (x y: Nat) : Bool := x < y


-- Nums
def num_impl_wrapping_add : Nat -> Nat -> Nat := sorry
def num_impl_from_le_bytes {α} : (Array α) -> u32 := sorry

-- Results
inductive result_Result α β
| ok : α -> result_Result α β
| err : β -> result_Result α β

axiom array_TryFromSliceError : Type

-- Assert
def assert : Bool -> Unit := fun _ => ()
def assume : Prop -> Unit := fun _ => ()
def prop_constructors_from_bool : Bool -> Prop := sorry

-- Hax
def hax_folds_fold_range
(s: Nat)
(e: Nat) :
((Array u32) -> Nat -> Bool) ->
(Array u32) ->
((Array u32) -> Nat -> (Array u32)) ->
(Array u32) := sorry

def hax_monomorphized_update_at_update_at_usize :
(Array u32) ->
Nat ->
u32 ->
(Array u32) := sorry

abbrev hax__autogenerated_refinement__BoundedUsize_BoundedUsize (_: Nat) (_: Nat) := Nat

def result_impl_unwrap {α} : α -> Array β := sorry

-- Vectors
def hax_repeat (x:Nat) (y:Nat) : Array u32 := sorry

-- Ranges

structure ops_range_Range_arg (α: Type) where
ops_range_Range_start : α
ops_range_Range_end : α

inductive ops_range_Range (α: Type) where
| constr_ops_range_Range : ops_range_Range_arg α -> ops_range_Range α


-- Arrays
def ops_index_Index_index (a: Array u8) : α -> β := sorry
def convert_TryInto_try_into {α} : Array α ->
result_Result (Array α) array_TryFromSliceError := sorry


-- Slices
def slice_impl_len (a: Array u32) : Nat := sorry

-- Bytes
def num_impl_to_le_bytes : u32 -> Array u8 := sorry
10 changes: 10 additions & 0 deletions examples/barrett/proofs/lean/extraction/lakefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "barrett"
version = "0.1.0"
defaultTargets = ["barrett"]

[[lean_lib]]
name = "Lib"

[[lean_exe]]
name = "barrett"
root = "barrett"
2 changes: 1 addition & 1 deletion rust-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ serde_json = { workspace = true, features = ["unbounded_depth"] }
schemars.workspace = true
serde-jsonlines = "0.5.0"
serde_stacker = "0.1.12"
pretty = "0.12.4"
pretty = "0.12"
12 changes: 11 additions & 1 deletion rust-engine/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ pub enum AttributeKind {
Tool {
/// The path to the tool
path: String,
/// The payload
/// The payload
tokens: String,
},
/// A doc comment
Expand Down Expand Up @@ -1540,5 +1540,15 @@ pub mod traits {
}
}
}

/// Manual implementation of HasKind as the Ty struct contains a Box<TyKind>
/// instead of a TyKind directly.
impl HasKind for Ty {
type Kind = TyKind;

fn kind(&self) -> &Self::Kind {
&(*self.0)
}
}
}
pub use traits::*;
33 changes: 33 additions & 0 deletions rust-engine/src/ast/identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,39 @@ mod global_id {
/// A projector.
Projector(ConcreteId),
}

impl GlobalId {
/// Extracts the Crate info
pub fn krate(&self) -> String {
match self {
GlobalId::Concrete(concrete_id) | GlobalId::Projector(concrete_id) => {
concrete_id.def_id.def_id.krate.clone()
}
}
}

/// Raw printing of identifier separated by underscore. Used for testing
pub fn to_debug_string(&self) -> String {
match self {
GlobalId::Concrete(concrete_id) => concrete_id
.def_id
.def_id
.clone()
.path
.into_iter()
.map(|def| match def.clone().data {
hax_frontend_exporter::DefPathItem::ValueNs(s)
| hax_frontend_exporter::DefPathItem::MacroNs(s)
| hax_frontend_exporter::DefPathItem::TypeNs(s) => s.clone(),
hax_frontend_exporter::DefPathItem::Impl => "impl".to_string(),
other => unimplemented!("{other:?}"),
})
.collect::<Vec<String>>()
.join("_"),
GlobalId::Projector(concrete_id) => todo!(),
}
}
}
}

/// Local identifier
Expand Down
Loading
Loading