Beingessner: Rust's Unsafe Pointer Types Need An Overhaul
Beingessner: Rust's Unsafe Pointer Types Need An Overhaul
Posted Mar 23, 2022 15:10 UTC (Wed) by farnz (subscriber, #17727)In reply to: Beingessner: Rust's Unsafe Pointer Types Need An Overhaul by uecker
Parent article: Beingessner: Rust's Unsafe Pointer Types Need An Overhaul
There are two important differences between Rust and C that make breaking changes in handling raw pointers more palatable on the Rust side:
- Use of raw pointers in Rust is already gated behind unsafe, and Rust style says to keep the use of unsafe to a minimum. This allows you to use data in papers like this ACM paper on Unsafe Rust to judge the maximum blast radius of changes - the data supports the idea that at most 25% of Rust code could be affected (as around 75% of published crates contain no Unsafe Rust), and that 3% of Rust code would be a good estimate of the amount of code affected by changes to raw pointers (about 10% of Unsafe Rust deals with raw pointers). In contrast, because of the nature of C, it's harder to tell how much C code is likely to be affected by any given change to pointer semantics.
- Rust's module system allows you to have maintained legacy code in an older edition and modern Rust in the same binary - I can link Rust 2015 code with Rust 2027 code, and the compiler will give the Rust 2015 code the semantics that went with Rust 2015, while giving me modern semantics for Rust 2027 code. #include in C means that I can't clearly delineate code that has modern semantics from code that doesn't, because some code has to have the "right" semantics whether it's #included into a compilation unit that has C99 semantics or whether it's #included into a compilation unit that has C27 semantics.
Of these, I think the former is the hard one to overcome; fixing the latter is something that can be done by a sufficiently smart C standard committee and compiler implementation team, while the former is about gathering statistics easily on which code might be affected.
