From fafc94ccfba4447c9eba7457a977d67a74507436 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 21 May 2019 14:18:43 +0200 Subject: [PATCH] removes the maybe_uninit feature gate and stop newtyping `core::mem::MaybeUninit` --- macros/src/codegen.rs | 41 +++++++++++++++++++++-------------------- src/export.rs | 30 ------------------------------ src/lib.rs | 1 - 3 files changed, 21 insertions(+), 51 deletions(-) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index c33ecf6361..9e5d20ce3f 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -229,8 +229,8 @@ fn resources( const_app.push(quote!( #(#attrs)* #(#cfgs)* - static mut #name: rtfm::export::MaybeUninit<#ty> = - rtfm::export::MaybeUninit::uninit(); + static mut #name: core::mem::MaybeUninit<#ty> = + core::mem::MaybeUninit::uninit(); )); } @@ -580,21 +580,21 @@ fn tasks( let task_fq = mk_fq_ident(name); let elems = (0..cap) - .map(|_| quote!(rtfm::export::MaybeUninit::uninit())) + .map(|_| quote!(core::mem::MaybeUninit::uninit())) .collect::>(); if cfg!(feature = "timer-queue") { let elems = elems.clone(); const_app.push(quote!( /// Buffer that holds the instants associated to the inputs of a task - static mut #task_instants: [rtfm::export::MaybeUninit; #cap_lit] = + static mut #task_instants: [core::mem::MaybeUninit; #cap_lit] = [#(#elems,)*]; )); } const_app.push(quote!( /// Buffer that holds the inputs of a task - static mut #task_inputs: [rtfm::export::MaybeUninit<#ty>; #cap_lit] = + static mut #task_inputs: [core::mem::MaybeUninit<#ty>; #cap_lit] = [#(#elems,)*]; )); @@ -612,8 +612,8 @@ fn tasks( } else { const_app.push(quote!( #[doc = #doc] - static mut #task_fq: rtfm::export::MaybeUninit<#fq_ty> = - rtfm::export::MaybeUninit::uninit(); + static mut #task_fq: core::mem::MaybeUninit<#fq_ty> = + core::mem::MaybeUninit::uninit(); )); quote!(#task_fq.as_mut_ptr()) @@ -717,8 +717,8 @@ fn dispatchers(app: &App, analysis: &Analysis) -> Vec } else { items.push(quote!( #[doc = #doc] - static mut #rq: rtfm::export::MaybeUninit<#rq_ty> = - rtfm::export::MaybeUninit::uninit(); + static mut #rq: core::mem::MaybeUninit<#rq_ty> = + core::mem::MaybeUninit::uninit(); )); quote!(#rq.as_mut_ptr()) @@ -771,7 +771,7 @@ fn dispatchers(app: &App, analysis: &Analysis) -> Vec let inputs = mk_inputs_ident(name); let fq = mk_fq_ident(name); - let input = quote!(#inputs.get_unchecked(usize::from(index)).read()); + let input = quote!(#inputs.get_unchecked(usize::from(index)).as_ptr().read()); let fq = if cfg!(feature = "nightly") { quote!(#fq) } else { @@ -780,7 +780,8 @@ fn dispatchers(app: &App, analysis: &Analysis) -> Vec let (let_instant, _instant) = if cfg!(feature = "timer-queue") { let instants = mk_instants_ident(name); - let instant = quote!(#instants.get_unchecked(usize::from(index)).read()); + let instant = + quote!(#instants.get_unchecked(usize::from(index)).as_ptr().read()); ( Some(quote!(let instant = #instant;)), @@ -992,7 +993,7 @@ fn timer_queue(app: &App, analysis: &Analysis) -> Vec let ty = quote!(rtfm::export::TimerQueue); items.push(quote!( /// The timer queue - static mut TQ: rtfm::export::MaybeUninit<#ty> = rtfm::export::MaybeUninit::uninit(); + static mut TQ: core::mem::MaybeUninit<#ty> = core::mem::MaybeUninit::uninit(); )); items.push(quote!( @@ -1178,7 +1179,7 @@ fn pre_init(app: &App, analysis: &Analysis) -> Vec { // initialize `MaybeUninit` `ReadyQueue`s for level in analysis.dispatchers.keys() { let rq = mk_rq_ident(*level); - stmts.push(quote!(#rq.write(rtfm::export::ReadyQueue::u8_sc());)) + stmts.push(quote!(#rq.as_mut_ptr().write(rtfm::export::ReadyQueue::u8_sc());)) } // initialize `MaybeUninit` `FreeQueue`s @@ -1186,7 +1187,7 @@ fn pre_init(app: &App, analysis: &Analysis) -> Vec { let fq = mk_fq_ident(name); stmts.push(quote!( - let fq = #fq.write(rtfm::export::FreeQueue::u8_sc()); + let fq = #fq.as_mut_ptr().write(rtfm::export::FreeQueue::u8_sc()); )); // populate the `FreeQueue`s @@ -1217,7 +1218,7 @@ fn pre_init(app: &App, analysis: &Analysis) -> Vec { // Initialize the timer queue if !analysis.timer_queue.tasks.is_empty() { - stmts.push(quote!(TQ.write(rtfm::export::TimerQueue::new(core.SYST));)); + stmts.push(quote!(TQ.as_mut_ptr().write(rtfm::export::TimerQueue::new(core.SYST));)); } // set interrupts priorities @@ -1431,7 +1432,7 @@ fn post_init(app: &App, analysis: &Analysis) -> Vec { continue; } - stmts.push(quote!(#name.write(late.#name);)); + stmts.push(quote!(#name.as_mut_ptr().write(late.#name);)); } // set exception priorities @@ -2252,7 +2253,7 @@ fn mk_spawn_body<'a>( let instants = mk_instants_ident(name); Some(quote!( - #instants.get_unchecked_mut(usize::from(index)).write(instant); + #instants.get_unchecked_mut(usize::from(index)).as_mut_ptr().write(instant); )) } else { None @@ -2287,7 +2288,7 @@ fn mk_spawn_body<'a>( let input = #tupled; if let Some(index) = #dequeue { - #inputs.get_unchecked_mut(usize::from(index)).write(input); + #inputs.get_unchecked_mut(usize::from(index)).as_mut_ptr().write(input); #write_instant @@ -2338,9 +2339,9 @@ fn mk_schedule_body<'a>(scheduler: &Ident, name: &Ident, app: &'a App) -> proc_m let input = #tupled; if let Some(index) = #dequeue { - #instants.get_unchecked_mut(usize::from(index)).write(instant); + #instants.get_unchecked_mut(usize::from(index)).as_mut_ptr().write(instant); - #inputs.get_unchecked_mut(usize::from(index)).write(input); + #inputs.get_unchecked_mut(usize::from(index)).as_mut_ptr().write(input); let nr = rtfm::export::NotReady { instant, diff --git a/src/export.rs b/src/export.rs index 93a92fcf2a..ee4df52a2c 100644 --- a/src/export.rs +++ b/src/export.rs @@ -68,36 +68,6 @@ impl Priority { } } -// We newtype `core::mem::MaybeUninit` so the end-user doesn't need `#![feature(maybe_uninit)]` in -// their code -pub struct MaybeUninit { - inner: core::mem::MaybeUninit, -} - -impl MaybeUninit { - pub const fn uninit() -> Self { - MaybeUninit { - inner: core::mem::MaybeUninit::uninit(), - } - } - - pub fn as_ptr(&self) -> *const T { - self.inner.as_ptr() - } - - pub fn as_mut_ptr(&mut self) -> *mut T { - self.inner.as_mut_ptr() - } - - pub unsafe fn read(&self) -> T { - self.inner.read() - } - - pub fn write(&mut self, value: T) -> &mut T { - self.inner.write(value) - } -} - #[inline(always)] pub fn assert_send() where diff --git a/src/lib.rs b/src/lib.rs index acd8d433fd..1fe88c4728 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,6 @@ //! language feature to reduce static memory usage, runtime overhead and initialization overhead. //! This feature requires a nightly compiler and may stop working at any time! -#![feature(maybe_uninit)] #![deny(missing_docs)] #![deny(warnings)] #![no_std]