Bug 1836869 - Switch malloc_size_of_derive to syn 2/synstructure 0.13. r=xpcom-reviewers,nika

Differential Revision: https://phabricator.services.mozilla.com/D180019
This commit is contained in:
Mike Hommey 2023-06-07 20:45:39 +00:00
Родитель 71f165597b
Коммит 9e0e81fd65
12 изменённых файлов: 15 добавлений и 2990 удалений

26
Cargo.lock сгенерированный
Просмотреть файл

@ -1244,7 +1244,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.18",
"synstructure 0.13.0",
"synstructure",
]
[[package]]
@ -3060,11 +3060,11 @@ dependencies = [
[[package]]
name = "malloc_size_of_derive"
version = "0.1.2"
version = "0.1.3"
dependencies = [
"proc-macro2",
"syn 1.0.107",
"synstructure 0.12.6",
"syn 2.0.18",
"synstructure",
]
[[package]]
@ -3936,7 +3936,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.18",
"synstructure 0.13.0",
"synstructure",
"unicode-xid",
]
@ -4956,7 +4956,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.18",
"synstructure 0.13.0",
"synstructure",
]
[[package]]
@ -5052,18 +5052,6 @@ dependencies = [
"thiserror",
]
[[package]]
name = "synstructure"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.107",
"unicode-xid",
]
[[package]]
name = "synstructure"
version = "0.13.0"
@ -5231,7 +5219,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.18",
"synstructure 0.13.0",
"synstructure",
]
[[package]]

20
gfx/wr/Cargo.lock сгенерированный
Просмотреть файл

@ -1518,11 +1518,11 @@ dependencies = [
[[package]]
name = "malloc_size_of_derive"
version = "0.1.2"
version = "0.1.3"
dependencies = [
"proc-macro2",
"syn 1.0.91",
"synstructure 0.12.3",
"syn 2.0.18",
"synstructure",
]
[[package]]
@ -1932,7 +1932,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 2.0.18",
"synstructure 0.13.0",
"synstructure",
"unicode-xid",
]
@ -2501,18 +2501,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "synstructure"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.91",
"unicode-xid",
]
[[package]]
name = "synstructure"
version = "0.13.0"

Просмотреть файл

@ -23,7 +23,6 @@ packages = [
"rand_core",
# transition to syn 2 is underway.
"syn",
"synstructure",
# Can be fixed by removing time dependency - see bug 1765324
"wasi",
]

Просмотреть файл

@ -109,7 +109,6 @@ TOLERATED_DUPES = {
"time": 2,
# Transition is underway from syn 1.x to 2.x. (bug 1835053)
"syn": 2,
"synstructure": 2,
}

Просмотреть файл

@ -1 +0,0 @@
{"files":{"Cargo.toml":"b9f3ce31a9ac80dc24f4afac7108b7cff44399f8d7503dc4addea4d256431a73","LICENSE":"219920e865eee70b7dcfc948a86b099e7f4fe2de01bcca2ca9a20c0a033f2b59","README.md":"a528e7356db49ea813c3290dd4f6b15d8e6c0a870cfc07a2df0f3d1381c575bf","src/lib.rs":"b8d9885399b22a5ee92b51e4ca757427da07775e940b25e1573180d9e8faf7d0","src/macros.rs":"e7cf1808faf5dac5ca25bd40ad99e95c2aab4f9899bd9327898761ea86271f7c"},"package":"f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"}

Просмотреть файл

@ -1,44 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "synstructure"
version = "0.12.6"
authors = ["Nika Layzell <nika@thelayzells.com>"]
include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE"]
description = "Helper methods and macros for custom derives"
documentation = "https://docs.rs/synstructure"
readme = "README.md"
keywords = ["syn", "macros", "derive", "expand_substructure", "enum"]
license = "MIT"
repository = "https://github.com/mystor/synstructure"
[dependencies.proc-macro2]
version = "1"
default-features = false
[dependencies.quote]
version = "1"
default-features = false
[dependencies.syn]
version = "1"
features = ["derive", "parsing", "printing", "clone-impls", "visit", "extra-traits"]
default-features = false
[dependencies.unicode-xid]
version = "0.2"
[dev-dependencies.synstructure_test_traits]
version = "0.1"
[features]
default = ["proc-macro"]
proc-macro = ["proc-macro2/proc-macro", "syn/proc-macro", "quote/proc-macro"]

Просмотреть файл

@ -1,7 +0,0 @@
Copyright 2016 Nika Layzell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

159
third_party/rust/synstructure-0.12.6/README.md поставляемый
Просмотреть файл

@ -1,159 +0,0 @@
# synstructure
[![Latest Version](https://img.shields.io/crates/v/synstructure.svg)](https://crates.io/crates/synstructure)
[![Documentation](https://docs.rs/synstructure/badge.svg)](https://docs.rs/synstructure)
[![Build Status](https://travis-ci.org/mystor/synstructure.svg?branch=master)](https://travis-ci.org/mystor/synstructure)
[![Rustc Version 1.31+](https://img.shields.io/badge/rustc-1.31+-lightgray.svg)](https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html)
> NOTE: What follows is an exerpt from the module level documentation. For full
> details read the docs on [docs.rs](https://docs.rs/synstructure/)
This crate provides helper types for matching against enum variants, and
extracting bindings to each of the fields in the deriving Struct or Enum in
a generic way.
If you are writing a `#[derive]` which needs to perform some operation on
every field, then you have come to the right place!
# Example: `WalkFields`
### Trait Implementation
```rust
pub trait WalkFields: std::any::Any {
fn walk_fields(&self, walk: &mut FnMut(&WalkFields));
}
impl WalkFields for i32 {
fn walk_fields(&self, _walk: &mut FnMut(&WalkFields)) {}
}
```
### Custom Derive
```rust
#[macro_use]
extern crate synstructure;
#[macro_use]
extern crate quote;
extern crate proc_macro2;
fn walkfields_derive(s: synstructure::Structure) -> proc_macro2::TokenStream {
let body = s.each(|bi| quote!{
walk(#bi)
});
s.bound_impl(quote!(example_traits::WalkFields), quote!{
fn walk_fields(&self, walk: &mut FnMut(&example_traits::WalkFields)) {
match *self { #body }
}
})
}
decl_derive!([WalkFields] => walkfields_derive);
/*
* Test Case
*/
fn main() {
test_derive! {
walkfields_derive {
enum A<T> {
B(i32, T),
C(i32),
}
}
expands to {
#[allow(non_upper_case_globals)]
const _DERIVE_example_traits_WalkFields_FOR_A: () = {
extern crate example_traits;
impl<T> example_traits::WalkFields for A<T>
where T: example_traits::WalkFields
{
fn walk_fields(&self, walk: &mut FnMut(&example_traits::WalkFields)) {
match *self {
A::B(ref __binding_0, ref __binding_1,) => {
{ walk(__binding_0) }
{ walk(__binding_1) }
}
A::C(ref __binding_0,) => {
{ walk(__binding_0) }
}
}
}
}
};
}
}
}
```
# Example: `Interest`
### Trait Implementation
```rust
pub trait Interest {
fn interesting(&self) -> bool;
}
impl Interest for i32 {
fn interesting(&self) -> bool { *self > 0 }
}
```
### Custom Derive
```rust
#[macro_use]
extern crate synstructure;
#[macro_use]
extern crate quote;
extern crate proc_macro2;
fn interest_derive(mut s: synstructure::Structure) -> proc_macro2::TokenStream {
let body = s.fold(false, |acc, bi| quote!{
#acc || example_traits::Interest::interesting(#bi)
});
s.bound_impl(quote!(example_traits::Interest), quote!{
fn interesting(&self) -> bool {
match *self {
#body
}
}
})
}
decl_derive!([Interest] => interest_derive);
/*
* Test Case
*/
fn main() {
test_derive!{
interest_derive {
enum A<T> {
B(i32, T),
C(i32),
}
}
expands to {
#[allow(non_upper_case_globals)]
const _DERIVE_example_traits_Interest_FOR_A: () = {
extern crate example_traits;
impl<T> example_traits::Interest for A<T>
where T: example_traits::Interest
{
fn interesting(&self) -> bool {
match *self {
A::B(ref __binding_0, ref __binding_1,) => {
false ||
example_traits::Interest::interesting(__binding_0) ||
example_traits::Interest::interesting(__binding_1)
}
A::C(ref __binding_0,) => {
false ||
example_traits::Interest::interesting(__binding_0)
}
}
}
}
};
}
}
}
```
For more example usage, consider investigating the `abomonation_derive` crate,
which makes use of this crate, and is fairly simple.

2488
third_party/rust/synstructure-0.12.6/src/lib.rs поставляемый

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,250 +0,0 @@
//! This module provides two utility macros for testing custom derives. They can
//! be used together to eliminate some of the boilerplate required in order to
//! declare and test custom derive implementations.
// Re-exports used by the decl_derive! and test_derive!
pub use proc_macro2::TokenStream as TokenStream2;
pub use syn::{parse_str, DeriveInput};
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
pub use proc_macro::TokenStream;
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
pub use syn::parse;
/// The `decl_derive!` macro declares a custom derive wrapper. It will parse the
/// incoming `TokenStream` into a `synstructure::Structure` object, and pass it
/// into the inner function.
///
/// Your inner function should take a `synstructure::Structure` by value, and
/// return a type implementing `synstructure::MacroResult`, for example:
///
/// ```
/// fn derive_simple(input: synstructure::Structure) -> proc_macro2::TokenStream {
/// unimplemented!()
/// }
///
/// fn derive_result(input: synstructure::Structure)
/// -> syn::Result<proc_macro2::TokenStream>
/// {
/// unimplemented!()
/// }
/// ```
///
/// # Usage
///
/// ### Without Attributes
/// ```
/// fn derive_interesting(_input: synstructure::Structure) -> proc_macro2::TokenStream {
/// quote::quote! { ... }
/// }
///
/// # const _IGNORE: &'static str = stringify! {
/// decl_derive!([Interesting] => derive_interesting);
/// # };
/// ```
///
/// ### With Attributes
/// ```
/// # fn main() {}
/// fn derive_interesting(_input: synstructure::Structure) -> proc_macro2::TokenStream {
/// quote::quote! { ... }
/// }
///
/// # const _IGNORE: &'static str = stringify! {
/// decl_derive!([Interesting, attributes(interesting_ignore)] => derive_interesting);
/// # };
/// ```
///
/// ### Decl Attributes & Doc Comments
/// ```
/// # fn main() {}
/// fn derive_interesting(_input: synstructure::Structure) -> proc_macro2::TokenStream {
/// quote::quote! { ... }
/// }
///
/// # const _IGNORE: &'static str = stringify! {
/// decl_derive! {
/// [Interesting] =>
/// #[allow(some_lint)]
/// /// Documentation Comments
/// derive_interesting
/// }
/// # };
/// ```
///
/// *This macro is available if `synstructure` is built with the `"proc-macro"`
/// feature.*
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[macro_export]
macro_rules! decl_derive {
// XXX: Switch to using this variant everywhere?
([$derives:ident $($derive_t:tt)*] => $(#[$($attrs:tt)*])* $inner:path) => {
#[proc_macro_derive($derives $($derive_t)*)]
#[allow(non_snake_case)]
$(#[$($attrs)*])*
pub fn $derives(
i: $crate::macros::TokenStream
) -> $crate::macros::TokenStream {
match $crate::macros::parse::<$crate::macros::DeriveInput>(i) {
Ok(p) => {
match $crate::Structure::try_new(&p) {
Ok(s) => $crate::MacroResult::into_stream($inner(s)),
Err(e) => e.to_compile_error().into(),
}
}
Err(e) => e.to_compile_error().into(),
}
}
};
}
/// The `decl_attribute!` macro declares a custom attribute wrapper. It will
/// parse the incoming `TokenStream` into a `synstructure::Structure` object,
/// and pass it into the inner function.
///
/// Your inner function should have the following type:
///
/// ```
/// fn attribute(
/// attr: proc_macro2::TokenStream,
/// structure: synstructure::Structure,
/// ) -> proc_macro2::TokenStream {
/// unimplemented!()
/// }
/// ```
///
/// # Usage
///
/// ```
/// fn attribute_interesting(
/// _attr: proc_macro2::TokenStream,
/// _structure: synstructure::Structure,
/// ) -> proc_macro2::TokenStream {
/// quote::quote! { ... }
/// }
///
/// # const _IGNORE: &'static str = stringify! {
/// decl_attribute!([interesting] => attribute_interesting);
/// # };
/// ```
///
/// *This macro is available if `synstructure` is built with the `"proc-macro"`
/// feature.*
#[cfg(all(
not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "wasi"))),
feature = "proc-macro"
))]
#[macro_export]
macro_rules! decl_attribute {
([$attribute:ident] => $(#[$($attrs:tt)*])* $inner:path) => {
#[proc_macro_attribute]
$(#[$($attrs)*])*
pub fn $attribute(
attr: $crate::macros::TokenStream,
i: $crate::macros::TokenStream,
) -> $crate::macros::TokenStream {
match $crate::macros::parse::<$crate::macros::DeriveInput>(i) {
Ok(p) => match $crate::Structure::try_new(&p) {
Ok(s) => $crate::MacroResult::into_stream($inner(attr.into(), s)),
Err(e) => e.to_compile_error().into(),
},
Err(e) => e.to_compile_error().into(),
}
}
};
}
/// Run a test on a custom derive. This macro expands both the original struct
/// and the expansion to ensure that they compile correctly, and confirms that
/// feeding the original struct into the named derive will produce the written
/// output.
///
/// You can add `no_build` to the end of the macro invocation to disable
/// checking that the written code compiles. This is useful in contexts where
/// the procedural macro cannot depend on the crate where it is used during
/// tests.
///
/// # Usage
///
/// ```
/// fn test_derive_example(_s: synstructure::Structure)
/// -> Result<proc_macro2::TokenStream, syn::Error>
/// {
/// Ok(quote::quote! { const YOUR_OUTPUT: &'static str = "here"; })
/// }
///
/// fn main() {
/// synstructure::test_derive!{
/// test_derive_example {
/// struct A;
/// }
/// expands to {
/// const YOUR_OUTPUT: &'static str = "here";
/// }
/// }
/// }
/// ```
#[macro_export]
macro_rules! test_derive {
($name:path { $($i:tt)* } expands to { $($o:tt)* }) => {
{
#[allow(dead_code)]
fn ensure_compiles() {
$($i)*
$($o)*
}
$crate::test_derive!($name { $($i)* } expands to { $($o)* } no_build);
}
};
($name:path { $($i:tt)* } expands to { $($o:tt)* } no_build) => {
{
let i = stringify!( $($i)* );
let parsed = $crate::macros::parse_str::<$crate::macros::DeriveInput>(i)
.expect(concat!(
"Failed to parse input to `#[derive(",
stringify!($name),
")]`",
));
let raw_res = $name($crate::Structure::new(&parsed));
let res = $crate::MacroResult::into_result(raw_res)
.expect(concat!(
"Procedural macro failed for `#[derive(",
stringify!($name),
")]`",
));
let expected = stringify!( $($o)* )
.parse::<$crate::macros::TokenStream2>()
.expect("output should be a valid TokenStream");
let mut expected_toks = $crate::macros::TokenStream2::from(expected);
if res.to_string() != expected_toks.to_string() {
panic!("\
test_derive failed:
expected:
```
{}
```
got:
```
{}
```\n",
$crate::unpretty_print(&expected_toks),
$crate::unpretty_print(&res),
);
}
}
};
}

Просмотреть файл

@ -1,6 +1,6 @@
[package]
name = "malloc_size_of_derive"
version = "0.1.2"
version = "0.1.3"
authors = ["The Servo Project Developers"]
license = "MIT/Apache-2.0"
description = "Crate for Firefox memory reporting, not intended for external use"
@ -11,5 +11,5 @@ proc-macro = true
[dependencies]
proc-macro2 = "1"
syn = { version = "1", features = ["full"] }
synstructure = "0.12"
syn = { version = "2", features = ["parsing"] }
synstructure = "0.13"

Просмотреть файл

@ -24,7 +24,7 @@ fn malloc_size_of_derive(s: synstructure::Structure) -> proc_macro2::TokenStream
let mut ignore = false;
let mut conditional = false;
for attr in binding.ast().attrs.iter() {
match attr.parse_meta().unwrap() {
match attr.meta {
syn::Meta::Path(ref path) | syn::Meta::List(syn::MetaList { ref path, .. }) => {
assert!(
!path.is_ident("ignore_malloc_size_of"),