Skip to content

Commit

Permalink
Update Rust nightly.
Browse files Browse the repository at this point in the history
Fixes a new opaque type error in the task macro.
Full error is "opaque type's hidden type cannot be another opaque type from the same scope".
This got disallwed by the lazy-TAIT PR: rust-lang/rust#94081

Sadly there's now some weird type inference errors with pre-lazy-TAIT
nightlies, so support for those is dropped.
  • Loading branch information
Dirbaio authored and FrozenDroid committed May 31, 2022
1 parent a975c20 commit a2a9228
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
30 changes: 22 additions & 8 deletions embassy-macros/src/macros/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ pub fn run(args: syn::AttributeArgs, mut f: syn::ItemFn) -> Result<TokenStream,

ctxt.check()?;

let name = f.sig.ident.clone();
let task_ident = f.sig.ident.clone();
let task_inner_ident = format_ident!("__{}_task", task_ident);
let future_ident = format_ident!("__{}_Future", task_ident);
let pool_ident = format_ident!("__{}_POOL", task_ident);
let new_ts_ident = format_ident!("__{}_NEW_TASKSTORAGE", task_ident);

let visibility = &f.vis;
f.sig.ident = format_ident!("task");
f.sig.ident = task_inner_ident.clone();
let impl_ty = if args.send {
quote!(impl ::core::future::Future + Send + 'static)
} else {
Expand All @@ -73,16 +77,26 @@ pub fn run(args: syn::AttributeArgs, mut f: syn::ItemFn) -> Result<TokenStream,

let attrs = &f.attrs;

let spawn_token = quote!(#embassy_path::executor::SpawnToken);
let task_storage = quote!(#embassy_path::executor::raw::TaskStorage);

let result = quote! {

#[allow(non_camel_case_types)]
type #future_ident = #impl_ty;

#(#attrs)*
#visibility fn #name(#fargs) -> #embassy_path::executor::SpawnToken<#impl_ty> {
use #embassy_path::executor::raw::TaskStorage;
#visibility fn #task_ident(#fargs) -> #spawn_token<#future_ident> {
#f
type F = #impl_ty;

#[allow(non_upper_case_globals)]
#[allow(clippy::declare_interior_mutable_const)]
const NEW_TASK: TaskStorage<F> = TaskStorage::new();
static POOL: [TaskStorage<F>; #pool_size] = [NEW_TASK; #pool_size];
unsafe { TaskStorage::spawn_pool(&POOL, move || task(#arg_names)) }
const #new_ts_ident: #task_storage<#future_ident> = #task_storage::new();

#[allow(non_upper_case_globals)]
static #pool_ident: [#task_storage<#future_ident>; #pool_size] = [#new_ts_ident; #pool_size];

unsafe { #task_storage::spawn_pool(&#pool_ident, move || #task_inner_ident(#arg_names)) }
}
};

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Before upgrading check that everything is available on all tier1 targets here:
# https://rust-lang.github.io/rustup-components-history
[toolchain]
channel = "nightly-2022-03-10"
channel = "nightly-2022-04-24"
components = [ "rust-src", "rustfmt" ]
targets = [ "thumbv7em-none-eabi", "thumbv7m-none-eabi", "thumbv6m-none-eabi", "thumbv7em-none-eabihf", "thumbv8m.main-none-eabihf", "wasm32-unknown-unknown" ]

0 comments on commit a2a9228

Please sign in to comment.