diff --git a/.gitignore b/.gitignore index af93bbc0..eb5a316c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ target -/.vscode diff --git a/Cargo.lock b/Cargo.lock index 730a9871..6174f0bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,6 +428,15 @@ dependencies = [ "slab", ] +[[package]] +name = "fuzzer" +version = "0.0.0" +dependencies = [ + "arbitrary", + "libfuzzer-sys", + "smallvec", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -459,9 +468,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", @@ -471,9 +480,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", @@ -486,9 +495,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", ] @@ -889,17 +898,13 @@ dependencies = [ "rayon", "serde_core", "serde_test", + "smallvec-macro", "zeroize", ] [[package]] -name = "smallvec-fuzz" +name = "smallvec-macro" version = "0.0.0" -dependencies = [ - "arbitrary", - "libfuzzer-sys", - "smallvec", -] [[package]] name = "syn" diff --git a/Cargo.toml b/Cargo.toml index bf7c9760..3ded9bd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [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" -repository = "https://github.com/servo/rust-smallvec" +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true description = "'Small vector' optimization: store up to a small number of items on the stack" keywords = ["small", "vec", "vector", "stack", "no_std"] categories = ["data-structures"] -exclude = [".gitignore", "tests/", "fuzz/", "benches/", ".github/"] +exclude = [".gitignore", "tests/", "fuzz/", "benches/", ".github/", "rustfmt.toml", ".vscode/"] [profile.bench] lto = "fat" @@ -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 = [ @@ -58,12 +52,13 @@ proptest = { version = "1", optional = true, features = [ ], default-features = false } rayon = { version = "1", optional = true, default-features = false } serde_core = { version = "1", optional = true, default-features = false } +smallvec-macro = { version = "0.0.0", path = "./macro", default-features = false } zeroize = { version = "1", optional = true, default-features = false } [dev-dependencies] serde_test = "1" criterion = "0.8" -iai-callgrind = "0.14" +iai-callgrind = "0.16" [[test]] name = "arbitrary" @@ -116,4 +111,13 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [workspace] -members = [".", "fuzz"] +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" +] diff --git a/README.md b/README.md index 5825ebd2..f87a7e4b 100644 --- a/README.md +++ b/README.md @@ -71,5 +71,6 @@ v.sort(); > [!NOTE] > > - SmallVec without any features enabled does not make use of the standard library. -> - The `rayon` feature implicitly requires `std`. -> - The `allocator-api2` feature requires `allocator-api` +> - The `rayon` and `proptest` features implicitly require `std`. +> - The `allocator-api2` feature requires `allocator-api`, though it does not + require `nightly` 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/macro/Cargo.toml b/macro/Cargo.toml new file mode 100644 index 00000000..7e7527bf --- /dev/null +++ b/macro/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "smallvec-macro" +version = "0.0.0" +edition.workspace = true +rust-version.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +description = "proc-macro crate for SmallVec" +keywords = [] +categories = [] + +[lib] +proc-macro = true +path = "./lib.rs" \ No newline at end of file diff --git a/macro/lib.rs b/macro/lib.rs new file mode 100644 index 00000000..e2fca5b9 --- /dev/null +++ b/macro/lib.rs @@ -0,0 +1,30 @@ +use proc_macro::{ + Delimiter, + TokenStream, + TokenTree +}; + +#[proc_macro_attribute] +pub fn syntax(attribute: TokenStream, item: TokenStream) -> TokenStream { + let mut element = Vec::::new(); + let mut iterator = item.into_iter().fuse(); + loop { + match [iterator.next(), iterator.next()] { + [ + Some(TokenTree::Punct(punctuation)), + Some(TokenTree::Group(group)) + ] if (punctuation.as_char(), group.delimiter()) == ('#', Delimiter::Bracket) => { + element.extend([punctuation.into(), group.into()]); + } + mut trees => { + element.extend( + attribute + .into_iter() + .chain(trees.iter_mut().flat_map(Option::take)) + .chain(iterator) + ); + return element.into_iter().collect(); + } + }; + } +} diff --git a/src/lib.rs b/src/lib.rs index 119f90a9..5deaf7e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,7 +130,8 @@ use { from_raw_parts_mut } }, - newrange::NewRange + newrange::NewRange, + smallvec_macro::syntax }; pub use { error::SmallVecError, @@ -141,12 +142,7 @@ pub use { splice::Splice } }; -#[cfg(feature = "internals")] -pub use { - locatedlength::LocatedLength, - rawsmallvec::RawSmallVec -}; -#[cfg(not(feature = "internals"))] +#[cfg_attr(feature = "internals", syntax(pub))] use { locatedlength::LocatedLength, rawsmallvec::RawSmallVec