LWN: Comments on "Rust for Linux redux" https://lwn.net/Articles/862018/ This is a special feed containing comments posted to the individual LWN article titled "Rust for Linux redux". en-us Thu, 16 Oct 2025 09:31:11 +0000 Thu, 16 Oct 2025 09:31:11 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net "anything moved from Rust into C++" https://lwn.net/Articles/865931/ https://lwn.net/Articles/865931/ tialaramex <div class="FormattedComment"> <font class="QuotedText">&gt; which is why I&#x27;d assume it is `FnMut`: so it can &quot;remember&quot; such things</font><br> <p> I expect it&#x27;s FnMut because the standard advice is to choose callable trait bounds in order of preference: FnOnce, FnMut, Fn. By using the broadest bounds in this case, and the narrowest bounds when writing functions or closures, you promote re-usability.<br> <p> Since we can expect to call this more than once FnOnce isn&#x27;t viable, so FnMut is next best. However although I did write an implementation to check it&#x27;s actually possible to implement e.g. a closure that matches various couples kissing in Unicode but not anything else it was rather awkward to do this, and I don&#x27;t anticipate such uses predominating. Instead I expect that once Pattern stabilizes people will write adaptors to make Patterns out of other things you could plausibly want.<br> </div> Wed, 11 Aug 2021 02:14:01 +0000 Rust for Linux redux https://lwn.net/Articles/864550/ https://lwn.net/Articles/864550/ mkru <div class="FormattedComment"> Compiling for platforms with and without CheriABI still will be possible.<br> The old hardware will be replaced by the new one, probably slowly, but still, it will.<br> I guess you mean that people with older hardware want to be sure that they kernel is safe.<br> As Linux is considering adding Rust as the second language, I guess someone has counted how many bugs it would help to avoid in the last X years.<br> Does anyone know where such report is available?<br> </div> Thu, 29 Jul 2021 05:18:10 +0000 Rust for Linux redux https://lwn.net/Articles/864527/ https://lwn.net/Articles/864527/ mpr22 <div class="FormattedComment"> Remember that even once devices with CHERI support enter the market, there will remain a large installed base of non-CHERI devices that people want to run the Linux kernel on.<br> </div> Wed, 28 Jul 2021 18:42:14 +0000 "anything moved from Rust into C++" https://lwn.net/Articles/864473/ https://lwn.net/Articles/864473/ mathstuf <div class="FormattedComment"> Agh. I got terms confused. `u8` is the &quot;code unit&quot; of UTF-8. Yes, scalars are code points. *face palm*<br> <p> <font class="QuotedText">&gt; (But I believe you&#x27;re right that what a human would perceive as &quot;a character&quot; is what Unicode calls an extended grapheme cluster, which is (confusingly) a sequence of Rust chars. The name &quot;char&quot; seems like a bad decision by Rust - e.g. Go uses &quot;rune&quot; as the type for code points, which is a bit weird but is much less misleading. And Rust doesn&#x27;t natively handle grapheme clusters at all, you need a third-party crate for that, unlike e.g. Swift where String is defined as a sequence of Characters and Character is defined as a grapheme cluster (and you have to use non-default APIs if you want access to a String&#x27;s Unicode Scalar Values or its UTF-8 code units).)</font><br> <p> I think Rust got it right keeping grapheme clusters out of the language proper. What sequence of code points constitutes a grapheme cluster changes from standard to standard as new codepoints and rules for combining are added. For example, `&lt;person&gt;&lt;join&gt;&lt;heart&gt;&lt;join&gt;&lt;person&gt;` is now a single grapheme cluster, but wasn&#x27;t in older versions of Unicode. Unless languages are tacking on `Unicode_12_0` on their `grapheme_length()` methods, it means that as the language updates its tables for newer standards, these methods can change their minds depending on what combinations are newly allowed.<br> <p> Yes, `char` is not the greatest name, `upoint` may have been better (as `unicode_point` is too long). However, I think `rune` is also poor since that brings to my mind &quot;grapheme (cluster)&quot; more than &quot;code point&quot;.<br> </div> Wed, 28 Jul 2021 14:01:35 +0000 "anything moved from Rust into C++" https://lwn.net/Articles/864471/ https://lwn.net/Articles/864471/ excors <div class="FormattedComment"> <font class="QuotedText">&gt; Just to nitpick, `u8` is the UTF-8 scalar (the smallest unit of the data stream). Rust&#x27;s `char` is a codepoint (which may have come from multiple scalars).</font><br> <p> Just to nitpick further, I think that&#x27;s entirely wrong :-) . The Rust documentation says char is a Unicode Scalar Value, which Unicode defines as &quot;Any Unicode code point except high-surrogate and low-surrogate code points&quot;, i.e. it&#x27;s not the same as a code point. And u8 is not a specifically UTF-8 type - it&#x27;s just an unsigned 8-bit integer, which happens to match the definition of a UTF-8 code unit (which nobody ever calls a &quot;UTF-8 scalar&quot;).<br> <p> (But I believe you&#x27;re right that what a human would perceive as &quot;a character&quot; is what Unicode calls an extended grapheme cluster, which is (confusingly) a sequence of Rust chars. The name &quot;char&quot; seems like a bad decision by Rust - e.g. Go uses &quot;rune&quot; as the type for code points, which is a bit weird but is much less misleading. And Rust doesn&#x27;t natively handle grapheme clusters at all, you need a third-party crate for that, unlike e.g. Swift where String is defined as a sequence of Characters and Character is defined as a grapheme cluster (and you have to use non-default APIs if you want access to a String&#x27;s Unicode Scalar Values or its UTF-8 code units).)<br> </div> Wed, 28 Jul 2021 13:36:43 +0000 Rust for Linux redux https://lwn.net/Articles/864468/ https://lwn.net/Articles/864468/ mkru <div class="FormattedComment"> I am not a kernel developer, but I have written a few simple drivers. <br> I am wondering whether adding Rust to the kernel is really the best approach for achieving memory safety.<br> There is (maybe are?) other alternative solution that is not yet available, but is on the horizon and seems to be much more inline with the C and how OS&#x27;es are implemented.<br> Namely, the CheriABI.<br> <p> Rust is relatively complex language, adding it to the kernel will greatly increase cognitive complexity.<br> Imagine 2 alternative scenarios:<br> 1. C + compiler warnings + CheriABI + a larger number of potential reviewers.<br> 2. Rust.<br> <p> How many errors/vulnerabilities can 2 help to avoid comparing to 1?<br> Is anyone able to estimate this?<br> Is greatly increasing the complexity still worth?<br> <p> <a rel="nofollow" href="https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/">https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/</a><br> <a rel="nofollow" href="https://dl.acm.org/doi/10.1145/3297858.3304042">https://dl.acm.org/doi/10.1145/3297858.3304042</a><br> <a rel="nofollow" href="https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/20210507-dsbd-cheri-morello.pdf">https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/202...</a><br> <p> </div> Wed, 28 Jul 2021 13:11:10 +0000 "anything moved from Rust into C++" https://lwn.net/Articles/864470/ https://lwn.net/Articles/864470/ mathstuf <div class="FormattedComment"> <font class="QuotedText">&gt; a particular Unicode scalar (approximately a single code point, so a Poop emoji or the capital A, but not a flag or two women kissing) is a match that&#x27;ll let you ask whether a string.contains(it) or string.ends_with(it) or just to string.find(it) and these all work today.</font><br> <p> Just to nitpick, `u8` is the UTF-8 scalar (the smallest unit of the data stream). Rust&#x27;s `char` is a codepoint (which may have come from multiple scalars). What users see as a single grapheme (or grapheme cluster) may have come from multiple codepoints (including flags or the &quot;two+ people&quot; emoji). So that pattern function can &quot;see&quot; `A` alone, but is going to see a decomposed `á` as `a` and a combining character since it is two codepoints (which is why I&#x27;d assume it is `FnMut`: so it can &quot;remember&quot; such things).<br> </div> Wed, 28 Jul 2021 12:57:40 +0000 Rust for Linux redux https://lwn.net/Articles/864464/ https://lwn.net/Articles/864464/ tialaramex <div class="FormattedComment"> In the end I don&#x27;t think I&#x27;d want it here because you are making several of them but rarely need the actual type, but arguably<br> <p> type Block = [u8; BLOCK_LEN];<br> <p> makes it clearer since that&#x27;s in fact what this is, and then:<br> <p> let mut parents_array = ArrayVec::&lt;&amp;Block, MAX_SIMD_DEGREE_OR_2&gt;::new();<br> <p> ... feels like a pretty reasonable type, it&#x27;s an ArrayVec of references to Blocks, right you are. Const generics helped more though.<br> </div> Wed, 28 Jul 2021 03:53:01 +0000 "anything moved from Rust into C++" https://lwn.net/Articles/864462/ https://lwn.net/Articles/864462/ tialaramex <div class="FormattedComment"> Why would such a claim &quot;make all subsequent statements suspect&quot; when it seems to be a very reasonable position?<br> <p> The shortest path wouldn&#x27;t be through Rust, but lots of key C++ people have exposure to stuff that they could in principle have seen somewhere else earlier but ended up learning in Rust because of Rust&#x27;s popularity.<br> <p> Take P2216. Rather modestly this proposal suggested that, since languages such as Rust treat nonsensical formats as a compile time error, rather than waiting until your code runs before inevitably complaining that the format is nonsense C++ could match the state of the art in this area and refuse to compile the program.<br> <p> Did Rust _invent_ this practice? No of course not. But, in C++ 20 (as originally shipped) the nonsense compiled, and in Rust it did not, the author and Library Evolution Working Group both saw that this is obviously superior, and so it was accepted for C++ 23 and &quot;backported&quot; into the standard library specification. P2216 doesn&#x27;t try to find out historically which postgraduate student first wrote a program that could do this, perhaps in 1985 in Lisp, it just points out that today Rust is a popular language that gets this right and C++ should join it.<br> <p> Or P1679. Once again, Rust doesn&#x27;t take centre stage here, the author merely acknowledges that &quot;Bananas&quot;.contains(&quot;nanas&quot;) exists in Rust† whereas in C++ you were expected to construct a string or string_view and then run find(&quot;nanas&quot;) and confirm the result is npos. Which, if you come from any language (not just Rust) with &quot;Bananas&quot;.contains(&quot;nanas&quot;) seems silly. Why am I paying the cognitive price of a find method I don&#x27;t need when all I wanted to do was check whether one thing is contained in another ?<br> <p> † Behind the scenes something clever is happening here. Today the C++ 23 feature is a bunch of overloads on string and string_view and so on. But the Rust feature isn&#x27;t, it&#x27;s relying on an (unstable for now) Trait named std::str::pattern::Pattern. If a future standard C++ adds any more things you might reasonably expect to be parameters for string.contains() they&#x27;ll be additional overloads. That isn&#x27;t inherited by your own string-like classes, you too will need to add the overloads explicitly, likewise if you currently add overloads to string.find() for your own needs, you&#x27;ll want to add the same overloads to string.contains() for symmetry.<br> <p> But thanks to Pattern in Rust both those things happen for free when you simply use Pattern. For example Rust already provided an implementation of Pattern for any F: FnMut(char) -&gt; bool -- and so, if you write any function or closure that can decide whether a particular Unicode scalar (approximately a single code point, so a Poop emoji or the capital A, but not a flag or two women kissing) is a match that&#x27;ll let you ask whether a string.contains(it) or string.ends_with(it) or just to string.find(it) and these all work today.<br> </div> Wed, 28 Jul 2021 03:36:41 +0000 Footguns https://lwn.net/Articles/864401/ https://lwn.net/Articles/864401/ farnz <p>Different to taint mode - taint in Perl attaches to data, not operations. Perl's taint says "this data is from the user and therefore untrusted until sanitised" (even if minimally sanitised). Rust's unsafe says "this operation has human-checked invariants that can result in UB if not correctly checked". <p>You can implement Perl's taint system easily in Rust, with a <tt>struct Tainted&lt;T&gt;(T)</tt> expressing that it holds tainted data, and some way to extract the tainted data and feed it back to the rest of the program. You can't implement <tt>unsafe</tt> easily in Perl 5, because Perl does not have the same ability to represent a function that breaks the abstract machine's invariants if misapplied. Tue, 27 Jul 2021 13:40:06 +0000 Footguns https://lwn.net/Articles/864393/ https://lwn.net/Articles/864393/ flussence <div class="FormattedComment"> But that&#x27;s just a thing akin to Perl&#x27;s taint mode, right? I wouldn&#x27;t call it a new capability.<br> </div> Tue, 27 Jul 2021 13:14:36 +0000 Rust for Linux redux https://lwn.net/Articles/864352/ https://lwn.net/Articles/864352/ mathstuf <div class="FormattedComment"> Yes, that was the &quot;mergable PEP&quot; I was referring to. Weren&#x27;t there prior attempts for similar things that went nowhere or am I crossing signals in my memory?<br> </div> Mon, 26 Jul 2021 16:23:57 +0000 Rust for Linux redux https://lwn.net/Articles/864299/ https://lwn.net/Articles/864299/ oconnor663 <div class="FormattedComment"> Hi, I wrote that code. So here&#x27;s a bunch of Rust details that no one asked for :) This is the starting example (<a rel="nofollow" href="https://github.com/BLAKE3-team/BLAKE3/blob/0.1.0/src/lib.rs#L491">https://github.com/BLAKE3-team/BLAKE3/blob/0.1.0/src/lib....</a>):<br> <p> let mut parents_array = ArrayVec::&lt;[&amp;[u8; BLOCK_LEN]; MAX_SIMD_DEGREE_OR_2]&gt;::new();<br> <p> A couple pieces of punctuation in that example comes from the fact that prior to the release of Rust 1.51 this March, Rust didn&#x27;t properly support const generics. So types like ArrayVec needed to work around that with shenanigans. But now that we do have const generics and an updated version of ArrayVec, the code looks like this (<a rel="nofollow" href="https://github.com/BLAKE3-team/BLAKE3/blob/1.0.0/src/lib.rs#L637">https://github.com/BLAKE3-team/BLAKE3/blob/1.0.0/src/lib....</a>):<br> <p> let mut parents_array = ArrayVec::&lt;&amp;[u8; BLOCK_LEN], MAX_SIMD_DEGREE_OR_2&gt;::new();<br> <p> That is, an &quot;ArrayVec of at most MAX_SIMD_DEGREE_OR_2 elements, each of type &#x27;reference to a byte array of length BLOCK_LEN&#x27;&quot;. One interesting thing to notice here is that the element type is actually optional. This will also compile (and would have in v0.1.0 too):<br> <p> let mut parents_array = ArrayVec::&lt;_, MAX_SIMD_DEGREE_OR_2&gt;::new();<br> <p> That is, an &quot;ArrayVec of at most MAX_SIMD_DEGREE_OR_2 elements, each of some type that&#x27;s deduced by the compiler.&quot; I chose to write the full type out explicitly, because this is highly optimized code doing tricky things, and I think this version is actually easier to understand for someone who&#x27;s familiar with Rust. But opinions can definitely differ here.<br> <p> Another thing to think about is that in C, this might have been just &quot;char**&quot;. What all this extra typing is buying us in Rust, is that the function is 100% memory safe. (It&#x27;s going to call some SIMD code that isn&#x27;t, but ignore that for now.) Even though the ArrayVec is variable-length, it&#x27;s still allocated on the stack, and pushes into it are guaranteed to panic rather than overrunning its stack footprint. The array pointers inside it are also length checked during construction by array_ref!() in the code below. (Which I would probably replace with standard .try_into() if I was refactoring this code today.)<br> <p> Another source of punctuation woes in Rust is lifetime annotations. I think it&#x27;s interesting to notice that we don&#x27;t see any of those here. The compiler doesn&#x27;t need any help to figure out that parents_array is scoped to the current function, so putting array pointers inside of it isn&#x27;t going to cause problems. But if we wanted to say return that array, we would need explicit lifetime annotations in the function signature in this case.<br> </div> Mon, 26 Jul 2021 14:21:52 +0000 Rust for Linux redux https://lwn.net/Articles/864287/ https://lwn.net/Articles/864287/ smurf <div class="FormattedComment"> <font class="QuotedText">&gt; Pattern-matching […] (or into a mergable PEP for Python for that matter).</font><br> <p> Huh? PEP 634 has been merged into what&#x27;s going to be 3.10 since February 26th, commit 145bf26.<br> </div> Mon, 26 Jul 2021 08:01:19 +0000 Rust for Linux redux https://lwn.net/Articles/864268/ https://lwn.net/Articles/864268/ mathstuf <div class="FormattedComment"> <font class="QuotedText">&gt; The code can be found here: <a href="https://docs.rs/blake3/0.1.0/src/blake3/lib.rs.html">https://docs.rs/blake3/0.1.0/src/blake3/lib.rs.html</a> which is the official implementation of BLAKE3 in Rust. Take of that what you will. We will see what kind of Rust code you are going to find in the Linux kernel.</font><br> <p> Hmm. Well, I found `parents_array` at least. Not *quite* sure why it needs to be specified there (possibly the length?), but type aliases would certainly make it much more readable IMO.<br> <p> As for `input_ptrs`, that is deep in AVX2 code…so yeah, that&#x27;s probably going to get a bit hairy (and, indeed, has a comment about its safety).<br> <p> Either way, given the *other* restrictions on code such as this, it&#x27;s not where I&#x27;d look for &quot;normal&quot; Rust code (unless I was coding up replacements for the sections doing similar machinations in the kernel today).<br> <p> <font class="QuotedText">&gt; Perhaps a recent one would have served you better, then.</font><br> <p> I used the post you linked to… Which, FWIW, I had actually read in the last week, though I missed that it was from 2019 (IIRC, it was from a link on HN or somewhere). Either case, yes, Ada is older than Rust. I&#x27;m not doubting that. I&#x27;m doubting the &quot;Ada finally has pointers!&quot; would have happened without Rust showing how to do lifetime tracking without runtime overhead:<br> <p> <font class="QuotedText">&gt; I think it was work on the ParaSail language, and the emergence of the Rust language, that first made us look again into supporting this feature. Pointer ownership models did not appear explicitly within Rust, but Rust made the restrictions associated with them look tractable, and maybe even desirable from a safety point of view.</font><br> <p> makes it seem like Rust is what made the SPARK team look at doing more rigorous pointer lifetime analysis. Later:<br> <p> <font class="QuotedText">&gt; But this is not great, as now I have a memory leak. Indeed, the value previously stored in My_Dictionary is no longer accessible and it has not been deallocated. The SPARK tool does not currently complain about this problem, even though the SPARK definition says it should (it has not been implemented yet).</font><br> <p> <font class="QuotedText">&gt; But this is not supported yet by the proof tool, as it raises the complex issue of tracking modifications of X that were done through Y during its lifetime:</font><br> <p> So maybe these things are complete, but links to further progress would be helpful.<br> </div> Sun, 25 Jul 2021 20:45:12 +0000 Rust for Linux redux https://lwn.net/Articles/864262/ https://lwn.net/Articles/864262/ mpr22 <div class="FormattedComment"> Looking at both of those things for a few minutes:<br> <p> It appears that the Ada Kernel Module Framework only exists as a proof of concept, and has not been the target of any publicly visible work in the original github repository or the two visible github forks.<br> <p> EwoK looks like it may well be quite an interesting project, but it&#x27;s 100% its own thing and nothing to do with the Linux kernel.<br> </div> Sun, 25 Jul 2021 19:28:32 +0000 Rust for Linux redux https://lwn.net/Articles/864257/ https://lwn.net/Articles/864257/ joshc <div class="FormattedComment"> A quick search tells me that such a thing exists for Ada.<br> <p> Source code: <a rel="nofollow" href="https://github.com/alkhimey/Ada_Kernel_Module_Framework">https://github.com/alkhimey/Ada_Kernel_Module_Framework</a><br> Blog posts can be found here: <a rel="nofollow" href="http://www.nihamkin.com/tag/kernel.html">http://www.nihamkin.com/tag/kernel.html</a><br> <p> I do not believe that it uses SPARK though. You might want to check out https://wookey-project.github.io/ewok/ada_spark.html for something like that.<br> </div> Sun, 25 Jul 2021 18:19:33 +0000 Rust for Linux redux https://lwn.net/Articles/864256/ https://lwn.net/Articles/864256/ Coconut <div class="FormattedComment"> Thanks, that answers my question.<br> </div> Sun, 25 Jul 2021 18:19:20 +0000 Rust for Linux redux https://lwn.net/Articles/864255/ https://lwn.net/Articles/864255/ Coconut <div class="FormattedComment"> <font class="QuotedText">&gt; Neither of these look like idiomatic code at all.</font><br> <p> The code can be found here: <a rel="nofollow" href="https://docs.rs/blake3/0.1.0/src/blake3/lib.rs.html">https://docs.rs/blake3/0.1.0/src/blake3/lib.rs.html</a> which is the official implementation of BLAKE3 in Rust. Take of that what you will. We will see what kind of Rust code you are going to find in the Linux kernel.<br> <p> <font class="QuotedText">&gt; Interesting how &quot;cannot store pointers in structures&quot; is considered suitable for &quot;no longer an issue&quot; in something like the kernel. That is still under active research and/or implementation by my reading of that post.</font><br> <p> Perhaps a recent one would have served you better, then.<br> <p> <font class="QuotedText">&gt; so how would that have worked out before Rust came onto the scene?</font><br> <p> How can you comment on this and the previous one with so much certainty if you have seemingly have not done your research? I obviously omitted a lot of information on Ada/SPARK. I am not supposed to sell it to you. That is not the point of the comment. I just wanted to know if Ada has been ever considered given that it is *perfectly suitable* for kernel development and is actually more safe than Rust (yes, it actually is, perhaps go through all of my links, then). To answer your question: they were actually working on it before Rust.<br> <p> <font class="QuotedText">&gt; I think the Linux kernel is about as interested in crates.io as they are about PyPI.</font><br> <p> I mentioned it because it is a common reaction from people that &quot;Ada is not modern, it does not even have a package manager!&quot;.<br> </div> Sun, 25 Jul 2021 18:19:15 +0000 Rust for Linux redux https://lwn.net/Articles/864253/ https://lwn.net/Articles/864253/ mathstuf <div class="FormattedComment"> I suspect you&#x27;re talking about the standards level, but implementations have definitely been paying attention (see the MSVC post in the sibling comment). However, to say that Rust is not exerting some pressure on C++ is to ignore what is happening.<br> <p> The epochs proposal[1] was directly inspired by Rust&#x27;s edition mechanism to allow for syntactic evolution of the language without breaking everything. Unfortunately, C++ has semantics tied too tightly to the syntax that even deprecating `0` or `NULL` for `nullptr` is a no-go due to ADL, type coercion, and confused template rules. While it&#x27;d be a nice thing to be able to bundle up terrible promotion rules to specific modules, the way that templates expand mean that you need to decide whether to evaluate them with the declaration&#x27;s epoch rules or the instantiator&#x27;s epoch rules because concepts care quite a bit about whether specific syntactic constructions are valid. Getting implementations to warn &quot;under epoch X, we find that type deduction and ADL take a different path because `0` no longer converts to `T*` silently&quot; is not something anyone is going to want to handle. Either &quot;no one&quot; updates to the new epoch because their codebase is not clean under `clang-tidy`&#x27;s &quot;modernize-*&quot; lints or only new code uses it because it&#x27;s an error for them anyways.<br> <p> Pattern-matching calls out Rust as a language to compare C++&#x27;s proposals against and is also called out for how to issue warnings due to incomplete matching. Pattern matching has been around since &quot;forever&quot; with various ML languages, but I wouldn&#x27;t be surprised if Rust&#x27;s success with it was the &quot;oomph&quot; that ignited the interest of it enough to actually get it in front of the committee for C++ (or into a mergable PEP for Python for that matter).<br> <p> I&#x27;m sure there are other Rust-inspired proposals around, but I suspect a number of them are in the library track (which I don&#x27;t have time to follow).<br> <p> [1] <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1881r1.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p...</a><br> </div> Sun, 25 Jul 2021 13:49:17 +0000 Rust for Linux redux https://lwn.net/Articles/864251/ https://lwn.net/Articles/864251/ mathstuf <div class="FormattedComment"> <font class="QuotedText">&gt; Have they considered Ada/SPARK?</font><br> <p> The Linux kernel was not &quot;seeking&quot; a new language to add. Developers did the work and showed how Rust could be used in it and *then* came to the kernel. Where was this done for Ada/SPARK for &quot;them&quot; to consider?<br> <p> <font class="QuotedText">&gt; let mut parents_array = ArrayVec::&lt;[&amp;[u8; BLOCK_LEN]; MAX_SIMD_DEGREE_OR_2]&gt;::new()</font><br> <font class="QuotedText">&gt; let input_ptrs: &amp;[*const u8; DEGREE] = &amp;*(inputs.as_ptr() as *const [*const u8; DEGREE]);</font><br> <p> Sure, syntactically, all kinds of abominations are possible. Crafting a grammar to only accept &quot;beautiful&quot; code is likely a doomed endeavour for any &quot;useful&quot; language. Neither of these look like idiomatic code at all. The former because the type is probably deduced elsewhere by what APIs accept `parents_array` (or, if not, that `[u8; BLOCK_LEN]` deserves its own type name; as does the `MAX_SIMD_DEGREE_OR_2`-sized array) so you end up with either:<br> <p> let mut parents_array = ArrayVec::new();<br> // parents_array.push(&amp;simd_blocks); // type deduced here<br> <p> or:<br> <p> let mut parents_array = ArrayVec::&lt;SimdBlockRefs&gt;::new();<br> <p> The latter `input_ptrs` is not idiomatic because it is desperately in need of an `unsafe` specifier and a comment describing what it does is safe. Slinging around an array of pointers is also not very Rust-like. The need for casts on the right and left side is also just weird…type deduction should make the left-hand type unnecessary (ignoring the unsafe-ness being presented).<br> <p> <font class="QuotedText">&gt; Plus, pointers are no longer an issue either: <a href="https://blog.adacore.com/using-pointers-in-spark.">https://blog.adacore.com/using-pointers-in-spark.</a></font><br> <p> Interesting how &quot;cannot store pointers in structures&quot; is considered suitable for &quot;no longer an issue&quot; in something like the kernel. That is still under active research and/or implementation by my reading of that post. And, without Rust, Ada/SPARK might still be without pointers, so how would that have worked out before Rust came onto the scene?<br> <p> <font class="QuotedText">&gt; I would also like to add, that Ada has a package manager as well, namely Alire</font><br> <p> I think the Linux kernel is about as interested in crates.io as they are about PyPI. Handy, but almost zero code there is suitable for usage in the kernel&#x27;s context (except for usage in build-time or other useful tools *related* to the kernel).<br> </div> Sun, 25 Jul 2021 13:34:10 +0000 Rust for Linux redux https://lwn.net/Articles/864249/ https://lwn.net/Articles/864249/ rahulsundaram <div class="FormattedComment"> <font class="QuotedText">&gt; To suggest that anything moved from Rust into C++ makes all subsequent statements suspect, thus &gt;probably not even worth reading.</font><br> <p> <a href="https://devblogs.microsoft.com/cppblog/new-safety-rules-in-c-core-check/">https://devblogs.microsoft.com/cppblog/new-safety-rules-i...</a><br> <p> &quot;C++ often falls behind Rust when it comes to programming safety. Visual Studio 2019 version 16.7 contains four new rules in C++ Core Check to incorporate some safety features from Rust into C++.&quot;<br> </div> Sun, 25 Jul 2021 12:32:26 +0000 Rust for Linux redux https://lwn.net/Articles/864242/ https://lwn.net/Articles/864242/ mpr22 <div class="FormattedComment"> <font class="QuotedText">&gt; Check them out. After you are done, can you tell me why Rust over Ada/SPARK?</font><br> <p> Because Rust advocates were willing to do the work (including the non-technical work of persuading the likes of Linus and Greg that their proposal is worthy of consideration at all), and Ada/SPARK advocates have apparently not been willing to do the work.<br> <p> Of course, I&#x27;d be surprised if the average Ada/SPARK advocate was interested in touching the Linux kernel in the first place (at least without a hazmat suit and long-handled tongs).<br> </div> Sun, 25 Jul 2021 09:47:47 +0000 Rust for Linux redux https://lwn.net/Articles/864233/ https://lwn.net/Articles/864233/ ncm <div class="FormattedComment"> To suggest that anything moved from Rust into C++ makes all subsequent statements suspect, thus probably not even worth reading.<br> <p> Especially, C++ Concepts predate even the first proposal of Rust as a project.<br> </div> Sun, 25 Jul 2021 02:54:17 +0000 Rust for Linux redux https://lwn.net/Articles/864230/ https://lwn.net/Articles/864230/ Coconut <div class="FormattedComment"> Have they considered Ada/SPARK? If they did, why did they decide against it and pick Rust over it? Ada/SPARK provides all the safety Rust does without sacrificing performance, and it provides even more! Its type system is great. You can have pre- and post-conditions. You can have ranged integer types. You can eliminate runtime errors and prove correctness of your code through formal verification. Just take a look at projects from <a rel="nofollow" href="https://github.com/Componolit">https://github.com/Componolit</a>. Plus, pointers are no longer an issue either: <a rel="nofollow" href="https://blog.adacore.com/using-pointers-in-spark">https://blog.adacore.com/using-pointers-in-spark</a>. I would also like to add, that Ada has a package manager as well, namely Alire[2].<br> <p> Given all that, my honest question is: why not Ada/SPARK when it is undoubtedly much better when it comes to safety, and much easier to read and write (to each their own, I suppose, but normal Rust can have 7 (!)[1] symbols next to each other and what it does (in generally, too) is way too hidden as opposed to the verbose (but not annoyingly so) Ada. You look at Ada and you immediately know what it does. The same cannot be said about Rust. It is almost akin to Perl. Seriously.<br> <p> Useful links:<br> <p> - <a rel="nofollow" href="https://docs.adacore.com/spark2014-docs/html/ug/en/usage_scenarios.html">https://docs.adacore.com/spark2014-docs/html/ug/en/usage_...</a><br> - <a rel="nofollow" href="https://docs.adacore.com/spark2014-docs/html/ug/en/source/type_contracts.html">https://docs.adacore.com/spark2014-docs/html/ug/en/source...</a><br> - <a rel="nofollow" href="https://docs.adacore.com/spark2014-docs/html/ug/en/source/concurrency.html#protected-types-and-protected-objects">https://docs.adacore.com/spark2014-docs/html/ug/en/source...</a><br> - <a rel="nofollow" href="https://www.electronicdesign.com/technologies/dev-tools/article/21801311/adacore-11-myths-about-ada">https://www.electronicdesign.com/technologies/dev-tools/a...</a><br> - <a rel="nofollow" href="https://blog.adacore.com/from-rust-to-spark-formally-proven-bip-buffers">https://blog.adacore.com/from-rust-to-spark-formally-prov...</a><br> - <a rel="nofollow" href="https://en.wikibooks.org/wiki/Ada_Programming/Contract_Based_Programming">https://en.wikibooks.org/wiki/Ada_Programming/Contract_Ba...</a><br> - <a rel="nofollow" href="https://www.adacore.com/gems/gem-31">https://www.adacore.com/gems/gem-31</a><br> - <a rel="nofollow" href="https://www.adacore.com/uploads/books/pdf/AdaCore-Tech-Cyber-Security-web.pdf">https://www.adacore.com/uploads/books/pdf/AdaCore-Tech-Cy...</a><br> <p> Check them out. After you are done, can you tell me why Rust over Ada/SPARK?<br> <p> [1]<br> <p> let mut parents_array = ArrayVec::&lt;[&amp;[u8; BLOCK_LEN]; MAX_SIMD_DEGREE_OR_2]&gt;::new()<br> let input_ptrs: &amp;[*const u8; DEGREE] = &amp;*(inputs.as_ptr() as *const [*const u8; DEGREE]);<br> <p> [2] <a rel="nofollow" href="https://alire.ada.dev/">https://alire.ada.dev/</a><br> </div> Sun, 25 Jul 2021 02:27:05 +0000 Footguns https://lwn.net/Articles/864227/ https://lwn.net/Articles/864227/ MrWim <div class="FormattedComment"> Also you can call unsafe functions.<br> </div> Sat, 24 Jul 2021 22:40:06 +0000 Footguns https://lwn.net/Articles/864222/ https://lwn.net/Articles/864222/ gbutler69 <div class="FormattedComment"> <font class="QuotedText">&gt; I believe Rust only lets you do 3 things in unsafe code that you weren&#x27;t anyway allowed to do in safe code. You can dereference a raw pointer. You can access fields in a union. You can mutate statics. That&#x27;s all.</font><br> <p> There is a 4th thing. It lets you make FFI calls to C. And also a 5th thing. It lets you implement unsafe traits.<br> </div> Sat, 24 Jul 2021 16:03:48 +0000 Signal https://lwn.net/Articles/864217/ https://lwn.net/Articles/864217/ Avamander <div class="FormattedComment"> I think it&#x27;s really not about the languages that much, those can be learned albeit with time. But a first contributor can&#x27;t improve the accessibility and user experience of bug triaging, discussion and patch submission, but they absolutely are dissuaded by those being outdated or poor. I really don&#x27;t think C has the need to be marketable other than the fact that it&#x27;s required for now. On the other hand things like mailing lists, git-email, bugzilla or IRC are real anti-advertisements for many. I mean, why bother with Linux if there are plethora of other projects that don&#x27;t place such annoyances in front of you in addition to writing good code itself?<br> </div> Sat, 24 Jul 2021 15:11:32 +0000 Rust / C risk management for undefined behavior (UB) https://lwn.net/Articles/864083/ https://lwn.net/Articles/864083/ nix <div class="FormattedComment"> <font class="QuotedText">&gt; What are the UB cases ? C standard enlists all UB cases.</font><br> <p> It&#x27;s not that easy! It lists *some*. Undefined behaviour is behaviour the Standard does not define: nothing more, nothing less. It does list some of them, but not all (that list would be much longer): but things the Standard does not mention are also things it does not define, and undefined behaviour. (Some of them might be defined in other standards: POSIX defines a bunch of stuff C99 leaves either explicitly or implicitly undefined, for example.)<br> <p> </div> Fri, 23 Jul 2021 09:41:07 +0000 Pointer provenance https://lwn.net/Articles/863907/ https://lwn.net/Articles/863907/ foom <div class="FormattedComment"> <a href="https://wg21.link/P1726R5">https://wg21.link/P1726R5</a><br> <a href="https://wg21.link/P2414R0">https://wg21.link/P2414R0</a><br> </div> Thu, 22 Jul 2021 02:14:21 +0000 Pointer provenance https://lwn.net/Articles/863885/ https://lwn.net/Articles/863885/ mathstuf <div class="FormattedComment"> I&#x27;ll note these two papers for the C++ committee which describe and propose resolutions to the provenance issue (for C++):<br> <p> P1726R5 (describing the problem)<br> P2414R0 (proposed solutions)<br> <p> I believe they are publicly available, but in an abundance of caution, I&#x27;ll leave them unlinked in case they are not (but those with access should be able to find them given these IDs).<br> </div> Wed, 21 Jul 2021 19:32:25 +0000 Rust for Linux redux https://lwn.net/Articles/863863/ https://lwn.net/Articles/863863/ smurf <div class="FormattedComment"> Well, obviously it matters whether we&#x27;re talking about &quot;X is retroactively declared to be UB&quot; (evaluate &quot;be||!be&quot; to be zero, or &quot;realloc()&quot; to poison the pointer you pass to it), or &quot;X is a bug which didn&#x27;t trigger any misbehavior due to Y but now does&quot; (e.g. Y = memory layout or register allocation, when X is a write-beyond-end-of-array or use-after-free bug).<br> <p> Without this context, both the statement itself and arguing about it is meaningless.<br> </div> Wed, 21 Jul 2021 15:46:27 +0000 Rust for Linux redux https://lwn.net/Articles/863860/ https://lwn.net/Articles/863860/ ma4ris5 <div class="FormattedComment"> <p> <font class="QuotedText">&gt; This reads a lot like C++ contracts to me. C could adopt something like those, but I imagine the C++ committee is going to forge the main path there and C can take it or leave it.</font><br> <p> I agree:<br> <p> Easiest low hanging fruit are the features that are already implemented and used<br> actively at C++ side, concepts, which were taken from Rust into C++.<br> <p> Kernel&#x27;s requirements might be too detailed compared to generic C/C++, thus<br> a domain language for attributes could possibly fix the remaining gap<br> for additional checks and optimizations.<br> <p> I mean items like:<br> Value compaction: negative return value is for an error, while &gt;= 0 value is success case.<br> Value bit range classification: some bits are used independently from others.<br> <p> So with domain language for attributes, static analysis and compile time optimization could<br> possibly improve runtime performance, and show places for potential overflows or leaks<br> from those ranges of values.<br> <p> I found following research title, which possibly might be near the idea:<br> <p> <a href="https://www.researchgate.net/publication/328988822_A_Generic_Static_Analysis_Framework_for_Domain-specific_Languages">https://www.researchgate.net/publication/328988822_A_Gene...</a><br> <p> I&#x27;m thinking more like the &quot;printf&quot; formatting checks:<br> If that could be generalized for functions and variables (into compile time/static check time),<br> then it could improve robustness.<br> <p> In a way that the attribute declaration could be specified in the source code,<br> so that the compiler could verify the checks efficiently (enough) and optimize accordingly.<br> <p> LTO side approaches this without code changes: it tracks value ranges between functions,<br> and can see possible overflow cases.<br> Attribute declarations could show developer&#x27;s intention in these corner cases,<br> so compiler could warn about remaining possible issues.<br> <p> Thus code could be proven to have no overflow issues, or accidental collisions between error values and valid values (to reduce risk for some of the rare problems).<br> <p> Also C-to-Rust automatic conversion could pick those declarations and generate better wrappers.<br> <p> Standardizing every new attribute feels too slow to have efficient progress for Kernel development,<br> so standardizing language for attribute declarations could be better.<br> <p> </div> Wed, 21 Jul 2021 15:37:22 +0000 Rust for Linux redux https://lwn.net/Articles/863734/ https://lwn.net/Articles/863734/ nye <div class="FormattedComment"> <font class="QuotedText">&gt; “It has been working for decades” is just not something that justifies any expectation for that program to continue running</font><br> <p> I&#x27;m saddened that we&#x27;ve reached the point where I genuinely can&#x27;t tell if this statement is meant seriously or not.<br> </div> Wed, 21 Jul 2021 13:35:59 +0000 Rust for Linux redux https://lwn.net/Articles/863694/ https://lwn.net/Articles/863694/ mathstuf <div class="FormattedComment"> <font class="QuotedText">&gt; __attribute_value_range__(0, 0, 64) /* return value&#x27;s value range is [0 - 64] */</font><br> <font class="QuotedText">&gt; __attribute_value_range__(1, 0, 256) /* First argument&#x27;s value range is [0 - 256] */</font><br> <font class="QuotedText">&gt; int foo (int i) { return i &gt;&gt; 2; }</font><br> <p> This reads a lot like C++ contracts to me. C could adopt something like those, but I imagine the C++ committee is going to forge the main path there and C can take it or leave it.<br> </div> Wed, 21 Jul 2021 00:34:58 +0000 Rust for Linux redux https://lwn.net/Articles/863625/ https://lwn.net/Articles/863625/ ma4ris5 <div class="FormattedComment"> Rust, C and C++ are compiler front end languages, both are using same compiler back end libraries for the same compiler suite.<br> <p> Detailed attributes seem to be the working solution to inform compiler about how the function behaves.<br> Both front ends can use same attribute mechanisms to make compiler back end libraries informed about function behavior.<br> <p> realloc() bug example isn&#x27;t actually C or Kernel issue at all: It seems to be LLVM C compiler front end bug,<br> and it affects &quot;rustc&quot; LLVM frontend implementation: &quot;rustc&quot; can&#x27;t use realloc().<br> <p> Here is the &quot;realloc()&quot; &quot;noalias&quot; issue analysis.<br> Correct return value is &quot;2 2&quot; which GCC gives,<br> and incorrect result comes from LLVM compiler (Fedora 34)<br> Test case was shown in <a href="https://lwn.net/Articles/862521/">https://lwn.net/Articles/862521/</a><br> <p> $ clang -O3 realloc_test.c -o realloc_test ; ./realloc_test<br> 1 2<br> $ gcc -O3 realloc_test.c -o realloc_test ; ./realloc_test<br> 2 2<br> <p> What is significant, &quot;stdlib.h&quot; doesn&#x27;t have &quot;noalias&quot; attribute for realloc()&quot;.<br> Even while &quot;noalias&quot; is absent, &quot;clang&quot; hard codes &quot;noalias&quot; for the function:<br> <p> /usr/include/stdlib.h contains (Fedora 34):<br> /* __attribute_malloc__ is not used, because if realloc returns<br> the same pointer that was passed to it, aliasing needs to be allowed<br> between objects pointed by the old and new pointers. */<br> extern void *realloc (void *__ptr, size_t __size)<br> __THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2));<br> <p> The above proves, that &quot;stdlib.h&quot; is clean, and doesn&#x27;t contain the &quot;noalias&quot; attribute,<br> so the bug is within &quot;clang&quot; LLVM compiler, for example when -O3 is used there.<br> <p> <p> After realloc() definition, stdlib.h has function &quot;reallocarray()&quot;, which is also interesting,<br> because it declares __attribute_alloc_size__ ((2, 3).<br> <p> /* Re-allocate the previously allocated block in PTR, making the new<br> block large enough for NMEMB elements of SIZE bytes each. */<br> /* __attribute_malloc__ is not used, because if reallocarray returns<br> the same pointer that was passed to it, aliasing needs to be allowed<br> between objects pointed by the old and new pointers. */<br> extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)<br> __THROW __attribute_warn_unused_result__<br> __attribute_alloc_size__ ((2, 3));<br> #endif<br> <p> <p> I think that there could be room for detailed function definition,<br> by adding already usable attributes into Kernel library functions.<br> <p> Also adding new attributes into Kernel and compiler could be useful.<br> <p> It might be even possible to add a domain language for custom attribute declarations,<br> which could be consumed by C compiler(s), for a precise function use validation.<br> I don&#x27;t know if this has been considered.<br> <p> Also &quot;C headers to Rust&quot; automatic conversions could take advantage of those<br> additional attributes.<br> <p> <p> For example a value range could be useful, something like:<br> __attribute_value_range__(0, 0, 64) /* return value&#x27;s value range is [0 - 64] */<br> __attribute_value_range__(1, 0, 256) /* First argument&#x27;s value range is [0 - 256] */<br> int foo (int i) { return i &gt;&gt; 2; }<br> <p> __attribute_value_errnum_with_range__(0, -255, -10, 0, 64) /* error within [-255,-10], value within [0 - 64] */<br> __attribute_value_errnum_with_range__(1, -255, -10, 0, 256) /* error within [-255,-10], value within [0 - 256] */<br> int foo (int i) { if (i &lt; 0) return i else return i &gt;&gt; 2; }<br> <p> These should be such that they should be sane, and could be mapped into &quot;C back end&quot; libraries easily.<br> <p> Personally I think that &quot;always inline&quot; functions could be used instead of macros, when this facility<br> is needed, and macro kind of inlining behaviour is necessary.<br> <p> So if the additional attribute declaration is useful for C, and also looks good from following point of views:<br> C++, C-to-Rust, Rust, and it is correct, readable and manageable, it should be worth adding.<br> <p> Compiler verification for having a working compiler:<br> - make sure (old) compiler doesn&#x27;t generate bad code<br> make c_compile_bug_check<br> - Make sure errors / warnings are reported (including relevant undefined behaviour cases for the Kernel):<br> make c_compile_error_warning_check<br> <p> Consume CERT Kernel warnings:<br> - Add already existing attributes to function definitions and variables.<br> - Introduce new attributes into for example value ranges, so that compiler can see whether integer could overflow.<br> <p> For example integer overflow mitigation could be something like:<br> 1. Enable or add (per C file) compilation flag for overflow reporting for making patches.<br> 2. Compiler (must) track value&#x27;s ranges and classifications (errors, warnings),<br> only warn about possible overflow cases.<br> 3. Add attributes for value&#x27;s range, to tell compiler what range the number has =&gt; unnecessary warnings go away. LTO / static check can validate these.<br> 4. Add overflow check, or add overflow semantics for a calculation with a warning (may wrap, saturate to MIN_INT, 0 or, MAX_INT) =&gt; UB warning goes away.<br> <p> 5. Deliver individual patches for C header files for fixing overflow warning issues (add the range semantics),<br> to fix large code base issues.<br> 6. Deliver patches that fix a single C file for remaining issues, until the C file doesn&#x27;t have integer overflow risk, 7. Last patch could enable &quot;integer overflow&quot; compiler warning, to make sure integer overflow is absent or visible in future Kernel patches (static analysis bot could watch these).<br> <p> A bot could also search for opportunities to enable the &quot;integer overflow compiler check&quot; for files that don&#x27;t have issues currently.<br> <p> </div> Tue, 20 Jul 2021 17:49:20 +0000 Rust for Linux redux https://lwn.net/Articles/863638/ https://lwn.net/Articles/863638/ Wol <div class="FormattedComment"> <font class="QuotedText">&gt; &gt; I still maintain that &quot;if it isn&#x27;t a ring or a field, I can&#x27;t reason about it&quot; is overreach. I mean, people do manage to write correct floating point software, for example.</font><br> <p> Ah ... so the OP was correct in saying it is overreach, but not for the reasons I understood ... fp is *almost* a ring :-) (if you use the &quot;approximately equal&quot; rather than the &quot;equals&quot; operator :-)<br> <p> Cheers,<br> Wol<br> </div> Tue, 20 Jul 2021 17:01:01 +0000 Rust for Linux redux https://lwn.net/Articles/863621/ https://lwn.net/Articles/863621/ excors <div class="FormattedComment"> <font class="QuotedText">&gt; But isn&#x27;t the set of all floating point numbers a finite set? Not that I know what the words &quot;ring&quot; or &quot;field&quot; actually mean in this context</font><br> <p> A ring is a set of values plus a pair of operators (&#x27;+&#x27; and &#x27;*&#x27;), which have the properties listed on <a href="https://mathworld.wolfram.com/Ring.html">https://mathworld.wolfram.com/Ring.html</a> . Floating point with addition and multiplication operators does not meet those properties, e.g. not all values have an additive inverse (you can&#x27;t subtract anything from Infinity or NaN to get 0), and it doesn&#x27;t guarantee a*(b+c) == a*b + a*c (so it&#x27;s not even a semiring), etc. A field is a ring with some additional properties on the &#x27;*&#x27; operator. You can reason about floating point numbers, but not using any of those common algebraic concepts.<br> </div> Tue, 20 Jul 2021 15:25:00 +0000 Rust for Linux redux https://lwn.net/Articles/863589/ https://lwn.net/Articles/863589/ Wol <div class="FormattedComment"> <font class="QuotedText">&gt; I still maintain that &quot;if it isn&#x27;t a ring or a field, I can&#x27;t reason about it&quot; is overreach. I mean, people do manage to write correct floating point software, for example.</font><br> <p> But isn&#x27;t the set of all floating point numbers a finite set? Not that I know what the words &quot;ring&quot; or &quot;field&quot; actually mean in this context, but surely the set of valid REAL*4 numbers is smaller than the set of int32 numbers.<br> <p> So it&#x27;s easy to reason about floating point in exactly the same way as we reason about ints. It only becomes a problem if we forget that floating point numbers and irrational numbers are disjoint sets ...<br> <p> Cheers,<br> Wol<br> </div> Tue, 20 Jul 2021 14:58:22 +0000 Footguns https://lwn.net/Articles/863555/ https://lwn.net/Articles/863555/ farnz <div class="FormattedComment"> <font class="QuotedText">&gt; The only thing I said is always true is that you can&#x27;t dereference something you can&#x27;t prove not to be NULL and expect it to not be UB; the check reordering is allowed because it was UB before and we can assume at that point what the author wanted. This doesn&#x27;t mean a warning should not be emitted unless (somehow) specified otherwise. If there&#x27;s a check before in the same function it&#x27;s trivial to prove it&#x27;s no longer NULL after that. Besides, you don&#x27;t need to know whether an optimization resulted from the UB. Knowing it exists is enough. And AFAICT that can be known before transforming to IR.</font><br> <p> This is the difference between your model, and the C model. In C, you can dereference something that you can&#x27;t prove not to be NULL, and expect it to not be UB; it&#x27;s only UB if, on a specific execution, the thing is NULL. If it happens not to be NULL, then there&#x27;s no UB. This comes down to whole program analysis - as a programmer, you might ensure that you only call ub(config) with non-NULL pointers, and thus it&#x27;s fine. <br> <p> So the C compiler is able to reason backwards - if thing *is* NULL, then there is UB. Ergo is must not be NULL, because UB isn&#x27;t allowed, which permits optimization on the basis that it&#x27;s not NULL. This is fine if the explicit NULL check is (e.g.) from a macro, or in generated code, or left over from refactoring and not yet removed; you&#x27;ve taken out something that&#x27;s always false in this context, and just deleted the dead code.<br> <p> It only becomes a problem where the human is surprised by the deletion of dead code - i.e. where the human thought the check was still important, but it&#x27;s actually considered always false (or always true) by the compiler. And as deletion of dead code takes place at every level - from AST, through IR, through machine instruction choice - the compiler needs to link back its elimination of dead code and determine whether or not the human would be surprised by this particular elimination.<br> <p> And that&#x27;s what makes it a hard problem - we may know that ub(config) is only ever called with a non-NULL pointer, but that needs a whole program analysis which the compiler cannot perform. We may also know this simply because we&#x27;ve refactored so that callers of ub(config) do the NULL check themselves, and the extra NULL check inside the function may be there because a preprocessor (which can be outside the compiler!) has used a general form of code that works regardless of the presence of the NULL checks; why use two macros and force the human to think about whether or not a NULL check has happened already, when you can use one?<br> </div> Tue, 20 Jul 2021 11:54:27 +0000