mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-17 06:08:26 +00:00
fix release builds
This commit is contained in:
parent
df85b25548
commit
f09a2e2280
4 changed files with 24 additions and 20 deletions
|
@ -16,3 +16,4 @@ rand = "0.8.5"
|
||||||
default = ["check_generation"]
|
default = ["check_generation"]
|
||||||
check_generation = []
|
check_generation = []
|
||||||
debug_borrows = []
|
debug_borrows = []
|
||||||
|
debug_ownership = []
|
||||||
|
|
|
@ -8,7 +8,6 @@ use std::{
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
panic::Location,
|
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -157,7 +156,7 @@ pub struct GenerationalBox<T> {
|
||||||
raw: MemoryLocation,
|
raw: MemoryLocation,
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||||
generation: u32,
|
generation: u32,
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
created_at: &'static std::panic::Location<'static>,
|
created_at: &'static std::panic::Location<'static>,
|
||||||
_marker: PhantomData<T>,
|
_marker: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
@ -288,9 +287,8 @@ impl MemoryLocation {
|
||||||
fn replace_with_caller<T: 'static>(
|
fn replace_with_caller<T: 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
value: T,
|
value: T,
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))] caller: &'static Location<
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
'static,
|
caller: &'static std::panic::Location<'static>,
|
||||||
>,
|
|
||||||
) -> GenerationalBox<T> {
|
) -> GenerationalBox<T> {
|
||||||
let mut inner_mut = self.0.data.borrow_mut();
|
let mut inner_mut = self.0.data.borrow_mut();
|
||||||
|
|
||||||
|
@ -301,7 +299,7 @@ impl MemoryLocation {
|
||||||
raw: *self,
|
raw: *self,
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||||
generation: self.0.generation.get(),
|
generation: self.0.generation.get(),
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
created_at: caller,
|
created_at: caller,
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
}
|
}
|
||||||
|
@ -310,7 +308,7 @@ impl MemoryLocation {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn try_borrow<T: Any>(
|
fn try_borrow<T: Any>(
|
||||||
&self,
|
&self,
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
created_at: &'static std::panic::Location<'static>,
|
created_at: &'static std::panic::Location<'static>,
|
||||||
) -> Result<GenerationalRef<'_, T>, BorrowError> {
|
) -> Result<GenerationalRef<'_, T>, BorrowError> {
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||||
|
@ -329,7 +327,7 @@ impl MemoryLocation {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
Err(_) => Err(BorrowError::Dropped(ValueDroppedError {
|
Err(_) => Err(BorrowError::Dropped(ValueDroppedError {
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
created_at,
|
created_at,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
@ -343,7 +341,7 @@ impl MemoryLocation {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn try_borrow_mut<T: Any>(
|
fn try_borrow_mut<T: Any>(
|
||||||
&self,
|
&self,
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
created_at: &'static std::panic::Location<'static>,
|
created_at: &'static std::panic::Location<'static>,
|
||||||
) -> Result<GenerationalRefMut<'_, T>, BorrowMutError> {
|
) -> Result<GenerationalRefMut<'_, T>, BorrowMutError> {
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
||||||
|
@ -363,7 +361,7 @@ impl MemoryLocation {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
Err(_) => Err(BorrowMutError::Dropped(ValueDroppedError {
|
Err(_) => Err(BorrowMutError::Dropped(ValueDroppedError {
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
created_at,
|
created_at,
|
||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
|
@ -422,14 +420,14 @@ impl Error for BorrowMutError {}
|
||||||
/// An error that can occur when trying to use a value that has been dropped.
|
/// An error that can occur when trying to use a value that has been dropped.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct ValueDroppedError {
|
pub struct ValueDroppedError {
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
created_at: &'static std::panic::Location<'static>,
|
created_at: &'static std::panic::Location<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ValueDroppedError {
|
impl Display for ValueDroppedError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.write_str("Failed to borrow because the value was dropped.")?;
|
f.write_str("Failed to borrow because the value was dropped.")?;
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
f.write_fmt(format_args!("created_at: {}", self.created_at))?;
|
f.write_fmt(format_args!("created_at: {}", self.created_at))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -686,7 +684,7 @@ impl Owner {
|
||||||
pub fn insert_with_caller<T: 'static>(
|
pub fn insert_with_caller<T: 'static>(
|
||||||
&self,
|
&self,
|
||||||
value: T,
|
value: T,
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
caller: &'static std::panic::Location<'static>,
|
caller: &'static std::panic::Location<'static>,
|
||||||
) -> GenerationalBox<T> {
|
) -> GenerationalBox<T> {
|
||||||
let mut location = self.store.claim();
|
let mut location = self.store.claim();
|
||||||
|
@ -706,7 +704,7 @@ impl Owner {
|
||||||
raw: location,
|
raw: location,
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
||||||
generation: location.0.generation.get(),
|
generation: location.0.generation.get(),
|
||||||
#[cfg(any(debug_assertions, feature = "check_generation"))]
|
#[cfg(any(debug_assertions, feature = "debug_ownership"))]
|
||||||
created_at: std::panic::Location::caller(),
|
created_at: std::panic::Location::caller(),
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::panic::Location;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use dioxus_core::prelude::{
|
use dioxus_core::prelude::{
|
||||||
|
@ -85,11 +84,18 @@ impl<T: 'static> CopyValue<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_with_caller(value: T, caller: &'static Location<'static>) -> Self {
|
pub(crate) fn new_with_caller(
|
||||||
|
value: T,
|
||||||
|
#[cfg(debug_assertions)] caller: &'static std::panic::Location<'static>,
|
||||||
|
) -> Self {
|
||||||
let owner = current_owner();
|
let owner = current_owner();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
value: owner.insert_with_caller(value, caller),
|
value: owner.insert_with_caller(
|
||||||
|
value,
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
caller,
|
||||||
|
),
|
||||||
origin_scope: current_scope_id().expect("in a virtual dom"),
|
origin_scope: current_scope_id().expect("in a virtual dom"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
panic::Location,
|
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
@ -48,7 +47,7 @@ use crate::{CopyValue, Effect};
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn use_signal<T: 'static>(cx: &ScopeState, f: impl FnOnce() -> T) -> Signal<T> {
|
pub fn use_signal<T: 'static>(cx: &ScopeState, f: impl FnOnce() -> T) -> Signal<T> {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
let caller = Location::caller();
|
let caller = std::panic::Location::caller();
|
||||||
|
|
||||||
*cx.use_hook(|| {
|
*cx.use_hook(|| {
|
||||||
Signal::new_with_caller(
|
Signal::new_with_caller(
|
||||||
|
@ -161,7 +160,7 @@ impl<T: 'static> Signal<T> {
|
||||||
/// Creates a new Signal. Signals are a Copy state management solution with automatic dependency tracking.
|
/// Creates a new Signal. Signals are a Copy state management solution with automatic dependency tracking.
|
||||||
fn new_with_caller(
|
fn new_with_caller(
|
||||||
value: T,
|
value: T,
|
||||||
#[cfg(debug_assertions)] caller: &'static Location<'static>,
|
#[cfg(debug_assertions)] caller: &'static std::panic::Location<'static>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: CopyValue::new_with_caller(
|
inner: CopyValue::new_with_caller(
|
||||||
|
|
Loading…
Add table
Reference in a new issue