library + trace: rewrite panic sites as explicit match+panic
Apply the same explicit match+panic shape to the library layer (channel, gen_server, gen_statem). Extend it to the smarm-trace-gated code that the default `cargo clippy --lib` does not see: the GLOBAL lock-poison sites in trace.rs and the current_pid sites inside te!() in channel.rs. Keep the current_pid match inside the te!() argument so non-trace builds evaluate nothing extra on the recv-wake hot path. const-init the trace thread-local.
This commit is contained in:
+31
-12
@@ -528,7 +528,10 @@ impl<G: GenServer> TimerHandle<G> {
|
||||
/// [`TimerId`] you can pass to `cancel`. Timer fires arrive before info and
|
||||
/// inbox messages.
|
||||
pub fn arm_after(&self, after: Duration, msg: G::Timer) -> TimerId {
|
||||
let mut reg = self.reg.lock().unwrap();
|
||||
let mut reg = match self.reg.lock() {
|
||||
Ok(g) => g,
|
||||
Err(e) => panic!("smarm: gen_server reg lock poisoned (core corrupt): {e}"),
|
||||
};
|
||||
let local = reg.mint();
|
||||
// The fire thunk carries the local id so the loop can retire the entry
|
||||
// on dispatch; `msg` is moved in (no `Clone` needed for one-shots).
|
||||
@@ -552,7 +555,10 @@ impl<G: GenServer> TimerHandle<G> {
|
||||
where
|
||||
G::Timer: Clone,
|
||||
{
|
||||
let mut reg = self.reg.lock().unwrap();
|
||||
let mut reg = match self.reg.lock() {
|
||||
Ok(g) => g,
|
||||
Err(e) => panic!("smarm: gen_server reg lock poisoned (core corrupt): {e}"),
|
||||
};
|
||||
let local = reg.mint();
|
||||
// A live periodic must keep the system arm open so the next tick can be
|
||||
// re-armed; the first periodic installs the loop's re-arm sender.
|
||||
@@ -577,7 +583,10 @@ impl<G: GenServer> TimerHandle<G> {
|
||||
/// stops re-arming: the entry is removed so the loop will not schedule
|
||||
/// another tick even if the pending one already escaped onto the channel.
|
||||
pub fn cancel(&self, id: TimerId) -> bool {
|
||||
let mut reg = self.reg.lock().unwrap();
|
||||
let mut reg = match self.reg.lock() {
|
||||
Ok(g) => g,
|
||||
Err(e) => panic!("smarm: gen_server reg lock poisoned (core corrupt): {e}"),
|
||||
};
|
||||
if let Some(sub) = reg.oneshots.remove(&id) {
|
||||
return cancel_timer(sub);
|
||||
}
|
||||
@@ -587,7 +596,7 @@ impl<G: GenServer> TimerHandle<G> {
|
||||
reg.rearm_tx = None;
|
||||
}
|
||||
debug_assert!(
|
||||
reg.rearm_tx.is_some() == !reg.periodics.is_empty(),
|
||||
reg.rearm_tx.is_some() != reg.periodics.is_empty(),
|
||||
"rearm_tx must be Some iff periodics is non-empty"
|
||||
);
|
||||
return beat;
|
||||
@@ -846,7 +855,10 @@ fn server_loop<G: GenServer>(
|
||||
impl<G: GenServer> Drop for Terminate<G> {
|
||||
fn drop(&mut self) {
|
||||
{
|
||||
let mut reg = self.1.lock().unwrap();
|
||||
let mut reg = match self.1.lock() {
|
||||
Ok(g) => g,
|
||||
Err(e) => panic!("smarm: gen_server reg lock poisoned (core corrupt): {e}"),
|
||||
};
|
||||
for (_, sub) in reg.oneshots.drain() {
|
||||
cancel_timer(sub);
|
||||
}
|
||||
@@ -995,7 +1007,10 @@ fn server_loop<G: GenServer>(
|
||||
// The one-shot fired: retire its registry entry so the
|
||||
// live set tracks only still-pending timers, then
|
||||
// dispatch.
|
||||
reg.lock().unwrap().oneshots.remove(&id);
|
||||
match reg.lock() {
|
||||
Ok(mut g) => { g.oneshots.remove(&id); }
|
||||
Err(e) => panic!("smarm: gen_server reg lock poisoned (core corrupt): {e}"),
|
||||
}
|
||||
guard.0.handle_timer(msg);
|
||||
reset_idle(&mut idle_deadline);
|
||||
}
|
||||
@@ -1006,16 +1021,20 @@ fn server_loop<G: GenServer>(
|
||||
// so the period is measured from fire-handling and a
|
||||
// handler that cancels stops the just-armed instance.
|
||||
let msg = {
|
||||
let mut g = reg.lock().unwrap();
|
||||
let mut g = match reg.lock() {
|
||||
Ok(g) => g,
|
||||
Err(e) => panic!("smarm: gen_server reg lock poisoned (core corrupt): {e}"),
|
||||
};
|
||||
let r = &mut *g;
|
||||
if let Some(p) = r.periodics.get_mut(&id) {
|
||||
let every = p.every;
|
||||
let msg = (p.make)();
|
||||
let tx = r
|
||||
.rearm_tx
|
||||
.as_ref()
|
||||
.expect("a live periodic keeps rearm_tx Some")
|
||||
.clone();
|
||||
let tx = match r.rearm_tx.as_ref() {
|
||||
Some(tx) => tx.clone(),
|
||||
None => panic!(
|
||||
"smarm: live periodic without rearm_tx (logic bug)"
|
||||
),
|
||||
};
|
||||
p.live = send_after_to(every, tx, Sys::Tick(id));
|
||||
Some(msg)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user