Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ad11629
Starting towards parsing the spec macro on traits and trait items
luketpeterson Jan 9, 2026
f0b851f
Removing spec invocations from function items within trait definitions
luketpeterson Jan 11, 2026
f9147a9
Short comments describing trait fn mangling
luketpeterson Jan 12, 2026
a333732
Adding test for trait specs
luketpeterson Jan 12, 2026
cd25fa4
Adding trait function mangling. Impl mangling still needed
luketpeterson Jan 12, 2026
8aa724a
refactoring trait logic into its own module
luketpeterson Jan 12, 2026
fa0b36f
Adding impl [spec] handling
luketpeterson Jan 12, 2026
4cc49a7
Updating test to also test specs on the implementation as well as on …
luketpeterson Jan 12, 2026
bdf6b3d
Adding `#[doc(hidden)]` and `#[inline]` attribs in the appropriate pl…
luketpeterson Jan 12, 2026
3c25d51
Removing unnecessary docs (which are always hidden) from the emitted …
luketpeterson Jan 12, 2026
53c76b2
Reverting default runtime behavior feature
luketpeterson Jan 12, 2026
35b7ede
Apply suggestions from code review
luketpeterson Jan 13, 2026
00f9d3d
Fixing rename missed by previous commit
luketpeterson Jan 13, 2026
770c30b
Throwing error when spec element is supplied on top-level spec attrib…
luketpeterson Jan 13, 2026
d116cbf
Making it an error if a trait function impl has a spec that contains …
luketpeterson Jan 17, 2026
ae1784d
Oops. Added default cargo feature in the last commit
luketpeterson Jan 17, 2026
439f900
Making #[spec] attribs on impl functions illegal
luketpeterson Jan 17, 2026
a1340e4
Moving trait and impl-block code to anodized-core
luketpeterson Jan 17, 2026
e74bdee
rearrange and fmt
mkovaxx Jan 19, 2026
fdc869c
meh
mkovaxx Jan 19, 2026
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 crates/anodized-core/src/annotate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl Parse for Spec {
maintains,
captures,
ensures,
span: input.span(),
})
}
}
Expand Down
20 changes: 20 additions & 0 deletions crates/anodized-core/src/annotate/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::test_util::assert_spec_eq;

use super::*;
use proc_macro2::Span;
use syn::parse_quote;

#[test]
Expand All @@ -18,6 +19,7 @@ fn simple_spec() {
closure: parse_quote! { |output| output > x },
cfg: None,
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand All @@ -40,6 +42,7 @@ fn all_clauses() {
closure: parse_quote! { |z| z >= x },
cfg: None,
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -101,6 +104,7 @@ fn array_of_conditions() {
cfg: None,
},
],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand All @@ -120,6 +124,7 @@ fn ensures_with_explicit_closure() {
closure: parse_quote! { |result| result.is_ok() || result.unwrap_err().kind() == ErrorKind::NotFound },
cfg: None,
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -151,6 +156,7 @@ fn multiple_clauses_of_same_flavor() {
cfg: None,
},
],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -193,6 +199,7 @@ fn mixed_single_and_array_clauses() {
cfg: None,
},
],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand All @@ -218,6 +225,7 @@ fn cfg_attributes() {
closure: parse_quote! { |output| output < x },
cfg: Some(parse_quote! { not(debug_assertions) }),
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -269,6 +277,7 @@ fn macro_in_condition() {
closure: parse_quote! { |output| matches!(self.state, State::Running) },
cfg: None,
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -298,6 +307,7 @@ fn binds_pattern() {
cfg: None,
},
],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand All @@ -323,6 +333,7 @@ fn multiple_conditions() {
maintains: vec![parse_quote! { self.items.len() <= self.items.capacity() }],
captures: vec![],
ensures: vec![],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -352,6 +363,7 @@ fn rename_return_value() {
cfg: None,
},
],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand All @@ -375,6 +387,7 @@ fn captures_simple_identifier() {
closure: parse_quote! { |output| output == old_count + 1 },
cfg: None,
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand All @@ -398,6 +411,7 @@ fn captures_identifier_with_alias() {
closure: parse_quote! { |output| output > prev_value },
cfg: None,
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -449,6 +463,7 @@ fn captures_array() {
cfg: None,
},
],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand All @@ -475,6 +490,7 @@ fn captures_with_all_clauses() {
closure: parse_quote! { |result| result > old_val },
cfg: None,
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -507,6 +523,7 @@ fn captures_array_expression() {
closure: parse_quote! { |output| slice.len() == 3 },
cfg: None,
}],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -576,6 +593,7 @@ fn captures_edge_case_cast_expr() {
alias: parse_quote! { old_red },
}],
ensures: vec![],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -605,6 +623,7 @@ fn captures_edge_case_array_of_cast_exprs() {
alias: parse_quote! { r8g8b8 },
}],
ensures: vec![],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down Expand Up @@ -638,6 +657,7 @@ fn captures_edge_case_list_of_cast_exprs() {
},
],
ensures: vec![],
span: Span::call_site(),
};

assert_spec_eq(&spec, &expected);
Expand Down
4 changes: 2 additions & 2 deletions crates/anodized-core/src/instrument/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use quote::{ToTokens, quote};
use syn::{Block, Ident, ItemFn, parse::Result, parse_quote};

impl Backend {
pub fn instrument_fn(self, spec: Spec, mut func: ItemFn) -> syn::Result<ItemFn> {
pub fn instrument_fn(&self, spec: Spec, mut func: ItemFn) -> syn::Result<ItemFn> {
let is_async = func.sig.asyncness.is_some();

// Extract the return type from the function signature
Expand All @@ -27,7 +27,7 @@ impl Backend {
}

fn instrument_fn_body(
self,
&self,
spec: &Spec,
original_body: &Block,
is_async: bool,
Expand Down
2 changes: 2 additions & 0 deletions crates/anodized-core/src/instrument/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::Meta;

pub mod function;
pub mod trait_spec;

pub struct Backend {
pub build_check: fn(Option<&Meta>, &TokenStream, &str, &TokenStream) -> TokenStream,
Expand Down
Loading