Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 5aaac4d

Browse files
committed
Run rustfmt
1 parent 66e5c91 commit 5aaac4d

File tree

10 files changed

+91
-92
lines changed

10 files changed

+91
-92
lines changed

liblumen_alloc/src/erts/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::mem;
33

44
use intrusive_collections::LinkedListLink;
55

6-
use super::{Term, TypedTerm, InvalidTermError};
6+
use super::{InvalidTermError, Term, TypedTerm};
77

88
#[derive(Debug)]
99
pub struct Message {

liblumen_alloc/src/erts/process/flags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::ops::{Not, BitOr, BitOrAssign, BitAnd, BitAndAssign};
1+
use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not};
22
use core::sync::atomic::{AtomicU32, Ordering};
33

44
/// This type provides an enum-like type with bitflag semantics,
@@ -16,7 +16,7 @@ impl ProcessFlag {
1616
pub const GrowHeap: Self = Self(1 << 1);
1717
/// This flag indicates that the next GC should be a full sweep unconditionally
1818
pub const NeedFullSweep: Self = Self(1 << 2);
19-
/// This flag indicates that the next GC check will always return `true`,
19+
/// This flag indicates that the next GC check will always return `true`,
2020
/// i.e. a collection will be forced
2121
pub const ForceGC: Self = Self(1 << 3);
2222
/// This flag indicates that GC should be disabled temporarily
@@ -151,4 +151,4 @@ mod tests {
151151
assert!(flags.is_set(ProcessFlag::NeedFullSweep));
152152
assert!(!flags.is_set(ProcessFlag::ForceGC));
153153
}
154-
}
154+
}

liblumen_alloc/src/erts/process/gc/collector.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use core::alloc::AllocErr;
22
use core::ptr;
33

4-
use log::trace;
54
use intrusive_collections::UnsafeRef;
5+
use log::trace;
66

77
use liblumen_core::util::pointer::{distance_absolute, in_area};
88

@@ -117,7 +117,9 @@ impl<'p> GarbageCollector<'p> {
117117
return Err(GcError::MaxHeapSizeExceeded);
118118
}
119119
// Unset heap_grow and need_fullsweep flags, because we are doing both
120-
self.process.flags.clear(ProcessFlag::GrowHeap | ProcessFlag::NeedFullSweep);
120+
self.process
121+
.flags
122+
.clear(ProcessFlag::GrowHeap | ProcessFlag::NeedFullSweep);
121123
// Allocate new heap
122124
let new_heap_start = alloc::heap(new_size).map_err(|_| GcError::AllocErr)?;
123125
let mut new_heap = YoungHeap::new(new_heap_start, new_size);
@@ -185,9 +187,15 @@ impl<'p> GarbageCollector<'p> {
185187
let heap_used = self.process.young.heap_used();
186188
let size_after = heap_used + stack_used + self.process.off_heap_size();
187189
if size_before >= size_after {
188-
trace!("Full sweep reclaimed {} words of garbage", size_before - size_after);
190+
trace!(
191+
"Full sweep reclaimed {} words of garbage",
192+
size_before - size_after
193+
);
189194
} else {
190-
trace!("Full sweep resulted in heap growth of {} words", size_after - size_before);
195+
trace!(
196+
"Full sweep resulted in heap growth of {} words",
197+
size_after - size_before
198+
);
191199
}
192200
// Determine if we oversized the heap and should shrink it
193201
let mut adjusted = false;

liblumen_alloc/src/erts/process/gc/old_heap.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use core::ptr;
21
use core::mem;
2+
use core::ptr;
33

44
use crate::erts::*;
55

@@ -161,7 +161,7 @@ impl OldHeap {
161161
// Sub-binaries are a little different, in that since we're garbage
162162
// collecting, we can't guarantee that the original binary will stick
163163
// around, and we don't necessarily want it to. Instead we create a new
164-
// heap binary (if within the size limit) that contains the slice of
164+
// heap binary (if within the size limit) that contains the slice of
165165
// the original binary that the sub-binary referenced. If the sub-binary
166166
// is too large to build a heap binary, then the original must be a ProcBin,
167167
// so we don't need to worry about it being collected out from under us
@@ -180,10 +180,7 @@ impl OldHeap {
180180
// Copy referenced part of binary to heap
181181
ptr::copy_nonoverlapping(bin_ptr, new_bin_ptr, bin_size);
182182
// Write heapbin header
183-
ptr::write(
184-
dst,
185-
HeapBin::from_raw_parts(bin_header, bin_flags),
186-
);
183+
ptr::write(dst, HeapBin::from_raw_parts(bin_header, bin_flags));
187184
// Write a move marker to the original location
188185
let marker = Term::from_raw(heap_top as usize | Term::FLAG_BOXED);
189186
ptr::write(orig, marker);

liblumen_alloc/src/erts/process/gc/virtual_heap.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use core::ptr;
55
use intrusive_collections::intrusive_adapter;
66
use intrusive_collections::{LinkedList, LinkedListLink, UnsafeRef};
77

8+
use super::{OldHeap, YoungHeap};
89
use crate::erts::*;
9-
use super::{YoungHeap, OldHeap};
1010

1111
intrusive_adapter!(pub ProcBinAdapter = UnsafeRef<ProcBin>: ProcBin { link: LinkedListLink });
1212

@@ -61,7 +61,9 @@ impl VirtualBinaryHeap {
6161
/// Returns true if the given pointer belongs to a binary on the virtual heap
6262
#[inline]
6363
pub fn contains<T>(&self, ptr: *const T) -> bool {
64-
self.bins.iter().any(|bin_ref| ptr == bin_ref as *const _ as *const T)
64+
self.bins
65+
.iter()
66+
.any(|bin_ref| ptr == bin_ref as *const _ as *const T)
6567
}
6668

6769
/// Adds the given `ProcBin` to the virtual binary heap

liblumen_alloc/src/erts/process/gc/young_heap.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl YoungHeap {
254254
// Sub-binaries are a little different, in that since we're garbage
255255
// collecting, we can't guarantee that the original binary will stick
256256
// around, and we don't necessarily want it to. Instead we create a new
257-
// heap binary (if within the size limit) that contains the slice of
257+
// heap binary (if within the size limit) that contains the slice of
258258
// the original binary that the sub-binary referenced. If the sub-binary
259259
// is too large to build a heap binary, then the original must be a ProcBin,
260260
// so we don't need to worry about it being collected out from under us
@@ -273,10 +273,7 @@ impl YoungHeap {
273273
// Copy referenced part of binary to heap
274274
ptr::copy_nonoverlapping(bin_ptr, new_bin_ptr, bin_size);
275275
// Write heapbin header
276-
ptr::write(
277-
dst,
278-
HeapBin::from_raw_parts(bin_header, bin_flags),
279-
);
276+
ptr::write(dst, HeapBin::from_raw_parts(bin_header, bin_flags));
280277
// Write a move marker to the original location
281278
let marker = Term::from_raw(heap_top as usize | Term::FLAG_BOXED);
282279
ptr::write(orig, marker);

liblumen_alloc/src/erts/term.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ pub use typed_term::*;
2828
//pub use map::*;
2929
pub use boxed::*;
3030

31+
use core::alloc::{AllocErr, Layout};
3132
use core::fmt;
3233
use core::ptr;
33-
use core::alloc::{Layout, AllocErr};
3434

3535
use super::ProcessControlBlock;
3636

@@ -105,16 +105,16 @@ impl crate::borrow::CloneToProcess for MapHeader {
105105
}
106106

107107
/// Constructs a binary from the given string, and associated with the given process
108-
///
108+
///
109109
/// For inputs greater than 64 bytes in size, the resulting binary data is allocated
110110
/// on the global shared heap, and reference counted (a `ProcBin`), the header to that
111111
/// binary is allocated on the process heap, and the data is placed in the processes'
112112
/// virtual binary heap, and a boxed term is returned which can then be placed on the stack,
113113
/// or as part of a larger structure if desired.
114-
///
114+
///
115115
/// For inputs less than or equal to 64 bytes, both the header and data are allocated
116116
/// on the process heap, and a boxed term is returned as described above.
117-
///
117+
///
118118
/// NOTE: If allocation fails for some reason, `Err(AllocErr)` is returned, this usually
119119
/// indicates that a process needs to be garbage collected, but in some cases may indicate
120120
/// that the global heap is out of space.
@@ -140,7 +140,8 @@ pub fn make_binary_from_str(process: &mut ProcessControlBlock, s: &str) -> Resul
140140
let header_ptr = process.alloc_layout(HeapBin::layout(s))?.as_ptr() as *mut HeapBin;
141141
// Pointer to start of binary data
142142
let bin_ptr = header_ptr.offset(1) as *mut u8;
143-
// Construct the right header based on whether input string is only ASCII or includes UTF8
143+
// Construct the right header based on whether input string is only ASCII or includes
144+
// UTF8
144145
let header = if s.is_ascii() {
145146
HeapBin::new_latin1(len)
146147
} else {
@@ -158,21 +159,24 @@ pub fn make_binary_from_str(process: &mut ProcessControlBlock, s: &str) -> Resul
158159
}
159160

160161
/// Constructs a binary from the given byte slice, and associated with the given process
161-
///
162+
///
162163
/// For inputs greater than 64 bytes in size, the resulting binary data is allocated
163164
/// on the global shared heap, and reference counted (a `ProcBin`), the header to that
164165
/// binary is allocated on the process heap, and the data is placed in the processes'
165166
/// virtual binary heap, and a boxed term is returned which can then be placed on the stack,
166167
/// or as part of a larger structure if desired.
167-
///
168+
///
168169
/// For inputs less than or equal to 64 bytes, both the header and data are allocated
169170
/// on the process heap, and a boxed term is returned as described above.
170-
///
171+
///
171172
/// NOTE: If allocation fails for some reason, `Err(AllocErr)` is returned, this usually
172173
/// indicates that a process needs to be garbage collected, but in some cases may indicate
173174
/// that the global heap is out of space.
174175
#[inline]
175-
pub fn make_binary_from_bytes(process: &mut ProcessControlBlock, s: &[u8]) -> Result<Term, AllocErr> {
176+
pub fn make_binary_from_bytes(
177+
process: &mut ProcessControlBlock,
178+
s: &[u8],
179+
) -> Result<Term, AllocErr> {
176180
let len = s.len();
177181
// Allocate ProcBins for sizes greater than 64 bytes
178182
if len > 64 {
@@ -190,10 +194,12 @@ pub fn make_binary_from_bytes(process: &mut ProcessControlBlock, s: &[u8]) -> Re
190194
} else {
191195
unsafe {
192196
// Allocates space on the process heap for the header + data
193-
let header_ptr = process.alloc_layout(HeapBin::layout_bytes(s))?.as_ptr() as *mut HeapBin;
197+
let header_ptr =
198+
process.alloc_layout(HeapBin::layout_bytes(s))?.as_ptr() as *mut HeapBin;
194199
// Pointer to start of binary data
195200
let bin_ptr = header_ptr.offset(1) as *mut u8;
196-
// Construct the right header based on whether input string is only ASCII or includes UTF8
201+
// Construct the right header based on whether input string is only ASCII or includes
202+
// UTF8
197203
let header = HeapBin::new(len);
198204
// Write header
199205
ptr::write(header_ptr, header);
@@ -203,19 +209,22 @@ pub fn make_binary_from_bytes(process: &mut ProcessControlBlock, s: &[u8]) -> Re
203209
let result = Term::from_raw(header_ptr as usize | Term::FLAG_BOXED);
204210
Ok(result)
205211
}
206-
}
212+
}
207213
}
208214

209215
/// Constructs a `Tuple` from a slice of `Term`
210-
///
216+
///
211217
/// Be aware that this does not allocate non-immediate terms in `elements` on the process heap,
212218
/// it is expected that the slice provided is constructed from either immediate terms, or
213219
/// terms which were returned from other constructor functions, e.g. `make_binary_from_str`.
214-
///
220+
///
215221
/// The resulting `Term` is a box pointing to the tuple header, and can itself be used in
216222
/// a slice passed to `make_tuple_from_slice` to produce nested tuples.
217223
#[inline]
218-
pub fn make_tuple_from_slice(process: &mut ProcessControlBlock, elements: &[Term]) -> Result<Term, AllocErr> {
224+
pub fn make_tuple_from_slice(
225+
process: &mut ProcessControlBlock,
226+
elements: &[Term],
227+
) -> Result<Term, AllocErr> {
219228
let len = elements.len();
220229
let layout = Tuple::layout(len);
221230
let tuple_ptr = unsafe { process.alloc_layout(layout)?.as_ptr() as *mut Tuple };
@@ -311,4 +320,4 @@ pub(crate) fn to_word_size(bytes: usize) -> usize {
311320
pub(crate) fn word_size_of<T: Sized>() -> usize {
312321
use core::mem;
313322
to_word_size(mem::size_of::<T>())
314-
}
323+
}

liblumen_alloc/src/erts/term/binary.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,7 @@ impl HeapBin {
431431

432432
#[inline]
433433
pub(in crate::erts) fn from_raw_parts(header: Term, flags: usize) -> Self {
434-
Self {
435-
header,
436-
flags,
437-
}
434+
Self { header, flags }
438435
}
439436

440437
/// Returns true if this binary is a raw binary
@@ -493,7 +490,8 @@ impl HeapBin {
493490
unsafe { Layout::from_size_align_unchecked(size, mem::align_of::<Term>()) }
494491
}
495492

496-
/// Get a `Layout` describing the necessary layout to allocate a `HeapBin` for the given byte slice
493+
/// Get a `Layout` describing the necessary layout to allocate a `HeapBin` for the given byte
494+
/// slice
497495
#[inline]
498496
pub fn layout_bytes(input: &[u8]) -> Layout {
499497
let size = mem::size_of::<Self>() + input.len();
@@ -650,11 +648,7 @@ impl SubBinary {
650648
///
651649
/// NOTE: You should not use this for any other purpose
652650
pub(crate) fn to_heapbin_parts(&self) -> Result<(Term, usize, *mut u8, usize), ()> {
653-
if self.bitsize == 0
654-
&& self.bitoffs == 0
655-
&& !self.writable
656-
&& self.size <= 64
657-
{
651+
if self.bitsize == 0 && self.bitoffs == 0 && !self.writable && self.size <= 64 {
658652
Ok(unsafe { self.to_raw_parts() })
659653
} else {
660654
Err(())
@@ -756,7 +750,7 @@ impl CloneToProcess for SubBinary {
756750
}
757751

758752
/// Represents a binary being matched
759-
///
753+
///
760754
/// See `ErlBinMatchBuffer` in `erl_bits.h`
761755
#[derive(Debug, Clone, Copy)]
762756
#[repr(C)]
@@ -772,7 +766,7 @@ pub struct MatchBuffer {
772766
}
773767
impl MatchBuffer {
774768
/// Create a match buffer from a binary
775-
///
769+
///
776770
/// See `erts_bs_start_match_2` in `erl_bits.c`
777771
#[inline]
778772
pub fn start_match(orig: Term) -> Self {
@@ -814,7 +808,7 @@ pub struct MatchContext {
814808
}
815809
impl MatchContext {
816810
/// Create a new MatchContext from a boxed procbin/heapbin/sub-bin
817-
///
811+
///
818812
/// See `erts_bs_start_match_2` in `erl_bits.c`
819813
#[inline]
820814
pub fn new(orig: Term) -> Self {

0 commit comments

Comments
 (0)