mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 07:49:17 +03:00
expand safety doc comment
This commit is contained in:
parent
6ebfcc8fa1
commit
8804b28be0
@ -121,9 +121,20 @@ impl<T> RocList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Marks a list as readonly. This means that it will be leaked.
|
||||
// For constants passed in from platform to application, this may be reasonable.
|
||||
// Marked unsafe because it should not be used lightly.
|
||||
/// Marks a list as readonly. This means that it will be leaked.
|
||||
/// For constants passed in from platform to application, this may be reasonable.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// A value can be read-only in Roc for 3 reasons:
|
||||
/// 1. The value is stored in read-only memory like a constant in the app.
|
||||
/// 2. Our refcounting maxes out. When that happens, we saturate to read-only.
|
||||
/// 3. This function is called
|
||||
///
|
||||
/// Any value that is set to read-only will be leaked.
|
||||
/// There is no way to tell how many references it has and if it is safe to free.
|
||||
/// As such, only values that should have a static lifetime for the entire application run
|
||||
/// should be considered for marking read-only.
|
||||
pub unsafe fn set_readonly(&self) {
|
||||
if let Some((_, storage)) = self.elements_and_storage() {
|
||||
storage.set(Storage::Readonly);
|
||||
|
@ -123,9 +123,20 @@ impl RocStr {
|
||||
}
|
||||
}
|
||||
|
||||
// Marks a str as readonly. This means that it will be leaked.
|
||||
// For constants passed in from platform to application, this may be reasonable.
|
||||
// Marked unsafe because it should not be used lightly.
|
||||
/// Marks a str as readonly. This means that it will be leaked.
|
||||
/// For constants passed in from platform to application, this may be reasonable.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// A value can be read-only in Roc for 3 reasons:
|
||||
/// 1. The value is stored in read-only memory like a constant in the app.
|
||||
/// 2. Our refcounting maxes out. When that happens, we saturate to read-only.
|
||||
/// 3. This function is called
|
||||
///
|
||||
/// Any value that is set to read-only will be leaked.
|
||||
/// There is no way to tell how many references it has and if it is safe to free.
|
||||
/// As such, only values that should have a static lifetime for the entire application run
|
||||
/// should be considered for marking read-only.
|
||||
pub unsafe fn set_readonly(&self) {
|
||||
match self.as_enum_ref() {
|
||||
RocStrInnerRef::HeapAllocated(roc_list) => unsafe { roc_list.set_readonly() },
|
||||
|
Loading…
Reference in New Issue
Block a user