Skip to content

Commit

Permalink
ref(relay): Remove syn v1 dependency (#4354)
Browse files Browse the repository at this point in the history
Fixes: #4308
  • Loading branch information
Dav1dde authored Dec 6, 2024
1 parent 64a8f95 commit 050aa2d
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 95 deletions.
99 changes: 44 additions & 55 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ sqlx = { version = "0.8.2", default-features = false }
statsdproxy = { version = "0.2.0", default-features = false }
symbolic-common = { version = "12.12.3", default-features = false }
symbolic-unreal = { version = "12.12.3", default-features = false }
syn = "1.0.109"
syn2 = { package = "syn", version = "2.0.11" }
synstructure = "0.12.6"
synstructure2 = { package = "synstructure", version = "0.13.1" }
syn = { version = "2.0.90" }
synstructure = { version = "0.13.1" }
# This dependency was added through git since we are experimenting with a fork of sysinfo which adds additional
# capabilities of reading cgroups memory stats. Such stats are used in Relay to correctly determine memory usage.
sysinfo = { git = "https://github.com/getsentry/sysinfo.git", rev = "e2e5d530600f96bdd79652c856918da23e5dd938" }
Expand Down
4 changes: 2 additions & 2 deletions relay-event-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ workspace = true

[dependencies]
quote = { workspace = true }
syn2 = { workspace = true }
synstructure2 = { workspace = true }
syn = { workspace = true }
synstructure = { workspace = true }
proc-macro2 = { workspace = true }

[lib]
Expand Down
4 changes: 2 additions & 2 deletions relay-event-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use syn2::{self as syn, Ident, Lit, LitBool, LitInt, LitStr};
use synstructure2::{self as synstructure, decl_derive};
use syn::{Ident, Lit, LitBool, LitInt, LitStr};
use synstructure::decl_derive;

mod utils;

Expand Down
3 changes: 1 addition & 2 deletions relay-event-derive/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn2 as syn;
use synstructure2::{Structure, VariantInfo};
use synstructure::{Structure, VariantInfo};

pub trait SynstructureExt {
fn try_each_variant<F, R>(&self, f: F) -> syn::Result<TokenStream>
Expand Down
2 changes: 1 addition & 1 deletion relay-ffi-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ proc-macro = true
workspace = true

[dependencies]
syn2 = { workspace = true, features = ["fold", "full"] }
syn = { workspace = true, features = ["fold", "full"] }
quote = { workspace = true }
10 changes: 5 additions & 5 deletions relay-ffi-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

use proc_macro::TokenStream;
use quote::ToTokens;
use syn2::fold::Fold;
use syn::fold::Fold;

struct CatchUnwind;

impl CatchUnwind {
fn fold(&mut self, input: TokenStream) -> TokenStream {
let f = syn2::parse(input).expect("#[catch_unwind] can only be applied to functions");
let f = syn::parse(input).expect("#[catch_unwind] can only be applied to functions");
self.fold_item_fn(f).to_token_stream().into()
}
}

impl Fold for CatchUnwind {
fn fold_item_fn(&mut self, i: syn2::ItemFn) -> syn2::ItemFn {
fn fold_item_fn(&mut self, i: syn::ItemFn) -> syn::ItemFn {
if i.sig.unsafety.is_none() {
panic!("#[catch_unwind] requires `unsafe fn`");
}
Expand All @@ -38,8 +38,8 @@ impl Fold for CatchUnwind {
})
}};

let block = Box::new(syn2::parse2(folded).unwrap());
syn2::ItemFn { block, ..i }
let block = Box::new(syn::parse2(folded).unwrap());
syn::ItemFn { block, ..i }
}
}

Expand Down
4 changes: 2 additions & 2 deletions relay-protocol-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ workspace = true

[dependencies]
quote = { workspace = true }
syn2 = { workspace = true }
synstructure2 = { workspace = true }
syn = { workspace = true }
synstructure = { workspace = true }
proc-macro2 = { workspace = true }

[lib]
Expand Down
6 changes: 3 additions & 3 deletions relay-protocol-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use std::str::FromStr;

use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use syn2::spanned::Spanned;
use syn2::{self as syn, Data, Error, Lit, LitStr};
use synstructure2::{self as synstructure, decl_derive};
use syn::spanned::Spanned;
use syn::{Data, Error, Lit, LitStr};
use synstructure::decl_derive;

mod utils;

Expand Down
3 changes: 1 addition & 2 deletions relay-protocol-derive/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn2 as syn;
use synstructure2::{Structure, VariantInfo};
use synstructure::{Structure, VariantInfo};

pub trait SynstructureExt {
fn try_each_variant<F, R>(&self, f: F) -> syn::Result<TokenStream>
Expand Down
2 changes: 1 addition & 1 deletion tools/document-metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ clap = { workspace = true, features = ["derive"] }
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
syn2 = { workspace = true, features = ["full"] }
syn = { workspace = true, features = ["full"] }

[dev-dependencies]
insta = { workspace = true }
2 changes: 1 addition & 1 deletion tools/document-metrics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::PathBuf;
use anyhow::{Context, Result};
use clap::{Parser, ValueEnum};
use serde::Serialize;
use syn2::{self as syn, Expr, Lit, LitStr};
use syn::{Expr, Lit, LitStr};

#[derive(Clone, Copy, Debug, ValueEnum)]
enum SchemaFormat {
Expand Down
2 changes: 1 addition & 1 deletion tools/document-pii/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ proc-macro2 = { workspace = true }
quote = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
syn2 = { workspace = true, features = ["visit", "full", "extra-traits"] }
syn = { workspace = true, features = ["visit", "full", "extra-traits"] }
walkdir = { workspace = true }

[dev-dependencies]
Expand Down
16 changes: 8 additions & 8 deletions tools/document-pii/src/item_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use std::io::BufRead;
use std::path::{Path, PathBuf};

use anyhow::anyhow;
use syn2::punctuated::Punctuated;
use syn2::visit::Visit;
use syn2::{ItemEnum, ItemStruct, UseTree};
use syn::punctuated::Punctuated;
use syn::visit::Visit;
use syn::{ItemEnum, ItemStruct, UseTree};

use crate::pii_finder::{FieldsWithAttribute, PiiFinder};
use crate::EnumOrStruct;
Expand Down Expand Up @@ -113,9 +113,9 @@ impl AstItemCollector {
for path in paths {
self.module_path = module_name_from_file(path)?;

let syntax_tree: syn2::File = {
let syntax_tree: syn::File = {
let file_content = fs::read_to_string(path.as_path())?;
syn2::parse_file(&file_content)?
syn::parse_file(&file_content)?
};

self.visit_file(&syntax_tree);
Expand All @@ -139,7 +139,7 @@ impl<'ast> Visit<'ast> for AstItemCollector {
.insert(enum_name, EnumOrStruct::Enum(node.clone()));
}

fn visit_item_use(&mut self, i: &'ast syn2::ItemUse) {
fn visit_item_use(&mut self, i: &'ast syn::ItemUse) {
let use_statements = usetree_to_paths(&i.tree, &self.module_path)
.iter()
.filter(|s| s.contains("relay"))
Expand Down Expand Up @@ -171,7 +171,7 @@ fn normalize_type_path(mut path: String, crate_root: &str, module_path: &str) ->
fn usetree_to_paths(use_tree: &UseTree, module_path: &str) -> Vec<String> {
let crate_root = module_path.split_once("::").map_or(module_path, |s| s.0);
let paths = flatten_use_tree(
syn2::Path {
syn::Path {
leading_colon: None,
segments: Punctuated::new(),
},
Expand All @@ -188,7 +188,7 @@ fn usetree_to_paths(use_tree: &UseTree, module_path: &str) -> Vec<String> {
///
/// For example: `use protocol::{Foo, Bar, Baz}` into `[protocol::Foo, protocol::Bar,
/// protocol::Baz]`.
fn flatten_use_tree(mut leading_path: syn2::Path, use_tree: &UseTree) -> Vec<String> {
fn flatten_use_tree(mut leading_path: syn::Path, use_tree: &UseTree) -> Vec<String> {
match use_tree {
UseTree::Path(use_path) => {
leading_path.segments.push(use_path.ident.clone().into());
Expand Down
3 changes: 1 addition & 2 deletions tools/document-pii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::path::PathBuf;

use clap::{command, Parser};
use serde::Serialize;
use syn2::ItemEnum;
use syn2::ItemStruct;
use syn::{ItemEnum, ItemStruct};
use walkdir::WalkDir;

use crate::item_collector::AstItemCollector;
Expand Down
8 changes: 4 additions & 4 deletions tools/document-pii/src/pii_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};

use anyhow::anyhow;
use proc_macro2::TokenTree;
use syn2::visit::Visit;
use syn2::{Attribute, Field, ItemEnum, ItemStruct, Meta, Path, Type, TypePath};
use syn::visit::Visit;
use syn::{Attribute, Field, ItemEnum, ItemStruct, Meta, Path, Type, TypePath};

use crate::EnumOrStruct;

Expand Down Expand Up @@ -236,9 +236,9 @@ fn get_field_types(path: &Path, segments: &mut BTreeSet<String>) {
let mut ident = first_segment.ident.to_string();

// Recursion on AngleBracketed args is necessary for nested generic types
if let syn2::PathArguments::AngleBracketed(angle_bracketed) = &first_segment.arguments {
if let syn::PathArguments::AngleBracketed(angle_bracketed) = &first_segment.arguments {
for generic_arg in angle_bracketed.args.iter() {
if let syn2::GenericArgument::Type(Type::Path(path)) = generic_arg {
if let syn::GenericArgument::Type(Type::Path(path)) = generic_arg {
get_field_types(&path.path, segments);
}
}
Expand Down

0 comments on commit 050aa2d

Please sign in to comment.