From 264d8f265f2a4e7879db09aa0baa89a9ef4ade89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 29 Dec 2021 21:04:29 +0000 Subject: [PATCH] remove dead code: ShaderDefs derive (#3490) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - remove some dead code and see if someone isn't happy about it Co-authored-by: François <8672791+mockersf@users.noreply.github.com> --- crates/bevy_derive/src/lib.rs | 8 ---- crates/bevy_derive/src/modules.rs | 1 - crates/bevy_derive/src/shader_defs.rs | 65 --------------------------- 3 files changed, 74 deletions(-) delete mode 100644 crates/bevy_derive/src/shader_defs.rs diff --git a/crates/bevy_derive/src/lib.rs b/crates/bevy_derive/src/lib.rs index 242a9a244fa7dd..902e92216e1c66 100644 --- a/crates/bevy_derive/src/lib.rs +++ b/crates/bevy_derive/src/lib.rs @@ -5,7 +5,6 @@ mod bevy_main; mod bytes; mod enum_variant_meta; mod modules; -mod shader_defs; use bevy_macro_utils::{derive_label, BevyManifest}; use proc_macro::TokenStream; @@ -17,13 +16,6 @@ pub fn derive_bytes(input: TokenStream) -> TokenStream { bytes::derive_bytes(input) } -/// Derives the ShaderDefs trait. Each field must implement ShaderDef or this will fail. -/// You can ignore fields using `#[shader_defs(ignore)]`. -#[proc_macro_derive(ShaderDefs, attributes(shader_def))] -pub fn derive_shader_defs(input: TokenStream) -> TokenStream { - shader_defs::derive_shader_defs(input) -} - /// Generates a dynamic plugin entry point function for the given `Plugin` type. #[proc_macro_derive(DynamicPlugin)] pub fn derive_dynamic_plugin(input: TokenStream) -> TokenStream { diff --git a/crates/bevy_derive/src/modules.rs b/crates/bevy_derive/src/modules.rs index e54f09313e3560..ae0f3d945e83a3 100644 --- a/crates/bevy_derive/src/modules.rs +++ b/crates/bevy_derive/src/modules.rs @@ -1,3 +1,2 @@ pub const BEVY_CORE: &str = "bevy_core"; -pub const BEVY_RENDER: &str = "bevy_render"; pub const BEVY_UTILS: &str = "bevy_utils"; diff --git a/crates/bevy_derive/src/shader_defs.rs b/crates/bevy_derive/src/shader_defs.rs deleted file mode 100644 index 41da09eb43e84f..00000000000000 --- a/crates/bevy_derive/src/shader_defs.rs +++ /dev/null @@ -1,65 +0,0 @@ -use bevy_macro_utils::BevyManifest; -use inflector::Inflector; -use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Fields, Path}; - -static SHADER_DEF_ATTRIBUTE_NAME: &str = "shader_def"; - -pub fn derive_shader_defs(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as DeriveInput); - let bevy_render_path: Path = BevyManifest::default().get_path(crate::modules::BEVY_RENDER); - - let fields = match &ast.data { - Data::Struct(DataStruct { - fields: Fields::Named(fields), - .. - }) => &fields.named, - _ => panic!("Expected a struct with named fields."), - }; - - let shader_def_idents = fields - .iter() - .filter(|f| { - f.attrs - .iter() - .any(|a| *a.path.get_ident().as_ref().unwrap() == SHADER_DEF_ATTRIBUTE_NAME) - }) - .map(|f| f.ident.as_ref().unwrap()) - .collect::>(); - let struct_name = &ast.ident; - let struct_name_pascal_case = ast.ident.to_string().to_pascal_case(); - let shader_defs = shader_def_idents - .iter() - .map(|i| format!("{}_{}", struct_name_pascal_case, i).to_uppercase()); - - let shader_defs_len = shader_defs.len(); - let shader_def_indices = 0..shader_defs_len; - - let generics = ast.generics; - let (impl_generics, ty_generics, _where_clause) = generics.split_for_impl(); - - TokenStream::from(quote! { - impl #impl_generics #bevy_render_path::shader::ShaderDefs for #struct_name #ty_generics { - fn shader_defs_len(&self) -> usize { - #shader_defs_len - } - - fn get_shader_def(&self, index: usize) -> Option<&str> { - use #bevy_render_path::shader::ShaderDef; - match index { - #(#shader_def_indices => if self.#shader_def_idents.is_defined() { - Some(#shader_defs) - } else { - None - },)* - _ => None, - } - } - - fn iter_shader_defs(&self) -> #bevy_render_path::shader::ShaderDefIterator { - #bevy_render_path::shader::ShaderDefIterator::new(self) - } - } - }) -}