5 ms·
Memory safety without lifetime parameters
- jtrueb 2y ago[flagged]
- deleted 2y ago[deleted]
- fallingsquirrel 2y ago> This proposal implements two sets of constraint rules. Free functions constrain return references by the shortest of the argument lifetimes. Non-static member functions constrain return references by the implicit object lifetime. It seems like this proposal just chooses a general set of constraints and forces it everywhere? Under these rules you couldn't e.g., have a regex object with a match method that takes a string and returns a reference to that same string. Seems too limiting to be practical.
- leni536 2y agoNo, it explores this particular design, but concludes that lifetime annotations are needed.
- aw1621107 2y agoThe draft for this paper was submitted a few days ago at https://news.ycombinator.com/item?id=41850258 https://news.ycombinator.com/item?id=41850258 (3 points, no comments). Not sure if there are any differences between the two versions.
- ndesaulniers 2y agoOverall interesting read. I'm rooting for Sean. If he has faith that C++ is not too far gone to be saved...perhaps I can, too. > Explain the infeasibility of making legacy lvalue- and rvalue-references memory safe. > Relocation must replace move semantics He advocates for adding lots of things to the language, but that point is a massive change to the language IMO. I definitely think move semantics are awful; as is the hierarchy of rvalues (xvalues and glvalues) is nuts, but at this point can they be removed from the language? Or do I misinterpret the point? Perhaps this is different between unsafe blocks (vs default safe blocks)?
- pjmlp 2y agoIf you check the flames on Reddit, not sure if he will keep at it, the WG21 feedback has been pretty disapointing, hence this paper, as kind of response to those replies. Most folks at WG21 think profiles will magically solve the problem, even though many of the ideas are only available on paper, not a random C++ compiler. The biggest issue is that while a language like Ada also has profiles, the safety culture is much different, and they are part of the ecosystem since Ada83, not something that was added later.
- blub 2y agoAuthor’s paper also doesn’t solve the problem, because I wager most C++ programmers wouldn’t touch this rustified C++, which manages to look even worse than the already not light on the eyes original.
- pjmlp 2y agoProbably, but then they will need to decide how much they feel like if C++ joins the computing equivalent of hazardous goods, where products written on it only have clearance for specific use cases. See "Product Security Bad Practices" from CISA and FBI, published last week. https://www.cisa.gov/resources-tools/resources/product-security-bad-practices https://www.cisa.gov/resources-tools/resources/product-secur... => "Software manufacturers should build products in a manner that systematically prevents the introduction of memory safety vulnerabilities, such as by using a memory safe language or hardware capabilities that prevent memory safety vulnerabilities. Additionally, software manufacturers should publish a memory safety roadmap by January 1, 2026."
- rfoo 2y ago> such as by using a memory safe language or hardware capabilities that prevent memory safety vulnerabilities Heh, now I do believe that my partially-memory-corruption-based side job may be in danger. If it was just "by using a memory safe language" I do not care, but if they want to boost hardware assisted mitigations (better and ubiquitous memory tagging etc) it's going to have significant impact.
- Animats 2y agoNot sure what to make of this. Is this a feature, or a whole design? The idea here is simply that if the whole call tree can be examined, rather than only looking at one module at a time, less annotation is needed. That's reasonable enough, although it may result in long compile times. What I don't see here is: - How are circular references handled? - C++ objects implicitly have links from parent to child and child to parent. So there's built-in circularity. How does that work? - What about interior mutability? Examining the whole call tree is useful. It allows catching mutex deadlocks where a thread locks against itself and stalls. It may be possible to replace something like Rust's RefCell with something, perhaps "SafeCell", that supports the same .borrow() and .borrow_mut operations, checking them at compile time for overlapping borrow scopes.
- j16sdiz 2y ago> - C++ objects implicitly have links from parent to child and child to parent. So there's built-in circularity. How does that work? Can you elaborate? In my understand, the parent/child relation are on the class not the object itself.
- Animats 2y agoA child class can reference fields in the parent, and the parent can call virtual functions in the child.
- carlmr 2y agoYou mean vtable for inheritance? There's no ownership relation here.
- jcelerier 2y agoWell, there is: it's easy to trigger unsafe behaviour by calling a virtual method accessing a child class data member (say some std::vector) when in the parent class destructor, as the child sub object will already have been destroyed. Thus it's reasonable to say that there is a bidirectional ownership relationship.
- p1necone 2y agoSeeing this on HN feels a bit like those apocryphal stories of the professor who hands out the "read all the questions before you start" quiz, and the last question just tells the students to ignore everything else, wait 30 minutes and leave for full marks.
- devnull3 2y agoThis appears to be a out of season April Fool's joke. Am I the only one who thinks the this sacrifices the readability?
- rfoo 2y agoIt may be done on purpose? To me this looks like a satirical piece in response to some "nooooo how dare you introduce lifetime annotations to C++"-style comments on the same author (Sean Baxter)'s C++ lifetime annotation proposal.
- devnull3 2y agoOn the other hand its published on open-std.org which adds to its credibility
- flohofwoe 2y agoC++ isn't exactly famous for being readable to begin with. If the name Sean Baxter doesn't ring a bell, he's creating the Circle compiler which one step after another fixes the problems of C++ (while not trailing off into a completely new language): https://www.circle-lang.org/quickref.html https://www.circle-lang.org/quickref.html
- einpoklum 2y ago> which one step after another fixes the problems of C++ Somehow, multiple groups of people have recently decided they want to "fix the problem": Carbon, Circle, CppFront2. But apparently, it's different fixes, and the formulation of the "the problem" is different. I am wary of rushing to do this, considering the fate of the D, a previous attempt to "fix the problem" with C++.
- flohofwoe 2y agoAFAIK the big difference of Circle to both Carbon and CppFront2 is that Circle is (mostly?) a superset of C++17, so it doesn't change the basic syntax, just adds things on top. I don't care much either way tbh, just watching from the sidelines while happily churning out C and Zig code ;) But IMHO Sean Baxter does more for C++ than the entire committee ever did in the last three decades - if C++ would have moved into a similar direction I probably wouldn't have dropped it as my main language).
- mmaniac 2y agoI'm not a fan of Rust, but my God, just use Rust instead of this. This is unreadable.
- burjui 2y agoEven plain C++ is very hard to read, it's one of the reasons I ditched it. Cannot even imagine writing code in this version. C++ is overcomplicated already, imho it's best to leave it to die naturally instead of prolonging the suffering of millions that use it.