Skip to content

Commit 55c1c60

Browse files
authored
Merge pull request #1441 from google/minisyn-inputs
Minisyn to wrap inputs
2 parents ce490d9 + ff0945c commit 55c1c60

File tree

5 files changed

+54
-31
lines changed

5 files changed

+54
-31
lines changed

engine/src/conversion/analysis/abstract_types.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// except according to those terms.
88

99
use indexmap::map::IndexMap as HashMap;
10-
use syn::{punctuated::Punctuated, token::Comma, FnArg};
10+
use syn::{punctuated::Punctuated, token::Comma};
1111

1212
use super::{
1313
fun::{
@@ -16,11 +16,14 @@ use super::{
1616
},
1717
pod::PodAnalysis,
1818
};
19-
use crate::conversion::{
20-
analysis::{depth_first::fields_and_bases_first, fun::ReceiverMutability},
21-
api::{ApiName, TypeKind},
22-
error_reporter::{convert_apis, convert_item_apis},
23-
ConvertErrorFromCpp, CppEffectiveName,
19+
use crate::{
20+
conversion::{
21+
analysis::{depth_first::fields_and_bases_first, fun::ReceiverMutability},
22+
api::{ApiName, TypeKind},
23+
error_reporter::{convert_apis, convert_item_apis},
24+
ConvertErrorFromCpp, CppEffectiveName,
25+
},
26+
minisyn::FnArg,
2427
};
2528
use crate::{
2629
conversion::{api::Api, apivec::ApiVec},
@@ -47,7 +50,7 @@ impl Signature {
4750
.iter()
4851
.skip(1) // skip `this` implicit argument
4952
.filter_map(|p| {
50-
if let FnArg::Typed(t) = p {
53+
if let syn::FnArg::Typed(t) = &p.0 {
5154
Some((*t.ty).clone())
5255
} else {
5356
None

engine/src/conversion/analysis/fun/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::{
2929
CppEffectiveName, CppOriginalName,
3030
},
3131
known_types::known_types,
32-
minisyn::minisynize_punctuated,
32+
minisyn::{minisynize_punctuated, FnArg},
3333
types::validate_ident_ok_for_rust,
3434
};
3535
use indexmap::map::IndexMap as HashMap;
@@ -41,8 +41,8 @@ use itertools::Itertools;
4141
use proc_macro2::Span;
4242
use quote::quote;
4343
use syn::{
44-
parse_quote, punctuated::Punctuated, token::Comma, FnArg, Ident, Pat, PatType, ReturnType,
45-
Type, TypePath, TypePtr, TypeReference, Visibility,
44+
parse_quote, punctuated::Punctuated, token::Comma, Ident, Pat, PatType, ReturnType, Type,
45+
TypePath, TypePtr, TypeReference, Visibility,
4646
};
4747

4848
use crate::{
@@ -1673,8 +1673,8 @@ impl<'a> FnAnalyzer<'a> {
16731673
sophistication: TypeConversionSophistication,
16741674
construct_into_self: bool,
16751675
) -> Result<(FnArg, ArgumentAnalysis), ConvertErrorFromCpp> {
1676-
Ok(match arg {
1677-
FnArg::Typed(pt) => {
1676+
Ok(match &arg.0 {
1677+
syn::FnArg::Typed(pt) => {
16781678
let mut pt = pt.clone();
16791679
let mut self_type = None;
16801680
let old_pat = *pt.pat;
@@ -1762,7 +1762,7 @@ impl<'a> FnAnalyzer<'a> {
17621762
UnsafetyNeeded::None
17631763
};
17641764
(
1765-
FnArg::Typed(pt),
1765+
syn::FnArg::Typed(pt).into(),
17661766
ArgumentAnalysis {
17671767
self_type,
17681768
name: new_pat.into(),
@@ -2367,10 +2367,10 @@ impl HasFieldsAndBases for Api<FnPrePhase2> {
23672367
}
23682368

23692369
/// Stringify a function argument for diagnostics
2370-
fn describe_arg(arg: &FnArg) -> String {
2370+
fn describe_arg(arg: &syn::FnArg) -> String {
23712371
match arg {
2372-
FnArg::Receiver(_) => "the function receiver (this/self paramter)".into(),
2373-
FnArg::Typed(PatType { pat, .. }) => match pat.as_ref() {
2372+
syn::FnArg::Receiver(_) => "the function receiver (this/self paramter)".into(),
2373+
syn::FnArg::Typed(PatType { pat, .. }) => match pat.as_ref() {
23742374
Pat::Ident(pti) => pti.ident.to_string(),
23752375
_ => "another argument we don't know how to describe".into(),
23762376
},

engine/src/conversion/codegen_rs/fun_codegen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ use syn::{
1616
parse_quote,
1717
punctuated::Punctuated,
1818
token::{Comma, Unsafe},
19-
Attribute, FnArg, ForeignItem, Ident, ImplItem, Item, ReturnType,
19+
Attribute, ForeignItem, Ident, ImplItem, Item, ReturnType,
2020
};
2121

2222
use super::{
2323
function_wrapper_rs::RustParamConversion,
2424
maybe_unsafes_to_tokens,
25-
unqualify::{unqualify_params, unqualify_ret_type},
25+
unqualify::{unqualify_params_minisyn, unqualify_ret_type},
2626
ImplBlockDetails, MaybeUnsafeStmt, RsCodegenResult, TraitImplBlockDetails, Use,
2727
};
2828
use crate::{
@@ -33,7 +33,7 @@ use crate::{
3333
},
3434
api::UnsafetyNeeded,
3535
},
36-
minisyn::minisynize_vec,
36+
minisyn::{minisynize_vec, FnArg},
3737
types::{Namespace, QualifiedName},
3838
};
3939
use crate::{
@@ -193,7 +193,7 @@ pub(super) fn gen_function(
193193
// well-known types should be unqualified already (e.g. just UniquePtr)
194194
// and the following code will act to unqualify only those types
195195
// which the user has declared.
196-
let params = unqualify_params(params);
196+
let params = unqualify_params_minisyn(params);
197197
let ret_type = unqualify_ret_type(ret_type.into_owned());
198198
// And we need to make an attribute for the namespace that the function
199199
// itself is in.

engine/src/conversion/codegen_rs/lifetime.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ use crate::{
1010
function_wrapper::{RustConversionType, TypeConversionPolicy},
1111
ArgumentAnalysis, ReceiverMutability,
1212
},
13+
minisyn::FnArg,
1314
types::QualifiedName,
1415
};
1516
use indexmap::set::IndexSet as HashSet;
1617
use proc_macro2::TokenStream;
1718
use quote::{quote, ToTokens};
1819
use std::borrow::Cow;
1920
use syn::{
20-
parse_quote, punctuated::Punctuated, token::Comma, FnArg, GenericArgument, PatType, Path,
21-
PathSegment, ReturnType, Type, TypePath, TypeReference,
21+
parse_quote, punctuated::Punctuated, token::Comma, GenericArgument, PatType, Path, PathSegment,
22+
ReturnType, Type, TypePath, TypeReference,
2223
};
2324

2425
/// Function which can add explicit lifetime parameters to function signatures
@@ -116,8 +117,9 @@ pub(crate) fn add_explicit_lifetime_if_necessary<'r>(
116117
}
117118
None => (None, params, ret_type),
118119
Some(new_return_type) => {
119-
for FnArg::Typed(PatType { ty, .. }) | FnArg::Receiver(syn::Receiver { ty, .. }) in
120-
params.iter_mut()
120+
for syn::FnArg::Typed(PatType { ty, .. })
121+
| syn::FnArg::Receiver(syn::Receiver { ty, .. }) in
122+
params.iter_mut().map(|minifnarg| &mut minifnarg.0)
121123
{
122124
match ty.as_mut() {
123125
Type::Path(TypePath {
@@ -139,8 +141,8 @@ fn reference_parameter_is_non_pod_reference(
139141
params: &Punctuated<FnArg, Comma>,
140142
non_pod_types: &HashSet<QualifiedName>,
141143
) -> bool {
142-
params.iter().any(|param| match param {
143-
FnArg::Typed(PatType { ty, .. }) => match ty.as_ref() {
144+
params.iter().any(|param| match &param.0 {
145+
syn::FnArg::Typed(PatType { ty, .. }) => match ty.as_ref() {
144146
Type::Reference(TypeReference { elem, .. }) => match elem.as_ref() {
145147
Type::Path(typ) => {
146148
let qn = QualifiedName::from_type_path(typ);

engine/src/conversion/codegen_rs/unqualify.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
// except according to those terms.
88

99
use syn::{
10-
parse_quote, punctuated::Punctuated, FnArg, GenericArgument, PathArguments, PathSegment,
11-
ReturnType, Token, Type, TypePath,
10+
parse_quote, punctuated::Punctuated, GenericArgument, PathArguments, PathSegment, ReturnType,
11+
Token, Type, TypePath,
1212
};
1313

14+
use crate::minisyn::FnArg;
15+
1416
fn unqualify_type_path(typ: TypePath) -> TypePath {
1517
// If we've still got more than one
1618
// path segment then this is referring to a type within
@@ -76,15 +78,31 @@ pub(crate) fn unqualify_ret_type(ret_type: ReturnType) -> ReturnType {
7678
}
7779
}
7880

79-
pub(crate) fn unqualify_params(
81+
pub(crate) fn unqualify_params_minisyn(
8082
params: Punctuated<FnArg, Token![,]>,
8183
) -> Punctuated<FnArg, Token![,]> {
84+
params
85+
.into_iter()
86+
.map(|p| match p.0 {
87+
syn::FnArg::Typed(mut pt) => {
88+
pt.ty = unqualify_boxed_type(pt.ty);
89+
syn::FnArg::Typed(pt)
90+
}
91+
_ => p.0,
92+
})
93+
.map(FnArg)
94+
.collect()
95+
}
96+
97+
pub(crate) fn unqualify_params(
98+
params: Punctuated<syn::FnArg, Token![,]>,
99+
) -> Punctuated<syn::FnArg, Token![,]> {
82100
params
83101
.into_iter()
84102
.map(|p| match p {
85-
FnArg::Typed(mut pt) => {
103+
syn::FnArg::Typed(mut pt) => {
86104
pt.ty = unqualify_boxed_type(pt.ty);
87-
FnArg::Typed(pt)
105+
syn::FnArg::Typed(pt)
88106
}
89107
_ => p,
90108
})

0 commit comments

Comments
 (0)