From 4ee1a8bcc83128a20e59e0f2e8e816ebd1a8a615 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan <me@rreverser.com> Date: Wed, 15 Nov 2017 22:50:13 +0000 Subject: [PATCH] Remove obsolete template specialization --- README.md | 2 -- src/bindgen/bindings.rs | 40 ++-------------------------- src/bindgen/builder.rs | 6 ----- src/bindgen/config.rs | 3 --- src/bindgen/library.rs | 17 ++---------- src/bindgen/monomorph.rs | 52 ------------------------------------- tests/rust/monomorph-1.toml | 2 -- tests/rust/monomorph-3.toml | 2 -- 8 files changed, 4 insertions(+), 120 deletions(-) delete mode 100644 tests/rust/monomorph-1.toml delete mode 100644 tests/rust/monomorph-3.toml diff --git a/README.md b/README.md index 64f011d..dab0371 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,6 @@ rename_args = "[None|GeckoCase|LowerCase|UpperCase|PascalCase|CamelCase|SnakeCas [struct] # A rule to use to rename field names rename_fields = "[None|GeckoCase|LowerCase|UpperCase|PascalCase|CamelCase|SnakeCase|ScreamingSnakeCase|QualifiedScreamingSnakeCase]" -# Whether to generate helper template specialization for generics -generic_template_specialization = true # Whether to derive an operator== for all structs derive_eq = false # Whether to derive an operator!= for all structs diff --git a/src/bindgen/bindings.rs b/src/bindgen/bindings.rs index 74bf4c9..4487b7f 100644 --- a/src/bindgen/bindings.rs +++ b/src/bindgen/bindings.rs @@ -9,8 +9,7 @@ use std::fs; use bindgen::config::{Config, Language}; use bindgen::ir::{Constant, ItemContainer, Function, Static}; -use bindgen::monomorph::TemplateSpecialization; -use bindgen::writer::{ListType, Source, SourceWriter}; +use bindgen::writer::{Source, SourceWriter}; /// A bindings header that can be written. pub struct Bindings { @@ -19,7 +18,6 @@ pub struct Bindings { constants: Vec<Constant>, items: Vec<ItemContainer>, functions: Vec<Function>, - template_specializations: Vec<TemplateSpecialization>, } impl Bindings { @@ -27,15 +25,13 @@ impl Bindings { constants: Vec<Constant>, globals: Vec<Static>, items: Vec<ItemContainer>, - functions: Vec<Function>, - template_specializations: Vec<TemplateSpecialization>) -> Bindings { + functions: Vec<Function>) -> Bindings { Bindings { config: config, globals: globals, constants: constants, items: items, functions: functions, - template_specializations: template_specializations, } } @@ -152,38 +148,6 @@ impl Bindings { out.new_line(); } - if self.config.structure.generic_template_specialization && - self.config.language == Language::Cxx { - self.open_namespaces(&mut out); - for template in &self.template_specializations { - out.new_line_if_not_start(); - out.write("template<"); - for (i, param) in template.generic.generic_params.iter().enumerate() { - if i != 0 { - out.write(", ") - } - write!(out, "typename {}", param); - } - out.write(">"); - out.new_line(); - write!(out, "struct {};", template.generic.name); - out.new_line(); - - for &(ref monomorph_path, ref generic_values) in &template.monomorphs { - out.new_line(); - out.write("template<>"); - out.new_line(); - write!(out, "struct {}<", template.generic.name); - out.write_horizontal_source_list(generic_values, ListType::Join(", ")); - write!(out, "> : public {}", monomorph_path); - out.open_brace(); - out.close_brace(true); - out.new_line(); - } - } - self.close_namespaces(&mut out); - } - if let Some(ref f) = self.config.autogen_warning { out.new_line_if_not_start(); write!(out, "{}", f); diff --git a/src/bindgen/builder.rs b/src/bindgen/builder.rs index 5dc5654..57de111 100644 --- a/src/bindgen/builder.rs +++ b/src/bindgen/builder.rs @@ -121,12 +121,6 @@ impl Builder { self } - #[allow(unused)] - pub fn with_generic_template_specialization(mut self, generic_template_specialization: bool) -> Builder { - self.config.structure.generic_template_specialization = generic_template_specialization; - self - } - #[allow(unused)] pub fn with_documentation(mut self, documentation: bool) -> Builder { self.config.documentation = documentation; diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs index a711471..c3c2661 100644 --- a/src/bindgen/config.rs +++ b/src/bindgen/config.rs @@ -146,8 +146,6 @@ impl FunctionConfig { pub struct StructConfig { /// The rename rule to apply to the name of struct fields pub rename_fields: Option<RenameRule>, - /// Whether to generate helper template specialization for generics - pub generic_template_specialization: bool, /// Whether to generate a piecewise equality operator pub derive_eq: bool, /// Whether to generate a piecewise inequality operator @@ -166,7 +164,6 @@ impl Default for StructConfig { fn default() -> StructConfig { StructConfig { rename_fields: None, - generic_template_specialization: true, derive_eq: false, derive_neq: false, derive_lt: false, diff --git a/src/bindgen/library.rs b/src/bindgen/library.rs index 3e8a60d..af534ea 100644 --- a/src/bindgen/library.rs +++ b/src/bindgen/library.rs @@ -10,7 +10,7 @@ use bindgen::config::{Config, Language}; use bindgen::dependencies::Dependencies; use bindgen::ir::{Constant, Enum, Function, ItemContainer, ItemMap, Item}; use bindgen::ir::{OpaqueItem, Path, Specialization, Static, Struct, Typedef, Union}; -use bindgen::monomorph::{Monomorphs, TemplateSpecialization}; +use bindgen::monomorph::Monomorphs; #[derive(Debug, Clone)] pub struct Library { @@ -24,7 +24,6 @@ pub struct Library { typedefs: ItemMap<Typedef>, specializations: ItemMap<Specialization>, functions: Vec<Function>, - template_specializations: Vec<TemplateSpecialization>, } impl Library { @@ -49,7 +48,6 @@ impl Library { typedefs: typedefs, specializations: specializations, functions: functions, - template_specializations: Vec::new(), } } @@ -74,27 +72,18 @@ impl Library { global.add_dependencies(&self, &mut dependencies); }); - if self.config.structure.generic_template_specialization && - self.config.language == Language::Cxx { - for template_specialization in &self.template_specializations { - template_specialization.add_dependencies(&self, &mut dependencies); - } - } - dependencies.sort(); let items = dependencies.order; let constants = self.constants.to_vec(); let globals = self.globals.to_vec(); let functions = mem::replace(&mut self.functions, Vec::new()); - let template_specializations = mem::replace(&mut self.template_specializations, Vec::new()); Ok(Bindings::new(self.config.clone(), constants, globals, items, - functions, - template_specializations)) + functions)) } pub fn get_items(&self, p: &Path) -> Option<Vec<ItemContainer>> { @@ -327,7 +316,5 @@ impl Library { for x in &mut self.functions { x.mangle_paths(&monomorphs); } - - self.template_specializations = monomorphs.drain_template_specializations(); } } diff --git a/src/bindgen/monomorph.rs b/src/bindgen/monomorph.rs index 1f05fd7..ea70009 100644 --- a/src/bindgen/monomorph.rs +++ b/src/bindgen/monomorph.rs @@ -3,35 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::collections::HashMap; -use std::collections::BTreeMap; use std::mem; -use bindgen::dependencies::Dependencies; use bindgen::ir::{GenericPath, OpaqueItem, Path, Struct, Type, Union}; -use bindgen::library::Library; - -#[derive(Clone, Debug)] -pub struct TemplateSpecialization { - pub generic: Struct, - pub monomorphs: Vec<(Path, Vec<Type>)>, -} - -impl TemplateSpecialization { - fn new(generic: Struct) -> TemplateSpecialization { - TemplateSpecialization { - generic: generic, - monomorphs: Vec::new(), - } - } - - pub fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { - for &(_, ref generic_values) in &self.monomorphs { - for generic_value in generic_values { - generic_value.add_dependencies(library, out); - } - } - } -} #[derive(Clone, Debug)] pub struct Monomorphs { @@ -39,7 +13,6 @@ pub struct Monomorphs { opaques: Vec<OpaqueItem>, structs: Vec<Struct>, unions: Vec<Union>, - templates: BTreeMap<Path, TemplateSpecialization>, } impl Monomorphs { @@ -49,7 +22,6 @@ impl Monomorphs { opaques: Vec::new(), structs: Vec::new(), unions: Vec::new(), - templates: BTreeMap::new(), } } @@ -61,12 +33,6 @@ impl Monomorphs { generic: &Struct, monomorph: Struct, parameters: Vec<Type>) { - // Add extra information for struct instantiations so we can use template - // specialization to make using the type more ergonomic. - self.templates.entry(generic.name.clone()) - .or_insert_with(|| TemplateSpecialization::new(generic.clone())) - .monomorphs.push((monomorph.name.clone(), parameters.clone())); - let replacement_path = GenericPath::new(generic.name.clone(), parameters); debug_assert!(generic.generic_params.len() > 0); @@ -117,22 +83,4 @@ impl Monomorphs { pub fn drain_unions(&mut self) -> Vec<Union> { mem::replace(&mut self.unions, Vec::new()) } - - pub fn drain_template_specializations(&mut self) -> Vec<TemplateSpecialization> { - let mut not_mangled = mem::replace(&mut self.templates, BTreeMap::new()); - let mut mangled = Vec::new(); - - // The generic type arguments in `templates` need to be mangled - for (_, template) in &mut not_mangled { - for &mut (_, ref mut generic_values) in &mut template.monomorphs { - for generic_value in generic_values { - generic_value.mangle_paths(&self); - } - } - - mangled.push(template.clone()); - } - - mangled - } } diff --git a/tests/rust/monomorph-1.toml b/tests/rust/monomorph-1.toml deleted file mode 100644 index 02f1ccc..0000000 --- a/tests/rust/monomorph-1.toml +++ /dev/null @@ -1,2 +0,0 @@ -[struct] -generic_template_specialization = true diff --git a/tests/rust/monomorph-3.toml b/tests/rust/monomorph-3.toml deleted file mode 100644 index 02f1ccc..0000000 --- a/tests/rust/monomorph-3.toml +++ /dev/null @@ -1,2 +0,0 @@ -[struct] -generic_template_specialization = true -- GitLab