Signal ops now all have #[track_caller] by default.

`EffectRun::run` and `IntoSubscriber::into_subscriber` are now `#[track_caller]`.
This commit is contained in:
Filipe Rodrigues 2025-05-28 05:34:08 +01:00
parent 8904c3b5c7
commit 5c6ee22376
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU
17 changed files with 16 additions and 60 deletions

View File

@ -193,7 +193,6 @@ where
where
Self: 'a;
#[track_caller]
fn borrow(&self) -> Self::Ref<'_> {
let res = self.inner.borrow();
match res {
@ -205,7 +204,6 @@ where
}
}
#[track_caller]
fn borrow_raw(&self) -> Self::Ref<'_> {
let res = self.inner.borrow_raw();
match res {
@ -226,7 +224,6 @@ where
{
type Value<'a> = Loadable<&'a T, E>;
#[track_caller]
fn with<F2, O>(&self, f: F2) -> O
where
F2: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -235,7 +232,6 @@ where
f(value.as_deref())
}
#[track_caller]
fn with_raw<F2, O>(&self, f: F2) -> O
where
F2: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -298,7 +294,6 @@ where
where
Self: 'a;
#[track_caller]
fn borrow_mut(&self) -> Self::RefMut<'_> {
let res = self.inner.borrow_mut();
match res {
@ -310,7 +305,6 @@ where
}
}
#[track_caller]
fn borrow_mut_raw(&self) -> Self::RefMut<'_> {
let res = self.inner.borrow_mut_raw();
match res {
@ -331,7 +325,6 @@ where
{
type Value<'a> = Loadable<&'a mut T, E>;
#[track_caller]
fn update<F2, O>(&self, f: F2) -> O
where
F2: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -340,7 +333,6 @@ where
f(value.as_deref_mut())
}
#[track_caller]
fn update_raw<F2, O>(&self, f: F2) -> O
where
F2: for<'a> FnOnce(Self::Value<'a>) -> O,

View File

@ -354,7 +354,6 @@ impl<F: Loader, W: AsyncReactiveWorld<F>> SignalBorrow for AsyncSignal<F, W> {
where
Self: 'a;
#[track_caller]
fn borrow(&self) -> Self::Ref<'_> {
// Start loading on borrow
let mut inner = self.inner.write();
@ -368,7 +367,6 @@ impl<F: Loader, W: AsyncReactiveWorld<F>> SignalBorrow for AsyncSignal<F, W> {
.then(|| BorrowRef(IMutRefMut::<_, W>::downgrade(inner)))
}
#[track_caller]
fn borrow_raw(&self) -> Self::Ref<'_> {
// Start loading on borrow
// TODO: Should we start loading here?
@ -390,7 +388,6 @@ where
{
type Value<'a> = Option<&'a F::Output>;
#[track_caller]
fn with<F2, O>(&self, f: F2) -> O
where
F2: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -447,7 +444,6 @@ impl<F: Loader, W: AsyncReactiveWorld<F>> SignalBorrowMut for AsyncSignal<F, W>
where
Self: 'a;
#[track_caller]
fn borrow_mut(&self) -> Self::RefMut<'_> {
// Note: We don't load when mutably borrowing, since that's probably
// not what the user wants
@ -461,7 +457,6 @@ impl<F: Loader, W: AsyncReactiveWorld<F>> SignalBorrowMut for AsyncSignal<F, W>
})
}
#[track_caller]
fn borrow_mut_raw(&self) -> Self::RefMut<'_> {
// Note: We don't load when mutably borrowing, since that's probably
// not what the user wants
@ -482,7 +477,6 @@ where
{
type Value<'a> = Option<&'a mut F::Output>;
#[track_caller]
fn update<F2, O>(&self, f: F2) -> O
where
F2: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -491,7 +485,6 @@ where
f(value.as_deref_mut())
}
#[track_caller]
fn update_raw<F2, O>(&self, f: F2) -> O
where
F2: for<'a> FnOnce(Self::Value<'a>) -> O,

View File

@ -115,14 +115,12 @@ impl<T: 'static, F: ?Sized, W: DerivedWorld<T, F>> SignalBorrow for Derived<T, F
where
Self: 'a;
#[track_caller]
fn borrow(&self) -> Self::Ref<'_> {
self.effect.inner_fn().trigger.gather_subscribers();
self.borrow_raw()
}
#[track_caller]
fn borrow_raw(&self) -> Self::Ref<'_> {
let effect_fn = self.effect.inner_fn();
let value = effect_fn.value.read();
@ -181,7 +179,6 @@ where
F: Fn() -> T,
W: DerivedWorld<T, F>,
{
#[track_caller]
fn run(&self, _ctx: EffectRunCtx<'_, W>) {
*self.value.write() = Some((self.f)());
self.trigger.exec();

View File

@ -447,6 +447,7 @@ pub fn running<W: ReactiveWorld>() -> Option<WeakEffect<W::F, W>> {
/// Effect run
pub trait EffectRun<W: ReactiveWorld = WorldDefault> {
/// Runs the effect
#[track_caller]
fn run(&self, ctx: EffectRunCtx<'_, W>);
}

View File

@ -87,7 +87,6 @@ impl<T: 'static, F: ?Sized, W: MemoWorld<T, F>> SignalBorrow for Memo<T, F, W> {
where
Self: 'a;
#[track_caller]
fn borrow(&self) -> Self::Ref<'_> {
self.effect.inner_fn().trigger.gather_subscribers();
@ -149,7 +148,6 @@ where
F: Fn() -> T,
W: MemoWorld<T, F>,
{
#[track_caller]
fn run(&self, _ctx: EffectRunCtx<'_, W>) {
let new_value = (self.f)();
let mut value = self.value.write();

View File

@ -114,14 +114,12 @@ impl<T: ?Sized + 'static, W: ReactiveWorld> SignalBorrow for Signal<T, W> {
where
Self: 'a;
#[track_caller]
fn borrow(&self) -> Self::Ref<'_> {
self.inner.trigger.gather_subscribers();
self.borrow_raw()
}
#[track_caller]
fn borrow_raw(&self) -> Self::Ref<'_> {
let value = self.inner.value.read();
BorrowRef(value)
@ -131,12 +129,10 @@ impl<T: ?Sized + 'static, W: ReactiveWorld> SignalBorrow for Signal<T, W> {
impl<T: 'static, W: ReactiveWorld> SignalReplace<T> for Signal<T, W> {
type Value = T;
#[track_caller]
fn replace(&self, new_value: T) -> Self::Value {
mem::replace(&mut self.borrow_mut(), new_value)
}
#[track_caller]
fn replace_raw(&self, new_value: T) -> Self::Value {
mem::replace(&mut self.borrow_mut_raw(), new_value)
}
@ -178,7 +174,6 @@ impl<T: ?Sized + 'static, W: ReactiveWorld> SignalBorrowMut for Signal<T, W> {
where
Self: 'a;
#[track_caller]
fn borrow_mut(&self) -> Self::RefMut<'_> {
let value = self.inner.value.write();
BorrowRefMut {
@ -187,7 +182,6 @@ impl<T: ?Sized + 'static, W: ReactiveWorld> SignalBorrowMut for Signal<T, W> {
}
}
#[track_caller]
fn borrow_mut_raw(&self) -> Self::RefMut<'_> {
let value = self.inner.value.write();
BorrowRefMut {

View File

@ -8,10 +8,12 @@ pub trait SignalBorrow {
Self: 'a;
/// Borrows the signal value
#[track_caller]
fn borrow(&self) -> Self::Ref<'_>;
/// Borrows the signal value without adding a dependency
// TODO: Better name than `_raw`?
// TODO: Allow using a different reference than `Self::Ref`?
#[track_caller]
fn borrow_raw(&self) -> Self::Ref<'_>;
}

View File

@ -8,10 +8,12 @@ pub trait SignalBorrowMut {
Self: 'a;
/// Borrows the signal value mutably
#[track_caller]
fn borrow_mut(&self) -> Self::RefMut<'_>;
/// Borrows the signal value mutably without updating dependencies
// TODO: Better name than `_raw`?
// TODO: Allow using a different reference than `Self::RefMut`?
#[track_caller]
fn borrow_mut_raw(&self) -> Self::RefMut<'_>;
}

View File

@ -33,9 +33,11 @@ pub trait SignalGet {
type Value;
/// Gets the signal value, by copying it.
#[track_caller]
fn get(&self) -> Self::Value;
/// Gets the signal value, by copying it without adding dependencies.
#[track_caller]
fn get_raw(&self) -> Self::Value;
}
@ -45,12 +47,10 @@ where
{
type Value = <S::Value<'static> as SignalGetCopy>::Value;
#[track_caller]
fn get(&self) -> Self::Value {
self.with(|value| self::convert_inner::<S>(value.copy_value()))
}
#[track_caller]
fn get_raw(&self) -> Self::Value {
self.with_raw(|value| self::convert_inner::<S>(value.copy_value()))
}

View File

@ -5,8 +5,10 @@ pub trait SignalReplace<T> {
type Value;
/// Replaces the signal value, returning the previous value
#[track_caller]
fn replace(&self, new_value: T) -> Self::Value;
/// Replaces the signal value, returning the previous value without triggering any dependencies.
#[track_caller]
fn replace_raw(&self, new_value: T) -> Self::Value;
}

View File

@ -28,9 +28,11 @@ pub auto trait SignalSetDefaultImpl {}
/// Signal set
pub trait SignalSet<Value> {
/// Sets the signal value
#[track_caller]
fn set(&self, new_value: Value);
/// Sets the signal value without updating dependencies
#[track_caller]
fn set_raw(&self, new_value: Value);
}
@ -38,12 +40,10 @@ impl<S, T> SignalSet<T> for S
where
S: for<'a> SignalUpdate<Value<'a>: SignalSetWith<T>> + SignalSetDefaultImpl,
{
#[track_caller]
fn set(&self, new_value: T) {
self.update(|value| SignalSetWith::set_value(value, new_value));
}
#[track_caller]
fn set_raw(&self, new_value: T) {
self.update_raw(|value| SignalSetWith::set_value(value, new_value));
}

View File

@ -15,11 +15,13 @@ pub trait SignalUpdate {
type Value<'a>: ?Sized;
/// Updates the signal value
#[track_caller]
fn update<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O;
/// Updates the signal value without updating dependencies
#[track_caller]
fn update_raw<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O;
@ -32,7 +34,6 @@ where
{
type Value<'a> = &'a mut T;
#[track_caller]
fn update<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -41,7 +42,6 @@ where
f(&mut borrow)
}
#[track_caller]
fn update_raw<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,

View File

@ -15,11 +15,13 @@ pub trait SignalWith {
type Value<'a>: ?Sized;
/// Uses the signal value
#[track_caller]
fn with<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O;
/// Uses the signal value without adding any dependencies
#[track_caller]
fn with_raw<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O;
@ -32,7 +34,6 @@ where
{
type Value<'a> = &'a T;
#[track_caller]
fn with<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -41,7 +42,6 @@ where
f(&borrow)
}
#[track_caller]
fn with_raw<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,

View File

@ -355,6 +355,7 @@ impl<W: ReactiveWorld> fmt::Debug for WeakTrigger<W> {
/// Types that may be converted into a subscriber
pub trait IntoSubscriber<W: ReactiveWorld> {
/// Converts this type into a weak effect.
#[track_caller]
fn into_subscriber(self) -> Subscriber<W>;
}
@ -378,7 +379,6 @@ where
W: ReactiveWorld,
WeakEffect<F, W>: CoerceUnsized<WeakEffect<W::F, W>>,
{
#[track_caller]
fn into_subscriber(self) -> Subscriber<W> {
Subscriber { effect: effect_value }
}

View File

@ -64,7 +64,6 @@ impl<S: SignalBorrow, T> SignalBorrow for WithDefault<S, T> {
where
Self: 'a;
#[track_caller]
fn borrow(&self) -> Self::Ref<'_> {
BorrowRef {
value: self.inner.borrow(),
@ -72,7 +71,6 @@ impl<S: SignalBorrow, T> SignalBorrow for WithDefault<S, T> {
}
}
#[track_caller]
fn borrow_raw(&self) -> Self::Ref<'_> {
BorrowRef {
value: self.inner.borrow_raw(),
@ -90,7 +88,6 @@ where
{
type Value<'a> = &'a T;
#[track_caller]
fn with<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -101,7 +98,6 @@ where
})
}
#[track_caller]
fn with_raw<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -130,12 +126,10 @@ impl<S, T> SignalSet<T> for WithDefault<S, T>
where
S: SignalSet<Option<T>>,
{
#[track_caller]
fn set(&self, new_value: T) {
self.inner.set(Some(new_value));
}
#[track_caller]
fn set_raw(&self, new_value: T) {
self.inner.set_raw(Some(new_value));
}
@ -145,12 +139,10 @@ impl<S, T> SignalSet<Option<T>> for WithDefault<S, T>
where
S: SignalSet<Option<T>>,
{
#[track_caller]
fn set(&self, new_value: Option<T>) {
self.inner.set(new_value);
}
#[track_caller]
fn set_raw(&self, new_value: Option<T>) {
self.inner.set_raw(new_value);
}
@ -163,12 +155,10 @@ where
{
type Value = T;
#[track_caller]
fn replace(&self, new_value: T) -> Self::Value {
self.inner.replace(Some(new_value)).unwrap_or(self.default)
}
#[track_caller]
fn replace_raw(&self, new_value: T) -> Self::Value {
self.inner.replace_raw(Some(new_value)).unwrap_or(self.default)
}
@ -181,12 +171,10 @@ where
{
type Value = T;
#[track_caller]
fn replace(&self, new_value: Option<T>) -> Self::Value {
self.inner.replace(new_value).unwrap_or(self.default)
}
#[track_caller]
fn replace_raw(&self, new_value: Option<T>) -> Self::Value {
self.inner.replace_raw(new_value).unwrap_or(self.default)
}
@ -231,7 +219,6 @@ where
where
Self: 'a;
#[track_caller]
fn borrow_mut(&self) -> Self::RefMut<'_> {
let mut value = self.inner.borrow_mut();
value.get_or_insert(self.default);
@ -239,7 +226,6 @@ where
BorrowRefMut { value }
}
#[track_caller]
fn borrow_mut_raw(&self) -> Self::RefMut<'_> {
let mut value = self.inner.borrow_mut_raw();
value.get_or_insert(self.default);
@ -255,7 +241,6 @@ where
{
type Value<'a> = &'a mut T;
#[track_caller]
fn update<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,
@ -263,7 +248,6 @@ where
self.inner.update(|value| f(value.get_or_insert(self.default)))
}
#[track_caller]
fn update_raw<F, O>(&self, f: F) -> O
where
F: for<'a> FnOnce(Self::Value<'a>) -> O,

View File

@ -64,12 +64,10 @@ impl SignalBorrow for Location {
where
Self: 'a;
#[track_caller]
fn borrow(&self) -> Self::Ref<'_> {
BorrowRef(self.0.borrow())
}
#[track_caller]
fn borrow_raw(&self) -> Self::Ref<'_> {
BorrowRef(self.0.borrow_raw())
}
@ -112,13 +110,11 @@ impl SignalBorrowMut for Location {
where
Self: 'a;
#[track_caller]
fn borrow_mut(&self) -> Self::RefMut<'_> {
let value = self.0.borrow_mut();
BorrowRefMut(value)
}
#[track_caller]
fn borrow_mut_raw(&self) -> Self::RefMut<'_> {
let value = self.0.borrow_mut_raw();
BorrowRefMut(value)

View File

@ -103,7 +103,6 @@ where
where
Self: 'a;
#[track_caller]
fn borrow(&self) -> Self::Ref<'_> {
BorrowRef(self.inner.borrow())
}
@ -120,12 +119,10 @@ where
{
type Value = T::Value;
#[track_caller]
fn replace(&self, new_value: T::Value) -> Self::Value {
mem::replace(&mut *self.borrow_mut(), new_value)
}
#[track_caller]
fn replace_raw(&self, new_value: T::Value) -> Self::Value {
mem::replace(&mut *self.borrow_mut_raw(), new_value)
}
@ -239,7 +236,6 @@ where
where
Self: 'a;
#[track_caller]
fn borrow_mut(&self) -> Self::RefMut<'_> {
let value = self.inner.borrow_mut();
BorrowRefMut {
@ -248,7 +244,6 @@ where
}
}
#[track_caller]
fn borrow_mut_raw(&self) -> Self::RefMut<'_> {
// TODO: Should we be updating the location on drop?
let value = self.inner.borrow_mut_raw();