Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Changes to the Lean backend:
- Add generation of specs from requires/ensures-annotations (#1815)
- Add support for nonliteral array sizes (#1826)
- Add `hax_lib::lean::proof` attribute (#1831)
- Add support for `#[hax_lib::opaque]` (#1846)

Miscellaneous:
- Reserve extraction folder for auto-generated files in Lean examples (#1754)
Expand Down
2 changes: 1 addition & 1 deletion hax-lib/proof-libs/lean/Hax/Lib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ inductive RustM.{u} (α : Type u) where
| ok (v: α): RustM α
| fail (e: Error): RustM α
| div
deriving Repr, BEq, DecidableEq
deriving Repr, BEq, DecidableEq, Inhabited

namespace RustM

Expand Down
12 changes: 12 additions & 0 deletions rust-engine/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,18 @@ pub struct Item {
pub meta: Metadata,
}

impl Item {
/// Checks whether the item was marked opaque using `hax_lib::opaque`
pub fn is_opaque(&self) -> bool {
self.meta.attributes.iter().any(|a| {
matches!(
a.kind,
AttributeKind::Hax(hax_lib_macros_types::AttrPayload::Erased)
)
})
}
}

/// A "flat" module: this contains only non-module items.
#[derive_group_for_ast]
pub struct Module {
Expand Down
8 changes: 4 additions & 4 deletions rust-engine/src/backends/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,20 +1161,20 @@ set_option linter.unusedVariables false
params,
safety: _,
} => {
let opaque = item.is_opaque();
docs![
docs![
docs![
docs!["def", line!(), name].group(),
docs![if opaque { "opaque" } else { "def" }, line!(), name].group(),
line!(),
generics,
params,
docs![": RustM", line!(), &body.ty].group(),
line!(),
":= do"
if opaque { nil!() } else { docs![":= do"] }
]
.group(),
line!(),
body
if opaque { nil!() } else { docs![line!(), body] }
]
.group()
.nest(INDENT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,11 @@ def Lean_tests.Reject_do_dsl.test
(pure (Rust_primitives.Hax.Tuple2.mk
Rust_primitives.Hax.Tuple0.mk Rust_primitives.Hax.Tuple0.mk))

opaque Lean_tests.Opaque.an_opaque_fn
(_ : Rust_primitives.Hax.Tuple0)
: RustM Rust_primitives.Hax.Tuple0


def Lean_tests.Matching.test_const_matching
(x : u32)
(c : Char)
Expand Down
1 change: 1 addition & 0 deletions tests/lean-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod ite;
pub mod loops;
pub mod matching;
pub mod monadic;
pub mod opaque;
pub mod reject_do_dsl;
pub mod specs;
pub mod structs;
Expand Down
2 changes: 2 additions & 0 deletions tests/lean-tests/src/opaque.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[hax_lib::opaque]
pub fn an_opaque_fn() {}
Loading