Skip to content

Commit 9799e24

Browse files
authored
Merge pull request #1509 from cryspen/lean-printer
Lean backend [Part 1/3]
2 parents 835876b + 41fe41a commit 9799e24

File tree

20 files changed

+819
-16
lines changed

20 files changed

+819
-16
lines changed

cli/default.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let
55
is-webapp-static-asset = path:
66
builtins.match ".*(script[.]js|index[.]html)" path != null;
77
buildInputs = lib.optionals stdenv.isDarwin [ libiconv libz.dev ];
8-
binaries = [ hax hax-engine.bin rustc gcc ] ++ buildInputs;
8+
binaries = [ hax hax-engine.bin rustc gcc hax_rust_engine ] ++ buildInputs;
99
commonArgs = {
1010
version = "0.0.1";
1111
src = lib.cleanSourceWith {
@@ -40,6 +40,12 @@ let
4040
inherit cargoArtifacts pname;
4141
doInstallCargoArtifacts = true;
4242
});
43+
hax_rust_engine = craneLib.buildPackage (commonArgs // {
44+
inherit cargoArtifacts;
45+
buildInputs = buildInputs ++ [ makeWrapper ];
46+
pname = "hax-rust-engine";
47+
cargoExtraArgs = "--manifest-path rust-engine/Cargo.toml --locked";
48+
});
4349
docs = craneLib.cargoDoc (commonArgs // {
4450
# preBuildPhases = [ "addRustcDocs" ];
4551
cargoDocExtraArgs = "--document-private-items";

cli/subcommands/src/cargo_hax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const RUST_ENGINE_BINARY_NOT_FOUND: &str =
133133
fn find_rust_hax_engine(message_format: MessageFormat) -> process::Command {
134134
use which::which;
135135

136-
std::env::var("HAX_RUST_BINARY")
136+
std::env::var("HAX_RUST_ENGINE_BINARY")
137137
.ok()
138138
.map(process::Command::new)
139139
.or_else(|| {

engine/lib/profiling.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Prelude
22

33
(** Is profiling enabled? *)
4-
let enabled = ref true
4+
let enabled = ref false
55

66
(** Profiles the function `f`, that operates in a given context over a given quantity of things it is processing. *)
77
let profile (type b) (context : Diagnostics.Context.t) (quantity : int)

examples/Cargo.lock

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

examples/barrett/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
.PHONY: default clean
2-
default:
1+
.PHONY: default lean clean
2+
default: lean
33
make -C proofs/fstar/extraction
44

5+
lean:
6+
cargo hax into lean
7+
58
clean:
69
rm -f proofs/fstar/extraction/.depend
710
rm -f proofs/fstar/extraction/*.fst
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
abbrev u8 := Nat
2+
abbrev u16 := Nat
3+
abbrev u32 := Nat
4+
abbrev u64 := Nat
5+
abbrev usize := Nat
6+
abbrev i8 := Nat
7+
abbrev i16 := Nat
8+
abbrev i32 := Nat
9+
abbrev i64 := Nat
10+
abbrev isize := Nat
11+
12+
-- Arithmetic
13+
def hax_machine_int_add (x y: Nat) := x + y
14+
def hax_machine_int_mul (x y: Nat) := x * y
15+
def hax_machine_int_bitxor (x y: Nat) : Nat := sorry
16+
17+
def hax_machine_int_eq (x y: Nat) : Bool := x = y
18+
def hax_machine_int_ne (x y: Nat) : Bool := x != y
19+
def hax_machine_int_ge (x y: Nat) : Bool := x >= y
20+
def hax_machine_int_gt (x y: Nat) : Bool := x > y
21+
def hax_machine_int_le (x y: Nat) : Bool := x <= y
22+
def hax_machine_int_lt (x y: Nat) : Bool := x < y
23+
24+
25+
-- Nums
26+
def num_impl_wrapping_add : Nat -> Nat -> Nat := sorry
27+
def num_impl_from_le_bytes {α} : (Array α) -> u32 := sorry
28+
29+
-- Results
30+
inductive result_Result α β
31+
| ok : α -> result_Result α β
32+
| err : β -> result_Result α β
33+
34+
axiom array_TryFromSliceError : Type
35+
36+
-- Assert
37+
def assert : Bool -> Unit := fun _ => ()
38+
def assume : Prop -> Unit := fun _ => ()
39+
def prop_constructors_from_bool : Bool -> Prop := sorry
40+
41+
-- Hax
42+
def hax_folds_fold_range
43+
(s: Nat)
44+
(e: Nat) :
45+
((Array u32) -> Nat -> Bool) ->
46+
(Array u32) ->
47+
((Array u32) -> Nat -> (Array u32)) ->
48+
(Array u32) := sorry
49+
50+
def hax_monomorphized_update_at_update_at_usize :
51+
(Array u32) ->
52+
Nat ->
53+
u32 ->
54+
(Array u32) := sorry
55+
56+
abbrev hax__autogenerated_refinement__BoundedUsize_BoundedUsize (_: Nat) (_: Nat) := Nat
57+
58+
def result_impl_unwrap {α} : α -> Array β := sorry
59+
60+
-- Vectors
61+
def hax_repeat (x:Nat) (y:Nat) : Array u32 := sorry
62+
63+
-- Ranges
64+
65+
structure ops_range_Range_arg (α: Type) where
66+
ops_range_Range_start : α
67+
ops_range_Range_end : α
68+
69+
inductive ops_range_Range (α: Type) where
70+
| constr_ops_range_Range : ops_range_Range_arg α -> ops_range_Range α
71+
72+
73+
-- Arrays
74+
def ops_index_Index_index (a: Array u8) : α -> β := sorry
75+
def convert_TryInto_try_into {α} : Array α ->
76+
result_Result (Array α) array_TryFromSliceError := sorry
77+
78+
79+
-- Slices
80+
def slice_impl_len (a: Array u32) : Nat := sorry
81+
82+
-- Bytes
83+
def num_impl_to_le_bytes : u32 -> Array u8 := sorry
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "barrett"
2+
version = "0.1.0"
3+
defaultTargets = ["barrett"]
4+
5+
[[lean_lib]]
6+
name = "Lib"
7+
8+
[[lean_exe]]
9+
name = "barrett"
10+
root = "barrett"

rust-engine/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ serde_json = { workspace = true, features = ["unbounded_depth"] }
1717
schemars.workspace = true
1818
serde-jsonlines = "0.5.0"
1919
serde_stacker = "0.1.12"
20-
pretty = "0.12.4"
20+
pretty = "0.12"

rust-engine/src/ast.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ pub enum AttributeKind {
11561156
Tool {
11571157
/// The path to the tool
11581158
path: String,
1159-
/// The payload
1159+
/// The payload
11601160
tokens: String,
11611161
},
11621162
/// A doc comment
@@ -1540,5 +1540,15 @@ pub mod traits {
15401540
}
15411541
}
15421542
}
1543+
1544+
/// Manual implementation of HasKind as the Ty struct contains a Box<TyKind>
1545+
/// instead of a TyKind directly.
1546+
impl HasKind for Ty {
1547+
type Kind = TyKind;
1548+
1549+
fn kind(&self) -> &Self::Kind {
1550+
&(*self.0)
1551+
}
1552+
}
15431553
}
15441554
pub use traits::*;

rust-engine/src/ast/identifiers.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,39 @@ mod global_id {
9090
/// A projector.
9191
Projector(ConcreteId),
9292
}
93+
94+
impl GlobalId {
95+
/// Extracts the Crate info
96+
pub fn krate(&self) -> String {
97+
match self {
98+
GlobalId::Concrete(concrete_id) | GlobalId::Projector(concrete_id) => {
99+
concrete_id.def_id.def_id.krate.clone()
100+
}
101+
}
102+
}
103+
104+
/// Raw printing of identifier separated by underscore. Used for testing
105+
pub fn to_debug_string(&self) -> String {
106+
match self {
107+
GlobalId::Concrete(concrete_id) => concrete_id
108+
.def_id
109+
.def_id
110+
.clone()
111+
.path
112+
.into_iter()
113+
.map(|def| match def.clone().data {
114+
hax_frontend_exporter::DefPathItem::ValueNs(s)
115+
| hax_frontend_exporter::DefPathItem::MacroNs(s)
116+
| hax_frontend_exporter::DefPathItem::TypeNs(s) => s.clone(),
117+
hax_frontend_exporter::DefPathItem::Impl => "impl".to_string(),
118+
other => unimplemented!("{other:?}"),
119+
})
120+
.collect::<Vec<String>>()
121+
.join("_"),
122+
GlobalId::Projector(concrete_id) => todo!(),
123+
}
124+
}
125+
}
93126
}
94127

95128
/// Local identifier

0 commit comments

Comments
 (0)