Skip to content

Commit

Permalink
Eliminate "Use" type.
Browse files Browse the repository at this point in the history
This was no longer necessary or sensible.
  • Loading branch information
adetaylor committed Feb 26, 2025
1 parent 7547cbc commit dd29343
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 136 deletions.
41 changes: 15 additions & 26 deletions engine/src/conversion/codegen_rs/fun_codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use super::{
function_wrapper_rs::RustParamConversion,
maybe_unsafes_to_tokens,
unqualify::{unqualify_params_minisyn, unqualify_ret_type},
ImplBlockDetails, MaybeUnsafeStmt, RsCodegenResult, TraitImplBlockDetails, Use,
utils::generate_cxx_use_stmt,
ImplBlockDetails, MaybeUnsafeStmt, RsCodegenResult, TraitImplBlockDetails,
};
use crate::{
conversion::{
Expand All @@ -34,7 +35,7 @@ use crate::{
api::UnsafetyNeeded,
},
minisyn::{minisynize_vec, FnArg},
types::{Namespace, QualifiedName},
types::QualifiedName,
};
use crate::{
conversion::{api::FuncToConvert, codegen_rs::lifetime::add_explicit_lifetime_if_necessary},
Expand Down Expand Up @@ -85,7 +86,7 @@ impl UnsafetyNeeded {
}

pub(super) fn gen_function(
ns: &Namespace,
name: &QualifiedName,
fun: FuncToConvert,
analysis: FnAnalysis,
non_pod_types: &HashSet<QualifiedName>,
Expand Down Expand Up @@ -132,7 +133,7 @@ pub(super) fn gen_function(
&ret_conversion,
);

let mut materializations = Vec::new();
let mut output_mod_items = Vec::new();

if analysis.rust_wrapper_needed {
match kind {
Expand Down Expand Up @@ -160,27 +161,15 @@ pub(super) fn gen_function(
}
_ => {
// Generate plain old function
materializations.push(Use::Custom(Box::new(fn_generator.generate_function_impl())));
output_mod_items.push(fn_generator.generate_function_impl());
}
}
}

// This and the 'if let' can be simplified. TODO.
let materialization = match kind {
FnKind::Method { .. } | FnKind::TraitMethod { .. } => None,
FnKind::Function => match analysis.rust_rename_strategy {
_ if analysis.rust_wrapper_needed => {
assert!(!materializations.is_empty());
None
}
RustRenameStrategy::RenameInOutputMod(ref alias) => {
Some(Use::UsedFromCxxBridgeWithAlias(alias.clone().into()))
}
_ => Some(Use::UsedFromCxxBridge),
},
};
if let Some(materialization) = materialization {
materializations.push(materialization);
} else if matches!(kind, FnKind::Function) {
let alias = match analysis.rust_rename_strategy {
RustRenameStrategy::RenameInOutputMod(ref alias) => Some(&alias.0),
_ => None,
};
output_mod_items.push(generate_cxx_use_stmt(name, alias));
}

if let Some(cpp_call_name) = cpp_call_name {
Expand All @@ -204,10 +193,10 @@ pub(super) fn gen_function(
let ret_type = unqualify_ret_type(ret_type.into_owned());
// And we need to make an attribute for the namespace that the function
// itself is in.
let namespace_attr = if ns.is_empty() || wrapper_function_needed {
let namespace_attr = if name.get_namespace().is_empty() || wrapper_function_needed {
Vec::new()
} else {
let namespace_string = ns.to_string();
let namespace_string = name.get_namespace().to_string();
Attribute::parse_outer
.parse2(quote!(
#[namespace = #namespace_string]
Expand All @@ -226,7 +215,7 @@ pub(super) fn gen_function(
extern_c_mod_items: vec![extern_c_mod_item],
impl_entry,
trait_impl_entry,
materializations,
output_mod_items,
..Default::default()
}
}
Expand Down
Loading

0 comments on commit dd29343

Please sign in to comment.