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
1
u/germandiago Oct 29 '24
No, they are not doing it. I said they could, it is just a possibility I have been thinking about. Once you fix parameters, probably you can take it further. In fact, Cpp2 does not restrict aliasing at all.
Once you do that, it goes viral across all the type system. So if there is another way, it will be more compatible. The semantics are there, though.
Profiles always had safe and unsafe code.
[[profiles::suppress("exclusive_aliasing")]] f(a, a);is like unsafe. What we should not need is top-level markers. Also, trusted code also exists, even in Rust: https://doc.rust-lang.org/nomicon/safe-unsafe-meaning.htmlNo, I am not proposing markers like that, I am gathering everything in a document, but to refine it will take some weeks, not much time. It is a collection of potential solutions/strategies, not a WG21 proposal as such.
If you inject aliasing checking in caller-side (generated in caller side) as a last fallback, that does not break ABI in any way.
This is the part I am thinking about, there are several ways and not all optimal, being the least optimal to assume no aliasing and overrestricting API calls. That would need, sometimes (but not always), changes to existing code, and tehre are two alternatives here also as far as I am researching. When I have something to publish as possible ideas I will drop it in Github so that you can take a look.
This, again, is more nuanced: there are cases where an API break is not a problem, for example, imagine this:
Compile safe here, f not compiled safe:
For that you do not need any information. It is indeed an API break but what is important there is to not compromise the safety. Can it lead to false positives? Yes. How can you deal with the false positives? There are two ways, but still in evolution. Let me think further. Whatever solution is for all those things, the solution will not be 100% perfect (in the sense of conservatively estimating safety), but it is a requirement that it lets you analyze old code (in my constraints) and that it fails by overconstrainig (safe).
So the workflow would be something like: analyze (free), fail if not proved safe, check overconstrained code. Now you have a chance to opt-out safety if you cannot touch the origin code. If you can, you can fix it.
I keep researching. I am pretty sure that whatever I come with, "optimal" or not, it must not be dangerous for code: no ABI breaks, if something does not compile, probably it should, but not all information can be derived from the signature without further analysis or some annotation at times (a few annotations are unavoidable BUT their absence will not make any code unsafe). This can lead to overconstrained diagnostics, but not to unsafe diagnostics, that's the point. I do not know how the final result will look. I am still on it.
Let's see what I can come up with and how it looks and how usable it would be. This leans on a lot of research done so far, what I am trying to figure out is how far this can be taken in "ordinary C++ with minimal annotations".
I think you are warning me here of things I am perfectly aware of.
I believe there are solutions for this, but that would rely in "trusting" the origin the same way you trust Rust std lib even if it has unsafe. Which is what it does at the end.