diff --git a/Cargo.lock b/Cargo.lock index 43a5c1b59..5bcdefb07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,7 +128,6 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "strum_macros", "syn", "tempfile", "unzip-n", @@ -381,15 +380,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "hermit-abi" version = "0.1.19" @@ -696,12 +686,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustversion" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" - [[package]] name = "ryu" version = "1.0.9" @@ -751,19 +735,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -[[package]] -name = "strum_macros" -version = "0.23.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn", -] - [[package]] name = "syn" version = "1.0.86" @@ -857,12 +828,6 @@ dependencies = [ "toml", ] -[[package]] -name = "unicode-segmentation" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" - [[package]] name = "unicode-width" version = "0.1.9" diff --git a/engine/Cargo.toml b/engine/Cargo.toml index 726cf5887..00aa4ddec 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -51,13 +51,11 @@ version_check = "0.9" aquamarine = "0.1" # docs tempfile = "3.1" once_cell = "1.7" -strum_macros = "0.23" serde_json = { version = "1.0", optional = true } [dependencies.syn] version = "1.0.39" -features = [ "full", "printing" ] -#features = [ "full", "printing", "extra-traits" ] +features = [ "full", "printing", "extra-traits" ] [package.metadata.docs.rs] features = ["build", "nightly"] diff --git a/engine/src/conversion/analysis/fun/function_wrapper.rs b/engine/src/conversion/analysis/fun/function_wrapper.rs index aaa68ad9a..6be34d299 100644 --- a/engine/src/conversion/analysis/fun/function_wrapper.rs +++ b/engine/src/conversion/analysis/fun/function_wrapper.rs @@ -67,7 +67,7 @@ impl RustConversionType { /// * Finally, the actual C++ API receives a `std::string` by value. /// The implementation here is distributed across this file, and /// `function_wrapper_rs` and `function_wrapper_cpp`. -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct TypeConversionPolicy { pub(crate) unwrapped_type: Type, pub(crate) cpp_conversion: CppConversionType, @@ -129,7 +129,7 @@ impl TypeConversionPolicy { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum CppFunctionBody { FunctionCall(Namespace, Ident), @@ -141,7 +141,7 @@ pub(crate) enum CppFunctionBody { Destructor(Namespace, Ident), } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum CppFunctionKind { Function, @@ -151,7 +151,7 @@ pub(crate) enum CppFunctionKind { SynthesizedConstructor, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct CppFunction { pub(crate) payload: CppFunctionBody, pub(crate) wrapper_function_name: Ident, diff --git a/engine/src/conversion/analysis/fun/mod.rs b/engine/src/conversion/analysis/fun/mod.rs index 80899f290..0bfc5438d 100644 --- a/engine/src/conversion/analysis/fun/mod.rs +++ b/engine/src/conversion/analysis/fun/mod.rs @@ -78,7 +78,7 @@ pub(crate) enum ReceiverMutability { Mutable, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum MethodKind { Normal(ReceiverMutability), Constructor, @@ -88,7 +88,7 @@ pub(crate) enum MethodKind { PureVirtual(ReceiverMutability), } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum TraitMethodKind { CopyConstructor, MoveConstructor, @@ -96,7 +96,7 @@ pub(crate) enum TraitMethodKind { Destructor, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct TraitMethodDetails { pub(crate) impl_for_specifics: TokenStream, pub(crate) trait_signature: TokenStream, @@ -113,7 +113,7 @@ pub(crate) struct TraitMethodDetails { pub(crate) trait_call_is_unsafe: bool, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum FnKind { Function, Method(QualifiedName, MethodKind), @@ -130,7 +130,7 @@ pub(crate) enum FnKind { /// Strategy for ensuring that the final, callable, Rust name /// is what the user originally expected. -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum RustRenameStrategy { /// cxx::bridge name matches user expectations @@ -140,14 +140,14 @@ pub(crate) enum RustRenameStrategy { RenameInOutputMod(Ident), } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum UnsafetyNeeded { None, JustBridge, Always, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct FnAnalysis { pub(crate) cxxbridge_name: Ident, pub(crate) rust_name: String, @@ -171,7 +171,7 @@ pub(crate) struct FnAnalysis { pub(crate) externally_callable: bool, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct ArgumentAnalysis { pub(crate) conversion: TypeConversionPolicy, pub(crate) name: Pat, @@ -199,6 +199,7 @@ impl Default for ReturnTypeAnalysis { } } +#[derive(Debug)] pub(crate) struct FnPhase; impl AnalysisPhase for FnPhase { diff --git a/engine/src/conversion/analysis/pod/mod.rs b/engine/src/conversion/analysis/pod/mod.rs index bd0d404d6..92b2572ab 100644 --- a/engine/src/conversion/analysis/pod/mod.rs +++ b/engine/src/conversion/analysis/pod/mod.rs @@ -37,6 +37,7 @@ use crate::{ use super::tdef::{TypedefAnalysis, TypedefPhase}; +#[derive(Debug)] pub(crate) struct PodAnalysis { pub(crate) kind: TypeKind, pub(crate) bases: HashSet, @@ -50,6 +51,7 @@ pub(crate) struct PodAnalysis { pub(crate) is_generic: bool, } +#[derive(Debug)] pub(crate) struct PodPhase; impl AnalysisPhase for PodPhase { diff --git a/engine/src/conversion/analysis/tdef.rs b/engine/src/conversion/analysis/tdef.rs index 1cef4fa47..77bcdfcff 100644 --- a/engine/src/conversion/analysis/tdef.rs +++ b/engine/src/conversion/analysis/tdef.rs @@ -29,6 +29,7 @@ use crate::{ types::QualifiedName, }; +#[derive(Debug)] pub(crate) struct TypedefAnalysis { pub(crate) kind: TypedefKind, pub(crate) deps: HashSet, @@ -36,6 +37,7 @@ pub(crate) struct TypedefAnalysis { /// Analysis phase where typedef analysis has been performed but no other /// analyses just yet. +#[derive(Debug)] pub(crate) struct TypedefPhase; impl AnalysisPhase for TypedefPhase { diff --git a/engine/src/conversion/api.rs b/engine/src/conversion/api.rs index 798c03f7e..a3e2c59ef 100644 --- a/engine/src/conversion/api.rs +++ b/engine/src/conversion/api.rs @@ -28,7 +28,7 @@ use super::{ ConvertError, }; -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] pub(crate) enum TypeKind { Pod, // trivial. Can be moved and copied in Rust. NonPod, // has destructor or non-trivial move constructors. Can only hold by UniquePtr @@ -54,6 +54,7 @@ pub(crate) enum CppVisibility { } /// Details about a C++ struct. +#[derive(Debug)] pub(crate) struct StructDetails { pub(crate) vis: CppVisibility, pub(crate) item: ItemStruct, @@ -62,7 +63,7 @@ pub(crate) struct StructDetails { } /// Layout of a type, equivalent to the same type in ir/layout.rs in bindgen -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct Layout { /// The size (in bytes) of this layout. pub(crate) size: usize, @@ -87,14 +88,14 @@ impl Parse for Layout { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum Virtualness { None, Virtual, PureVirtual, } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub(crate) enum CastMutability { ConstToConst, MutToConst, @@ -103,7 +104,7 @@ pub(crate) enum CastMutability { /// Indicates that this function didn't exist originally in the C++ /// but we've created it afresh. -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum Synthesis { MakeUnique, SubclassConstructor { @@ -120,7 +121,7 @@ pub(crate) enum Synthesis { /// Information about references (as opposed to pointers) to be found /// within the function signature. This is derived from bindgen annotations /// which is why it's not within `FuncToConvert::inputs` -#[derive(Default, Clone)] +#[derive(Default, Clone, Debug)] pub(crate) struct References { pub(crate) rvalue_ref_params: HashSet, pub(crate) ref_params: HashSet, @@ -138,7 +139,7 @@ impl References { } } -#[derive(Clone, Hash, Eq, PartialEq)] +#[derive(Clone, Hash, Eq, PartialEq, Debug)] pub(crate) enum SpecialMemberKind { DefaultConstructor, CopyConstructor, @@ -157,7 +158,7 @@ pub(crate) enum SpecialMemberKind { /// during normal bindgen parsing. If that happens, they'll create one /// of these structures, and typically fill in some of the /// `synthesized_*` members which are not filled in from bindgen. -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct FuncToConvert { pub(crate) ident: Ident, pub(crate) doc_attr: Option, @@ -192,6 +193,7 @@ pub(crate) trait AnalysisPhase { } /// No analysis has been applied to this API. +#[derive(Debug)] pub(crate) struct NullPhase; impl AnalysisPhase for NullPhase { @@ -200,7 +202,7 @@ impl AnalysisPhase for NullPhase { type FunAnalysis = (); } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum TypedefKind { Use(ItemUse), Type(ItemType), @@ -311,7 +313,6 @@ impl SubclassName { } } -#[derive(strum_macros::Display)] /// Different types of API we might encounter. /// /// This type is parameterized over an `ApiAnalysis`. This is any additional @@ -321,12 +322,7 @@ impl SubclassName { /// This is not as high-level as the equivalent types in `cxx` or `bindgen`, /// because sometimes we pass on the `bindgen` output directly in the /// Rust codegen output. -/// -/// This derives from [strum_macros::Display] because we want to be -/// able to debug-print the enum discriminant without worrying about -/// the fact that their payloads may not be `Debug` or `Display`. -/// (Specifically, allowing `syn` Types to be `Debug` requires -/// enabling syn's `extra-traits` feature which increases compile time.) +#[derive(Debug)] pub(crate) enum Api { /// A forward declared type for which no definition is available. ForwardDeclaration { name: ApiName }, @@ -405,6 +401,7 @@ pub(crate) enum Api { }, } +#[derive(Debug)] pub(crate) struct RustSubclassFnDetails { pub(crate) params: Punctuated, pub(crate) ret: ReturnType, @@ -476,12 +473,6 @@ impl Api { } } -impl std::fmt::Debug for Api { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?} (kind={})", self.name_info(), self) - } -} - pub(crate) type UnanalyzedApi = Api; impl Api { diff --git a/engine/src/conversion/convert_error.rs b/engine/src/conversion/convert_error.rs index d4a751e21..c87d32a30 100644 --- a/engine/src/conversion/convert_error.rs +++ b/engine/src/conversion/convert_error.rs @@ -117,7 +117,7 @@ impl Display for ConvertError { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) enum ErrorContext { Item(Ident), Method { self_ty: Ident, method: Ident }, diff --git a/engine/src/conversion/mod.rs b/engine/src/conversion/mod.rs index 227d1fafb..ed1dd1ced 100644 --- a/engine/src/conversion/mod.rs +++ b/engine/src/conversion/mod.rs @@ -24,6 +24,8 @@ mod error_reporter; mod parse; mod utilities; +use std::fmt::Debug; + use analysis::fun::FnAnalyzer; use autocxx_parser::IncludeCppConfig; pub(crate) use codegen_cpp::CppCodeGenerator; @@ -82,7 +84,12 @@ impl<'a> BridgeConverter<'a> { } } - fn dump_apis(label: &str, apis: &[Api]) { + fn dump_apis(label: &str, apis: &[Api]) + where + T::FunAnalysis: Debug, + T::StructAnalysis: Debug, + T::TypedefAnalysis: Debug, + { if LOG_APIS { log::info!( "APIs after {}:\n{}",