r/cpp
•
u/steveklabnik1
•
Oct 24 '24
•
1
Why Safety Profiles Failed
https://www.circle-lang.org/draft-profiles.html
180
Upvotes
View all comments
Show parent comment
7
u/ts826848 Oct 26 '24
No one is intentionally proposing an unsound "safe" C++ (or at least I very much hope so!), but intent is meaningless when it comes to proposals. What matters is what the proposal says, and that's precisely one of the main criticisms of the profiles proposal - it may intend to describe a safe C++, but the claim is that the proposed profile(s) are actually unsound. In other words, critics claim that the profiles proposal is proposing an unsound "safe" C++, even if it doesn't intend to do so.
That's what profiles claim to allow, and you're taking their claim at face value. Other people here are rather more skeptical of those claims and have articulated their reasons why they think that the profiles analysis doesn't work and perhaps even can't work. And if the profiles analysis can't work then it doesn't matter that you can try to use it on existing code - a broken analysis will yield broken results.
Sean Baxter states in this comment that individual Safe C++ features can be toggled on/off at a fairly fine-grained level. I think this would mean you can turn on individual sub-analyses for specific parts of your codebase, so you don't need code to conform to the entirety of Safe C++ to compile.
But even if you assume Safe C++ isn't that fine-grained, I think the other two primary responses from Safe C++ proponents would be:
Python 2/3 is not a good analogy here because the biggest problem for that migration was that there was practically zero ability to interop between the two - either your entire codebase was Python 2 or your entire codebase was Python 3. This is not the case for either Safe C++ or profiles - they both promise the ability to interop between the safe subset and the rest of the C++ universe, so you can continue to use your existing code without needing to touch it.
There's a bit of an issue here in that there's some lack of precision in what's being talked about.
There's the actual profiles proposal, as described in Herb's papers. Soundness absolutely seems to be an issue for that, as described in Sean's papers and in the comments here.
Then there's your hypothetical proposal that lives only in your head and in your comments, described in an ad-hoc and piecemeal fashion with varying levels of rigor. You're describing soundness as a goal, but it's difficult for anyone else to verify that that goal is actually met.
As I said elsewhere, you're focusing too much on the specific example and so missed the point it was trying to convey. The problem is not
std::sortvsstd::ranges::sort; the claim is that profiles cannot distinguish "this function has soundness preconditions" and "this function is valid for all possible inputs", and so may inadvertently allow calls to the former in "safe" code.Again, you need to be clear about whether you're talking about the actual profiles proposal or your hypothetical proposal, especially when your proposal diverges from the actual proposal as it does here. The actual lifetimes proposal claims to work for all pointer-like types. That includes raw pointers!
So yes, people are in fact asking for perfect analysis for raw pointers, because that's what the proposal claims to be able to do. If you want to ban them from your subset, fine, but you need to make it clear you're not talking about the actual profiles proposal and that you're talking about your own version of profiles.
I'm also pretty sure multiple people have explained to you that no one is asking for non-local alias analysis. Rust doesn't do it, Safe C++ doesn't do it, profiles don't do it, and all three of them make it a design goal to not use non-local alias analysis.
This is exactly the issue people have with the profiles proposal! Details matter - You can articulate a hand-wavey high-level strategy all you want, but hand-wavey high-level strategy is completely useless for implementers since it provides no guidance about what exactly needs to be done or how exactly things will work.
The bulk of the
funwork is not in specifying the high-level approach, it's in specifying in detail the exact rules that are to be used and looking at what the consequences are. That's precisely what happened with the lifetimes proposal - it existed as a high-level strategy/goal for quite some time, but were effectively unactionable because they lacked enough detail for anyone to even try to implement them. But now that it has materialized, people are able to take a look at the details and find potential holes (and they say they have!).I think people are seeing a repeat of this with what you say. You describe all these high-level concepts and goals and such, but neither you nor anyone else can know whether it'll actually work until the rubber meets the road and all the details are hammered out. For all anyone knows what you describe can turn out to be a repeat of the profiles proposal: sounds promising, but turns out to be (possibly) fatally flawed when you actually provide details. Or maybe it could work! No one knows.