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

Remove strum_macros and use full #[derive(Debug)] #812

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
8 changes: 4 additions & 4 deletions engine/src/conversion/analysis/fun/function_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -129,7 +129,7 @@ impl TypeConversionPolicy {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]

pub(crate) enum CppFunctionBody {
FunctionCall(Namespace, Ident),
Expand All @@ -141,7 +141,7 @@ pub(crate) enum CppFunctionBody {
Destructor(Namespace, Ident),
}

#[derive(Clone)]
#[derive(Clone, Debug)]

pub(crate) enum CppFunctionKind {
Function,
Expand All @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions engine/src/conversion/analysis/fun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) enum ReceiverMutability {
Mutable,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) enum MethodKind {
Normal(ReceiverMutability),
Constructor,
Expand All @@ -88,15 +88,15 @@ pub(crate) enum MethodKind {
PureVirtual(ReceiverMutability),
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) enum TraitMethodKind {
CopyConstructor,
MoveConstructor,
Cast,
Destructor,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct TraitMethodDetails {
pub(crate) impl_for_specifics: TokenStream,
pub(crate) trait_signature: TokenStream,
Expand All @@ -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),
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -199,6 +199,7 @@ impl Default for ReturnTypeAnalysis {
}
}

#[derive(Debug)]
pub(crate) struct FnPhase;

impl AnalysisPhase for FnPhase {
Expand Down
2 changes: 2 additions & 0 deletions engine/src/conversion/analysis/pod/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<QualifiedName>,
Expand All @@ -50,6 +51,7 @@ pub(crate) struct PodAnalysis {
pub(crate) is_generic: bool,
}

#[derive(Debug)]
pub(crate) struct PodPhase;

impl AnalysisPhase for PodPhase {
Expand Down
2 changes: 2 additions & 0 deletions engine/src/conversion/analysis/tdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ use crate::{
types::QualifiedName,
};

#[derive(Debug)]
pub(crate) struct TypedefAnalysis {
pub(crate) kind: TypedefKind,
pub(crate) deps: HashSet<QualifiedName>,
}

/// Analysis phase where typedef analysis has been performed but no other
/// analyses just yet.
#[derive(Debug)]
pub(crate) struct TypedefPhase;

impl AnalysisPhase for TypedefPhase {
Expand Down
35 changes: 13 additions & 22 deletions engine/src/conversion/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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<Ident>,
pub(crate) ref_params: HashSet<Ident>,
Expand All @@ -138,7 +139,7 @@ impl References {
}
}

#[derive(Clone, Hash, Eq, PartialEq)]
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
pub(crate) enum SpecialMemberKind {
DefaultConstructor,
CopyConstructor,
Expand All @@ -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<Attribute>,
Expand Down Expand Up @@ -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 {
Expand All @@ -200,7 +202,7 @@ impl AnalysisPhase for NullPhase {
type FunAnalysis = ();
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) enum TypedefKind {
Use(ItemUse),
Type(ItemType),
Expand Down Expand Up @@ -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
Expand All @@ -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<T: AnalysisPhase> {
/// A forward declared type for which no definition is available.
ForwardDeclaration { name: ApiName },
Expand Down Expand Up @@ -405,6 +401,7 @@ pub(crate) enum Api<T: AnalysisPhase> {
},
}

#[derive(Debug)]
pub(crate) struct RustSubclassFnDetails {
pub(crate) params: Punctuated<FnArg, Comma>,
pub(crate) ret: ReturnType,
Expand Down Expand Up @@ -476,12 +473,6 @@ impl<T: AnalysisPhase> Api<T> {
}
}

impl<T: AnalysisPhase> std::fmt::Debug for Api<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?} (kind={})", self.name_info(), self)
}
}

pub(crate) type UnanalyzedApi = Api<NullPhase>;

impl<T: AnalysisPhase> Api<T> {
Expand Down
2 changes: 1 addition & 1 deletion engine/src/conversion/convert_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Loading