18 Jul 2023 |
m4b | oh yea why don't i just option box | 06:02:40 |
m4b | hahaha | 06:02:43 |
m4b | you see my head has been stuck in this unsafe rust land last 5 hours, i just assumed it had to be raw pointers | 06:03:02 |
cwfitzgerald | I don't think I've ever actually directly used maybe uninit | 06:04:03 |
m4b | i have to look at it though, there might be a reason; it is super gnarly low level code | 06:04:07 |
cwfitzgerald | It mainly comes up in container implementations | 06:04:23 |
m4b | yea this is a container | 06:04:30 |
cwfitzgerald | https://doc.rust-lang.org/nomicon/unchecked-uninit.html might be worth a read | 06:05:39 |
m4b | yes yes | 06:05:51 |
cwfitzgerald | (similarly their section on impling Vec | 06:06:13 |
m4b | that section is literally what i was doing | 06:06:32 |
m4b | almost verbatim taken; the problem i had was i had a final leak when deallocating the entire thing; and i had no real way to know which things were allocated or not (Box not being null (even using std::mem::zeroed is a compile time error now!)) | 06:07:49 |
m4b | i could deallocate them when particular elements were removed, but if you just dropped the whole thing, anything that wasn't explicitly removed was leaked | 06:08:19 |
cwfitzgerald | You're making a vec box T basically? | 06:10:01 |
m4b | they're like chunks of arrays of recursive nested arrays of boxes that are dynamic, yes | 06:10:48 |
cwfitzgerald | Whosy what a what | 06:11:19 |
m4b | each child has a mask group, and this extra control information determines what goes in where, and if it's 0, they get deallocated | 06:11:28 |
cwfitzgerald | Oh I think I know what you're getting at | 06:11:51 |
cwfitzgerald | Can't you look at the mask info to know when to drop things? | 06:12:09 |
m4b | i thought about doing that but i wrote this code like 3 years ago and i'd have to reverse engineer the masking stuff; it felt easier to just check if the allocated things were 0 (or None, now) | 06:12:56 |
m4b | i feel like i was on drugs or something when i wrote it, i don't even recognize this strange persons writing :P | 06:13:19 |
cwfitzgerald | Probably not worth the bother anyway | 06:13:51 |
cwfitzgerald | Cpus churn through branches like nobody's business | 06:14:06 |
m4b | well its still a branch anyway looking up the child information, right? so i figured it shouldn't matter much. i'm actually more worried about the branching on accesses with unwrap now | 06:14:56 |
m4b | #[inline(always)]
fn set_mask(storage: &mut [u32], i: usize, x: bool) {
const BITS_U32: usize = 32;
let w = i / BITS_U32;
let b = i % BITS_U32;
let flag = 1 << b;
// i believe we can unsafe access due to i being shifted internally
let val = if x {
storage[w] | flag
} else {
storage[w] & !flag
};
storage[w] = val;
}
like this is the masking code, wtf, i don't even know; i'd have to invert this and get a list of children mapping to the array indexes, seems like a lot of trouble
| 06:16:08 |
cwfitzgerald | In reply to @m4b:matrix.org well its still a branch anyway looking up the child information, right? so i figured it shouldn't matter much. i'm actually more worried about the branching on accesses with unwrap now Unwrap_unchecked? | 06:20:05 |
m4b | for someone who says they don't write any unsafe, you sure do seem to know some unsafe stuff 😆 | 06:20:44 |
cwfitzgerald | I said I don't use maybeuninit :) | 06:21:10 |
m4b | ah | 06:21:24 |
m4b | i'm more of a transmute kind of person anyway :P | 06:21:37 |