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 27 '24 edited Oct 27 '24
Assume profiles need analysis and fixing of all dependencies beforehand in safe mode in order to guarantee aliasing safety, which is where I will focus the discussion below.
Case 1: your dependency has been safely compiled, you use safe compilation in your client code
Dependency:
This function has been verified by compilation: since it contains no annotation, it assumes not aliasing. If it aliased, it would have been caught by the analysis when compiling it if the body violates the assumption.
Now you have your client code, which you also compile safely in your own code, so it assumes all reasonable safeties, including non-aliasing:
The key here is that you assume information on the signature of dependency and the compilation restricted the semantics: you know it has been compiled in safe mode and the provides advertises that safety. This is not "today" C++ in the sense that the compilation has been more restrictive, but it is just a compile-time feature.
So yes, this analysis is in fact adding information to the signature in safe mode.
Case 2: your dependency has not been safely compiled, your code must be compiled safely
Your dependency looks like this:
Case 3: the dependency has been compiled in safe mode, your code is compiling unsafe
Dependency:
Case 4: I tried to compile my dependency as alias safe, but it was not
Final words
In some way, the analysis, as you say, goes viral: you can only compose things that gave you the guarantees you want or suppress. But that is not unsound. In any case, it takes some work to prepare the dependencies, but as little as possible, and, of course, recompiling.
But my point here is that as long as you can "recompile" your dependencies, it is very little work to add safety without rewriting (only the "provides" in this case, but local analysis can be more complicated, yes). This lets you increasingly add safeties also, partitioned, not only aliasing. It is incremental.
In Safe C++ you would need to port your code directly. Or use it as-is, which provides zero safety directly, so you are worse-off if you do not port it beforehand to even enable the analysis.
Now, criticize, I am thinking as I do. The provides is invented syntax but that must be known in some way for profiles: what is guaranteeing.