Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: use WakerHack unconditionally even if nightly feature is enabled. #3528

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions embassy-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ avr-device = { version = "0.5.3", optional = true }
critical-section = { version = "1.1", features = ["std"] }
trybuild = "1.0"

[build-dependencies]
rustc_version = "0.4.1"

[features]

## Enable nightly-only features
Expand Down
11 changes: 0 additions & 11 deletions embassy-executor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,4 @@ fn main() {

let mut rustc_cfgs = common::CfgSet::new();
common::set_target_cfgs(&mut rustc_cfgs);

// Waker API changed on 2024-09-06
rustc_cfgs.declare("at_least_2024_09_06");
let Some(compiler) = common::compiler_info() else {
return;
};
if compiler.channel == rustc_version::Channel::Nightly
&& compiler.commit_date.map(|d| d >= "2024-09-06").unwrap_or(false)
{
rustc_cfgs.enable("at_least_2024_09_06");
}
}
19 changes: 0 additions & 19 deletions embassy-executor/build_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,3 @@ impl PartialOrd<&str> for CompilerDate {
Self::parse(other).map(|other| self.cmp(&other))
}
}

pub struct CompilerInfo {
#[allow(unused)]
pub version: rustc_version::Version,
pub channel: rustc_version::Channel,
pub commit_date: Option<CompilerDate>,
}

pub fn compiler_info() -> Option<CompilerInfo> {
let Ok(meta) = rustc_version::version_meta() else {
return None;
};

Some(CompilerInfo {
version: meta.semver,
channel: meta.channel,
commit_date: meta.commit_date.as_deref().and_then(CompilerDate::parse),
})
}
1 change: 0 additions & 1 deletion embassy-executor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg_attr(not(any(feature = "arch-std", feature = "arch-wasm")), no_std)]
#![cfg_attr(all(feature = "nightly", not(at_least_2024_09_06)), feature(waker_getters))]
#![allow(clippy::new_without_default)]
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
Expand Down
42 changes: 11 additions & 31 deletions embassy-executor/src/raw/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,20 @@ pub(crate) unsafe fn from_task(p: TaskRef) -> Waker {
///
/// Panics if the waker is not created by the Embassy executor.
pub fn task_from_waker(waker: &Waker) -> TaskRef {
let (vtable, data) = {
#[cfg(not(feature = "nightly"))]
{
struct WakerHack {
data: *const (),
vtable: &'static RawWakerVTable,
}

// safety: OK because WakerHack has the same layout as Waker.
// This is not really guaranteed because the structs are `repr(Rust)`, it is
// indeed the case in the current implementation.
// TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992
let hack: &WakerHack = unsafe { core::mem::transmute(waker) };
(hack.vtable, hack.data)
}

#[cfg(feature = "nightly")]
{
#[cfg(not(at_least_2024_09_06))]
{
let raw_waker = waker.as_raw();
(raw_waker.vtable(), raw_waker.data())
}
struct WakerHack {
data: *const (),
vtable: &'static RawWakerVTable,
}

#[cfg(at_least_2024_09_06)]
{
(waker.vtable(), waker.data())
}
}
};
// safety: OK because WakerHack has the same layout as Waker.
// This is not really guaranteed because the structs are `repr(Rust)`, it is
// indeed the case in the current implementation.
// TODO use waker_getters when stable. https://github.com/rust-lang/rust/issues/96992
let hack: &WakerHack = unsafe { core::mem::transmute(waker) };

if vtable != &VTABLE {
if hack.vtable != &VTABLE {
panic!("Found waker not created by the Embassy executor. `embassy_time::Timer` only works with the Embassy executor.")
}
// safety: our wakers are always created with `TaskRef::as_ptr`
unsafe { TaskRef::from_ptr(data as *const TaskHeader) }
unsafe { TaskRef::from_ptr(hack.data as *const TaskHeader) }
}