3 ms·
If the compiler is using a niche, it should really check every assignment that it's not accidentally the niche. That's still faster than also writing the tag.
by tlb 2y ago
If the compiler is using a niche, it should really check every assignment that it's not accidentally the niche. That's still faster than also writing the tag.
- jenadine 2y agoIt doesn't need to check the assignment because that type cannot be the niche by construction.
- imtringued 2y agoThe problem is that you need to validate every potentially written niche after an unsafe block. There is no generic way to re-validate structs in a bounded address space. You'd need something akin to a garbage collector that traces references at fixed offsets including type knowledge. This is not completely infeasible since Rust has a lot of information at compile time to avoid checks, but the extreme cases where people are writing to complicated graph like structures inside unsafe {} can realistically only be dealt with through tracing all safe references that lie inside the bounded address space. In practice it will also be a struggle to sandbox C code into a small enough CHERI style address space so that you don't have to check literally your entire computer's memory after an FFI call. It's not the enums that are the problem. unsafe can break anything if you are determined enough.
- im3w1l 2y agoIsn't it the other way around? An unsafe block must respect niches.