From 2abfd0451599761a5a2fa0c7f3024bbab564537c Mon Sep 17 00:00:00 2001 From: Franziskus Kiefer Date: Thu, 7 Nov 2024 15:25:26 +0100 Subject: [PATCH] actually disable macros with cfg --- hax-lib/Cargo.toml | 7 +++++-- hax-lib/macros/Cargo.toml | 23 +++++++++++++++++------ hax-lib/macros/src/dummy.rs | 2 +- hax-lib/macros/src/lib.rs | 4 ++-- hax-lib/src/dummy.rs | 2 +- hax-lib/src/lib.rs | 6 +++--- hax-lib/src/proc_macros.rs | 6 ++++-- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/hax-lib/Cargo.toml b/hax-lib/Cargo.toml index 72365216a..bf31d343b 100644 --- a/hax-lib/Cargo.toml +++ b/hax-lib/Cargo.toml @@ -9,11 +9,14 @@ repository.workspace = true readme = "README.md" description = "Hax-specific helpers for Rust programs" -[dependencies] -hax-lib-macros = { workspace = true, optional = true } + +[target.'cfg(hax)'.dependencies] num-bigint = { version = "0.4.3", default-features = false, optional = true } num-traits = { version = "0.2.15", default-features = false, optional = true } +[dependencies] +hax-lib-macros = { workspace = true, optional = true } + [features] default = ["macros", "hax"] macros = ["dep:hax-lib-macros"] diff --git a/hax-lib/macros/Cargo.toml b/hax-lib/macros/Cargo.toml index 19d8d35ba..09457ba8e 100644 --- a/hax-lib/macros/Cargo.toml +++ b/hax-lib/macros/Cargo.toml @@ -12,18 +12,29 @@ description = "Hax-specific proc-macros for Rust programs" [lib] proc-macro = true -[dependencies] +[target.'cfg(hax)'.dependencies] proc-macro-error = { version = "1.0.4", optional = true } +hax-lib-macros-types = { workspace = true, optional = true } +paste = { version = "1.0.15", optional = true } + +[dependencies] proc-macro2 = { workspace = true, optional = true } quote = { workspace = true } syn = { version = "2.0", features = ["full", "visit-mut"] } -hax-lib-macros-types = { workspace = true, optional = true } -paste = { version = "1.0.15", optional = true } [features] -hax = [ "dep:paste", "dep:hax-lib-macros-types", "dep:proc-macro-error", "dep:proc-macro2", - "syn/visit", "syn/extra-traits", "syn/parsing" - ] +hax = [ + "dep:paste", + "dep:hax-lib-macros-types", + "dep:proc-macro-error", + "dep:proc-macro2", + "syn/visit", + "syn/extra-traits", + "syn/parsing", +] [dev-dependencies] hax-lib = { path = ".." } + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(hax)', 'cfg(doc_cfg)'] } diff --git a/hax-lib/macros/src/dummy.rs b/hax-lib/macros/src/dummy.rs index c415c8802..69988e652 100644 --- a/hax-lib/macros/src/dummy.rs +++ b/hax-lib/macros/src/dummy.rs @@ -61,7 +61,7 @@ pub fn lemma(_attr: TokenStream, _item: TokenStream) -> TokenStream { } fn unsafe_expr() -> TokenStream { - quote! { ::std::compile_error!("`hax_lib::unsafe_expr` has no meaning outside of hax extraction, please use it solely on hax only places.") }.into() + quote! {}.into() } #[proc_macro] diff --git a/hax-lib/macros/src/lib.rs b/hax-lib/macros/src/lib.rs index 28f38b917..ec7b1f1b1 100644 --- a/hax-lib/macros/src/lib.rs +++ b/hax-lib/macros/src/lib.rs @@ -1,8 +1,8 @@ // Proc-macros must "reside in the root of the crate": whence the use // of `std::include!` instead of proper module declaration. -#[cfg(feature = "hax")] +#[cfg(hax)] std::include!("implementation.rs"); -#[cfg(not(feature = "hax"))] +#[cfg(not(hax))] std::include!("dummy.rs"); diff --git a/hax-lib/src/dummy.rs b/hax-lib/src/dummy.rs index 44d5d4a51..85febeeec 100644 --- a/hax-lib/src/dummy.rs +++ b/hax-lib/src/dummy.rs @@ -11,7 +11,7 @@ macro_rules! debug_assert { #[macro_export] macro_rules! assert { ($($arg:tt)*) => { - ::core::assert!($arg); + ::core::assert!($($arg)*); }; } diff --git a/hax-lib/src/lib.rs b/hax-lib/src/lib.rs index 9e0742efa..304ace616 100644 --- a/hax-lib/src/lib.rs +++ b/hax-lib/src/lib.rs @@ -18,11 +18,11 @@ #[cfg(feature = "macros")] mod proc_macros; -// hax engine relies on `hax-lib` names: to avoid clutering names with +// hax engine relies on `hax-lib` names: to avoid cluttering names with // an additional `implementation` in all paths, we `include!` instead // of doing conditional `mod` and `pub use`. -#[cfg(not(feature = "hax"))] +#[cfg(not(hax))] core::include!("dummy.rs"); -#[cfg(feature = "hax")] +#[cfg(hax)] core::include!("implementation.rs"); diff --git a/hax-lib/src/proc_macros.rs b/hax-lib/src/proc_macros.rs index 866c7cfda..92eb4bd7a 100644 --- a/hax-lib/src/proc_macros.rs +++ b/hax-lib/src/proc_macros.rs @@ -2,10 +2,12 @@ //! proc-macro crate cannot export anything but procedural macros. pub use hax_lib_macros::{ - attributes, ensures, exclude, impl_fn_decoration, include, lemma, loop_invariant, opaque_type, - refinement_type, requires, trait_fn_decoration, + attributes, ensures, exclude, include, lemma, opaque_type, refinement_type, requires, }; +#[cfg(hax)] +pub use hax_lib_macros::{impl_fn_decoration, loop_invariant, trait_fn_decoration}; + pub use hax_lib_macros::{ process_init, process_read, process_write, protocol_messages, pv_constructor, pv_handwritten, };