From fa4b618fb0e8430594c9a4f31b9638126f5c763d Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sat, 17 Oct 2026 14:37:14 +0200 Subject: [PATCH 1/4] feat: add syntax macro --- Cargo.lock | 35 ++++++++++++++++++++--------------- Cargo.toml | 30 ++++++++++++++++-------------- README.md | 2 +- fuzz/Cargo.toml | 9 ++++++--- src/lib.rs | 10 +++------- syntax/Cargo.toml | 16 ++++++++++++++++ syntax/lib.rs | 25 +++++++++++++++++++++++++ 7 files changed, 87 insertions(+), 40 deletions(-) create mode 100644 syntax/Cargo.toml create mode 100644 syntax/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 977bd2f7..ce95fb6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -402,6 +402,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fuzzer" +version = "0.0.0" +dependencies = [ + "arbitrary", + "libfuzzer-sys", + "smallvec", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -444,9 +453,9 @@ checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" [[package]] name = "iai-callgrind" -version = "0.14.2" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c9e864ad001cbbf35a64f7b574998823b8622bb483a25246fa1b0e2b3888686" +checksum = "0b1e4910d3a9137442723dfb772c32dc10674c4181ca078d2fd227cd5dce9db0" dependencies = [ "bincode", "derive_more", @@ -456,9 +465,9 @@ dependencies = [ [[package]] name = "iai-callgrind-macros" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9cee6c3bc32b63ff40e5e56190b1276d2bd0e0b319aa6f998864c27865d3b4e" +checksum = "4d03775318d3f9f01b39ac6612b01464006dc397a654a89dd57df2fd34fb68c3" dependencies = [ "derive_more", "proc-macro-error2", @@ -471,9 +480,9 @@ dependencies = [ [[package]] name = "iai-callgrind-runner" -version = "0.14.2" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82491521e6505b06a824274712a1307904e7cdfdf047735f7dfdb28b5f7a337" +checksum = "b74c9743c00c3bca4aaffc69c87cae56837796cd362438daf354a3f785788c68" dependencies = [ "serde", ] @@ -900,18 +909,10 @@ dependencies = [ "rayon", "serde_core", "serde_test", + "syntax", "zeroize", ] -[[package]] -name = "smallvec-fuzz" -version = "0.0.0" -dependencies = [ - "arbitrary", - "libfuzzer-sys", - "smallvec", -] - [[package]] name = "syn" version = "2.0.119" @@ -934,6 +935,10 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syntax" +version = "0.0.0" + [[package]] name = "thiserror" version = "2.0.20" diff --git a/Cargo.toml b/Cargo.toml index 51c626e1..fb2673cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "smallvec" version = "2.0.0-beta.3" -edition = "2024" -rust-version = "1.86" -authors = ["The Servo Project Developers"] -license = "MIT OR Apache-2.0" +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +license.workspace = true repository = "https://github.com/servo/rust-smallvec" description = "'Small vector' optimization: store up to a small number of items on the stack" keywords = ["small", "vec", "vector", "stack", "no_std"] @@ -18,26 +18,20 @@ opt-level = 3 debug = false strip = true -# Dedicated profile for the iai-callgrind benchmarks. Callgrind needs the -# function symbols in the binary to attribute event counts, so we disable -# stripping (and keep debug info for line-level detail). Without symbols the -# runner collects zero events for every benchmark. LTO is left on (inherited) -# since it does not affect collection and keeps the run representative. [profile.callgrind] inherits = "bench" -debug = 1 +debug = true strip = false [features] allocator-api = [] -allocator-api2 = ["dep:allocator-api2", "allocator-api"] +allocator-api2 = ["allocator-api", "dep:allocator-api2"] internals = [] proptest = ["dep:proptest", "std"] -rayon = ["std", "dep:rayon"] +rayon = ["dep:rayon", "std"] serde = ["dep:serde_core"] specialization = [] std = [] -zeroize = ["dep:zeroize"] [dependencies] allocator-api2 = { version = "0.4", optional = true, features = ["alloc"], default-features = false } @@ -50,12 +44,13 @@ malloc_size_of = { version = "0.1", optional = true, default-features = false } proptest = { version = "1.11", optional = true, features = ["std"], default-features = false } rayon = { version = "1.12", optional = true, default-features = false } serde_core = { version = "1.0", optional = true, default-features = false } +syntax = { path = "./syntax" } zeroize = { version = "1.9", optional = true, default-features = false } [dev-dependencies] serde_test = "1.0" criterion = "0.8" -iai-callgrind = "0.14" +iai-callgrind = "0.16" [[test]] name = "arbitrary" @@ -104,7 +99,14 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [workspace] +package.edition = "2024" +package.authors = ["The Servo Project Developers"] +package.license = "MIT OR Apache-2.0" +package.repository = "https://github.com/servo/rust-smallvec" +package.rust-version = "1.86" +resolver = "3" members = [ ".", "fuzz", + "syntax" ] diff --git a/README.md b/README.md index c1dd9540..50b4daba 100644 --- a/README.md +++ b/README.md @@ -70,5 +70,5 @@ v.sort(); > [!NOTE] > > - SmallVec without any features enabled does not make use of the standard library. -> - The `rayon` feature implicitly requires `std`. +> - The `rayon` and `proptest` features implicitly require `std`. > - The `allocator-api2` feature requires `allocator-api` diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index d4456908..2427015f 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -1,9 +1,12 @@ [package] -name = "smallvec-fuzz" +name = "fuzzer" version = "0.0.0" -authors = ["The Servo Project Developers"] +authors.workspace = true +edition.workspace = true +repository.workspace = true +license.workspace = true +description = "Fuzzer for SmallVec" publish = false -edition = "2024" [package.metadata] cargo-fuzz = true diff --git a/src/lib.rs b/src/lib.rs index fa03ac5e..4f96c7b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,14 +87,10 @@ use { drop_in_place } }, - newrange::NewRange + newrange::NewRange, + syntax::syntax }; -#[cfg(feature = "internals")] -pub use { - locatedlength::LocatedLength, - rawsmallvec::RawSmallVec -}; -#[cfg(not(feature = "internals"))] +#[cfg_attr(feature = "internals", syntax(pub))] use { locatedlength::LocatedLength, rawsmallvec::RawSmallVec diff --git a/syntax/Cargo.toml b/syntax/Cargo.toml new file mode 100644 index 00000000..e1f3c2df --- /dev/null +++ b/syntax/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "syntax" +version = "0.0.0" +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +description = "Syntax macro for SmallVec" +publish = false + +[lib] +proc-macro = true +path = "./lib.rs" + +[dependencies] diff --git a/syntax/lib.rs b/syntax/lib.rs new file mode 100644 index 00000000..83c1a6b4 --- /dev/null +++ b/syntax/lib.rs @@ -0,0 +1,25 @@ +use proc_macro::{ + Delimiter, + TokenStream, + TokenTree +}; + +#[proc_macro_attribute] +pub fn syntax(attr: TokenStream, item: TokenStream) -> TokenStream { + let mut item_attrs = Vec::::new(); + let mut iter = item.into_iter().fuse(); + loop { + match [iter.next(), iter.next()] { + [Some(TokenTree::Punct(p)), Some(TokenTree::Group(g))] + if (p.as_char(), g.delimiter()) == ('#', Delimiter::Bracket) => + { + item_attrs.extend([p.into(), g.into()]); + } + mut trees => { + let trees = trees.iter_mut().flat_map(Option::take); + item_attrs.extend(attr.into_iter().chain(trees).chain(iter)); + return item_attrs.into_iter().collect(); + } + }; + } +} From 9f5b4dc936d8958a87793c0beb11e69ce0a7d1d9 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sun, 18 Oct 2026 16:16:58 +0200 Subject: [PATCH 2/4] docs: add nightly warning --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 50b4daba..89ce9845 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,4 @@ v.sort(); > > - SmallVec without any features enabled does not make use of the standard library. > - The `rayon` and `proptest` features implicitly require `std`. -> - The `allocator-api2` feature requires `allocator-api` +> - The `allocator-api2` feature requires `allocator-api`, though it does not require `nightly` From 057ad5cee8c6ddb2d8be29c6652b5bc396de919b Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sun, 18 Oct 2026 16:21:17 +0200 Subject: [PATCH 3/4] fix: markdownlint --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 89ce9845..6a30ad0b 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,5 @@ v.sort(); > > - SmallVec without any features enabled does not make use of the standard library. > - The `rayon` and `proptest` features implicitly require `std`. -> - The `allocator-api2` feature requires `allocator-api`, though it does not require `nightly` +> - The `allocator-api2` feature requires `allocator-api`, though it does not + require `nightly` From 0114f2677ae3c3bb8c09430b4114b5b3f755874d Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sun, 18 Oct 2026 16:22:47 +0200 Subject: [PATCH 4/4] fix: no markdown trailing space --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a30ad0b..3f5d5d06 100644 --- a/README.md +++ b/README.md @@ -71,5 +71,5 @@ v.sort(); > > - SmallVec without any features enabled does not make use of the standard library. > - The `rayon` and `proptest` features implicitly require `std`. -> - The `allocator-api2` feature requires `allocator-api`, though it does not +> - The `allocator-api2` feature requires `allocator-api`, though it does not require `nightly`