Skip to content

Commit b737b9f

Browse files
committed
Cleanup
1 parent 78a166f commit b737b9f

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

rtic-macros/src/codegen/module.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::syntax::{ast::App, Context};
22
use crate::{analyze::Analysis, codegen::bindings::interrupt_mod, codegen::util};
33

44
use proc_macro2::TokenStream as TokenStream2;
5-
use quote::{format_ident, quote};
5+
use quote::quote;
66

77
#[allow(clippy::too_many_lines)]
88
pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
@@ -132,19 +132,9 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
132132
let internal_spawn_helper_ident = util::internal_task_ident(name, "spawn_helper");
133133
let internal_waker_ident = util::internal_task_ident(name, "waker");
134134
let from_ptr_n_args = util::from_ptr_n_args_ident(spawnee.inputs.len());
135-
let (input_args, input_tupled, input_untupled, input_ty) =
135+
let (generic_input_args, input_args, input_tupled, input_untupled, input_ty) =
136136
util::regroup_inputs(&spawnee.inputs);
137137

138-
let generics: Vec<_> = spawnee.inputs.iter().enumerate().map(|(i, _)| format_ident!("T{i}")).collect();
139-
let generic_input_args = generics.iter().enumerate().map(|(i, generic)| {
140-
let ident = format_ident!("_{i}");
141-
quote! { #ident: #generic }
142-
});
143-
let constraints = generics.iter().zip(&spawnee.inputs).map(|(generic, input)| {
144-
let ty = &input.ty;
145-
quote!{ #generic: rtic::export::dummy::Dummy<T=#ty> + Send + Sync }
146-
});
147-
148138
// Spawn caller
149139
items.push(quote!(
150140
#(#cfgs)*
@@ -171,9 +161,8 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
171161
/// Spawns the task directly
172162
#[allow(non_snake_case)]
173163
#[doc(hidden)]
174-
pub fn #internal_spawn_ident<#(#generics),*>(#(#generic_input_args,)*) -> ::core::result::Result<(), #input_ty>
175-
where #(#constraints),*
176-
{
164+
pub fn #internal_spawn_ident(#(#generic_input_args,)*) -> ::core::result::Result<(), #input_ty> {
165+
// SAFETY: The generic args require Send + Sync
177166
unsafe { #internal_spawn_helper_ident(#(#input_untupled.to()),*) }
178167
}
179168
));
@@ -224,27 +213,21 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
224213
let internal_spawn_ident = util::internal_task_ident(ident, "spawn_helper");
225214
let attrs = &task.attrs;
226215
let cfgs = &task.cfgs;
227-
let inputs = &task.inputs;
228216
let generics = if task.is_bottom {
229217
quote!()
230218
} else {
231219
quote!(<'a>)
232220
};
233221

234-
let input_vals = inputs.iter().map(|i| match &*i.pat {
235-
syn::Pat::Ident(pat_ident) => pat_ident.ident.clone(),
236-
_ => todo!(),
237-
}).collect::<Vec<_>>();
238-
239-
let (_input_args, _input_tupled, _input_untupled, input_ty) = util::regroup_inputs(&task.inputs);
222+
let (_generic_input_args, input_args, _input_tupled, input_untupled, input_ty) = util::regroup_inputs(&task.inputs);
240223
quote! {
241224
#(#attrs)*
242225
#(#cfgs)*
243226
#[allow(non_snake_case)]
244-
pub(super) fn #ident #generics(&self #(,#[allow(unused_mut)] #inputs)*) -> ::core::result::Result<(), #input_ty> {
227+
pub(super) fn #ident #generics(&self #(,#input_args)*) -> ::core::result::Result<(), #input_ty> {
245228
// SAFETY: This is safe to call since this can only be called
246229
// from the same executor
247-
unsafe { #internal_spawn_ident(#(#input_vals,)*) }
230+
unsafe { #internal_spawn_ident(#(#input_untupled,)*) }
248231
}
249232
}
250233
})

rtic-macros/src/codegen/util.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub fn link_section_uninit() -> TokenStream2 {
3535
pub fn regroup_inputs(
3636
inputs: &[PatType],
3737
) -> (
38+
// Generic args e.g. &[`_0: Dummy<T=i32>`, `_1: Dummy<T=i64>`]
39+
Vec<TokenStream2>,
3840
// args e.g. &[`_0`], &[`_0: i32`, `_1: i64`]
3941
Vec<TokenStream2>,
4042
// tupled e.g. `_0`, `(_0, _1)`
@@ -48,12 +50,14 @@ pub fn regroup_inputs(
4850
let ty = &inputs[0].ty;
4951

5052
(
53+
vec![quote!(_0: impl rtic::export::dummy::Dummy<T=#ty> + Send + Sync)],
5154
vec![quote!(_0: #ty)],
5255
quote!(_0),
5356
vec![quote!(_0)],
5457
quote!(#ty),
5558
)
5659
} else {
60+
let mut generic_args = vec![];
5761
let mut args = vec![];
5862
let mut pats = vec![];
5963
let mut tys = vec![];
@@ -62,6 +66,8 @@ pub fn regroup_inputs(
6266
let i = Ident::new(&format!("_{i}"), Span::call_site());
6367
let ty = &input.ty;
6468

69+
generic_args.push(quote!(#i: impl rtic::export::dummy::Dummy<T=#ty> + Send + Sync));
70+
6571
args.push(quote!(#i: #ty));
6672

6773
pats.push(quote!(#i));
@@ -74,7 +80,7 @@ pub fn regroup_inputs(
7480
quote!((#(#pats,)*))
7581
};
7682
let ty = quote!((#(#tys,)*));
77-
(args, tupled, pats, ty)
83+
(generic_args, args, tupled, pats, ty)
7884
}
7985
}
8086

0 commit comments

Comments
 (0)