Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates to parser #56

Merged
merged 9 commits into from
Jul 8, 2023
Merged

updates to parser #56

merged 9 commits into from
Jul 8, 2023

Conversation

knickish
Copy link
Collaborator

Fixes many issues related to generics

@not-fl3
Copy link
Owner

not-fl3 commented May 22, 2023

wow, great work!

diff --git a/derive/src/parse.rs b/derive/src/parse.rs
index 42de5d2..67d8575 100644
--- a/derive/src/parse.rs
+++ b/derive/src/parse.rs
@@ -14,14 +14,14 @@ use alloc::{format, vec};
 
 use proc_macro::{Delimiter, Group, TokenStream, TokenTree};
 
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub struct Attribute {
     pub name: String,
     pub tokens: Vec<String>,
 }
 
 #[allow(dead_code)]
-#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Copy, Clone)]
 pub enum Visibility {
     Public,
     Crate,
@@ -29,12 +29,12 @@ pub enum Visibility {
     Private,
 }
 
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub struct Lifetime {
     pub(crate) ident: String,
 }
 
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub struct Field {
     pub attributes: Vec<Attribute>,
     pub vis: Visibility,
@@ -42,19 +42,19 @@ pub struct Field {
     pub ty: Type,
 }
 
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub enum ConstValType {
     Value(isize),
     Named(Box<Type>),
 }
 
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub enum FnType {
     Bare,
     Closure { reusable: bool, fn_mut: bool },
 }
 
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub enum Category {
     Never,
     None,
@@ -96,7 +96,7 @@ pub enum Category {
 }
 
 #[allow(dead_code)]
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub struct Type {
     pub ident: Category,
     pub wraps: Option<Vec<Type>>,
@@ -104,7 +104,7 @@ pub struct Type {
     pub as_other: Option<Box<Type>>,
 }
 
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub enum Generic {
     ConstGeneric {
         name: String,
@@ -126,7 +126,7 @@ pub enum Generic {
     },
 }
 
-#[derive(Debug, Clone, PartialEq, Hash, Eq)]
+#[derive(Debug, Clone)]
 pub struct Struct {
     pub name: Option<String>,
     pub named: bool,
@@ -1481,25 +1481,13 @@ fn get_all_bounds<T: Iterator<Item = TokenTree> + Clone>(source: &mut Peekable<T
     for gen in ret.iter_mut() {
         match gen {
             Generic::Generic { bounds, .. } => {
-                *bounds = std::mem::take(bounds)
-                    .into_iter()
-                    .collect::<HashSet<_>>()
-                    .into_iter()
-                    .collect()
+                *bounds = std::mem::take(bounds);
             }
             Generic::Lifetime { bounds, .. } => {
-                *bounds = std::mem::take(bounds)
-                    .into_iter()
-                    .collect::<HashSet<_>>()
-                    .into_iter()
-                    .collect()
+                *bounds = std::mem::take(bounds);
             }
             Generic::WhereBounded { bounds, .. } => {
-                *bounds = std::mem::take(bounds)
-                    .into_iter()
-                    .collect::<HashSet<_>>()
-                    .into_iter()
-                    .collect()
+                *bounds = std::mem::take(bounds);
             }
             _ => (),
         }

<- is this collect() for de-duplication? removing those traits reduce compilation time by ~0.1s and reduce /target space usage by 1M, also a bit less runtime allocations during the collect().

Also this for gen in ret.iter_mut() { looks a little suspicios, is getting only the last value from ret an expected behavior?

@knickish
Copy link
Collaborator Author

You're correct, those were not needed so far as I can tell.

@not-fl3
Copy link
Owner

not-fl3 commented May 23, 2023

You're correct, those were not needed so far as I can tell.

got it. So maybe we can avoid that ret variable at all and just add to the bounds right away while parsing? (I did not tried and not sure if this is possible)

@knickish
Copy link
Collaborator Author

knickish commented Jul 2, 2023

@not-fl3 I was able to remove that bit also, it was indeed leftover

@not-fl3 not-fl3 merged commit 12b45d2 into not-fl3:master Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants