You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are mutliple uses of unsafe that can be either replaced with safe code or with an external crate. I propose using this issue to discuss these cases and then document in the code why each unsafe is fine. This makes code review much easier.
Transmutes to enums. Totally fine although the compiler generates the same assembly for safe match statements.
Custom TranspositionTable that allows to trigger undefined behaviour from safe code (if I understand the code correctly):
let tt = TranspositionTable::new_num_entries(40000);let prng = PRNG::init(932445561);let key:u64 = prng.rand();let(found1, entry1):(bool,&mutEntry) = tt.probe(key);let(found2, entry2) = tt.probe(key);// second mutable reference to the same object -> UB
I did not look into the usecases yet. There are probably alternatives available in the ecosystem.
Custom TimeManager: Internals can be replaced with atomics and Ordering::Relaxed load/store (although the Instance might be problematic). Also: do not create mutable references from UnsafeCell in unguarded code but use ptr::write to avoid UB.
There are mutliple uses of unsafe that can be either replaced with safe code or with an external crate. I propose using this issue to discuss these cases and then document in the code why each unsafe is fine. This makes code review much easier.
match
statements.Arc
without weak counter fromservo_arc
. The discussion to include this instd
died here. Why not use the crate? The currently published version has possible UB Currently-published servo_arc contains undefined behavior servo/servo#26358TranspositionTable
that allows to trigger undefined behaviour from safe code (if I understand the code correctly):I did not look into the usecases yet. There are probably alternatives available in the ecosystem.
TimeManager
: Internals can be replaced with atomics andOrdering::Relaxed
load/store (although theInstance
might be problematic). Also: do not create mutable references fromUnsafeCell
in unguarded code but use ptr::write to avoid UB.I am quite sure that the compiler will elide the bound checks. Another possibility is to use enum_map or static asserts.
static mut
and replace it either with lazy_static or with const fn initialization. https://github.com/sfleischman105/Pleco/blob/292d38e78dd7d82112aef79a379e8329707e3659/pleco_engine/src/tables/pawn_table.rs#L82MoveList
.mem::uninitialized
to gether with an enum that encodes if a field is used or not. Is there a reason that this is arepr(u8)
enum instead of carrying the data itself? https://github.com/sfleischman105/Pleco/blob/292d38e78dd7d82112aef79a379e8329707e3659/pleco_engine/src/movepick/mod.rs#L64The text was updated successfully, but these errors were encountered: