Skip to content

Commit

Permalink
Newtype wrapper for more concise syn debug output.
Browse files Browse the repository at this point in the history
This improves our internal debug logging substantially, so that all details of
each API are recorded at every stage of conversion. Previously this was
impractical due to the extreme verbosity of syn's Debug implementation. This
change wraps every stored syn type in a newtype wrapper which uses to_tokens()
to produce more concise Debug output.
  • Loading branch information
adetaylor committed Jun 28, 2023
1 parent 907b2ef commit c3cdbcb
Show file tree
Hide file tree
Showing 26 changed files with 380 additions and 228 deletions.
20 changes: 0 additions & 20 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ version_check = "0.9"
aquamarine = "0.1" # docs
tempfile = "3.4"
once_cell = "1.7"
strum_macros = "0.24"
serde_json = { version = "1.0", optional = true }
miette = "5"
thiserror = "1"
Expand Down
5 changes: 3 additions & 2 deletions engine/src/conversion/analysis/allocators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
},
apivec::ApiVec,
},
minisyn::minisynize_punctuated,
types::{make_ident, QualifiedName},
};

Expand Down Expand Up @@ -76,8 +77,8 @@ fn create_alloc_and_free(ty_name: QualifiedName) -> impl Iterator<Item = Api<Pod
fun: Box::new(FuncToConvert {
ident,
doc_attrs: Vec::new(),
inputs,
output,
inputs: minisynize_punctuated(inputs),
output: output.into(),
vis: parse_quote! { pub },
virtualness: crate::conversion::api::Virtualness::None,
cpp_vis: CppVisibility::Public,
Expand Down
3 changes: 2 additions & 1 deletion engine/src/conversion/analysis/casts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::minisyn::FnArg;
use itertools::Itertools;
use quote::quote;
use syn::{parse_quote, FnArg};
use syn::parse_quote;

use crate::{
conversion::{
Expand Down
2 changes: 1 addition & 1 deletion engine/src/conversion/analysis/ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use indexmap::map::IndexMap as HashMap;

use syn::Ident;
use crate::minisyn::Ident;

use crate::conversion::api::ApiName;
use crate::conversion::apivec::ApiVec;
Expand Down
6 changes: 0 additions & 6 deletions engine/src/conversion/analysis/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use itertools::Itertools;

use crate::{
conversion::api::{Api, TypeKind},
types::QualifiedName,
Expand All @@ -22,10 +20,6 @@ use super::{
pub(crate) trait HasDependencies {
fn name(&self) -> &QualifiedName;
fn deps(&self) -> Box<dyn Iterator<Item = &QualifiedName> + '_>;

fn format_deps(&self) -> String {
self.deps().join(",")
}
}

impl HasDependencies for Api<FnPrePhase1> {
Expand Down
25 changes: 13 additions & 12 deletions engine/src/conversion/analysis/fun/function_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::minisyn::Ident;
use crate::{
conversion::{api::SubclassName, type_helpers::extract_pinned_mutable_reference_type},
types::{Namespace, QualifiedName},
};
use quote::ToTokens;
use syn::{parse_quote, Ident, Type, TypeReference};
use syn::{parse_quote, Type, TypeReference};

#[derive(Clone, Debug)]
pub(crate) enum CppConversionType {
Expand Down Expand Up @@ -85,9 +86,9 @@ impl RustConversionType {
/// variant params. That would remove the possibility of various runtime
/// panics by enforcing (for example) that conversion from a pointer always
/// has a Type::Ptr.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct TypeConversionPolicy {
unwrapped_type: Type,
unwrapped_type: crate::minisyn::Type,
pub(crate) cpp_conversion: CppConversionType,
pub(crate) rust_conversion: RustConversionType,
}
Expand All @@ -103,7 +104,7 @@ impl TypeConversionPolicy {
rust_conversion: RustConversionType,
) -> Self {
Self {
unwrapped_type: ty,
unwrapped_type: ty.into(),
cpp_conversion,
rust_conversion,
}
Expand Down Expand Up @@ -140,15 +141,15 @@ impl TypeConversionPolicy {

pub(crate) fn new_to_unique_ptr(ty: Type) -> Self {
TypeConversionPolicy {
unwrapped_type: ty,
unwrapped_type: ty.into(),
cpp_conversion: CppConversionType::FromValueToUniquePtr,
rust_conversion: RustConversionType::None,
}
}

pub(crate) fn new_for_placement_return(ty: Type) -> Self {
TypeConversionPolicy {
unwrapped_type: ty,
unwrapped_type: ty.into(),
cpp_conversion: CppConversionType::FromReturnValueToPlacementPtr,
// Rust conversion is marked as none here, since this policy
// will be applied to the return value, and the Rust-side
Expand All @@ -164,7 +165,7 @@ impl TypeConversionPolicy {
pub(crate) fn unconverted_rust_type(&self) -> Type {
match self.cpp_conversion {
CppConversionType::FromValueToUniquePtr => self.make_unique_ptr_type(),
_ => self.unwrapped_type.clone(),
_ => self.unwrapped_type.clone().into(),
}
}

Expand All @@ -177,7 +178,7 @@ impl TypeConversionPolicy {
*mut #innerty
}
}
_ => self.unwrapped_type.clone(),
_ => self.unwrapped_type.clone().into(),
}
}

Expand Down Expand Up @@ -229,7 +230,7 @@ impl TypeConversionPolicy {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) enum CppFunctionBody {
FunctionCall(Namespace, Ident),
StaticMethodCall(Namespace, Ident, Ident),
Expand All @@ -241,7 +242,7 @@ pub(crate) enum CppFunctionBody {
FreeUninitialized(QualifiedName),
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) enum CppFunctionKind {
Function,
Method,
Expand All @@ -250,10 +251,10 @@ pub(crate) enum CppFunctionKind {
SynthesizedConstructor,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub(crate) struct CppFunction {
pub(crate) payload: CppFunctionBody,
pub(crate) wrapper_function_name: Ident,
pub(crate) wrapper_function_name: crate::minisyn::Ident,
pub(crate) original_cpp_name: String,
pub(crate) return_conversion: Option<TypeConversionPolicy>,
pub(crate) argument_conversion: Vec<TypeConversionPolicy>,
Expand Down
Loading

0 comments on commit c3cdbcb

Please sign in to comment.