-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a FAQ section #59
Draft
Dalzhim
wants to merge
1
commit into
cppalliance:develop
Choose a base branch
from
Dalzhim:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2789,6 +2789,84 @@ Everything in this proposal took about 18 months to design and implement in Circ | |||||||||||||||||||||
|
||||||||||||||||||||||
An earlier version of this work was presented to SG23 at the St Louis 2024 ISO meeting, with the closing poll "We should promise more committee time on borrow checking?" --- SF: 20, WF: 7, N: 1, WA: 0, SA: 0. | ||||||||||||||||||||||
|
||||||||||||||||||||||
# FAQ | ||||||||||||||||||||||
|
||||||||||||||||||||||
* [What is the goal?](#what-is-the-goal) | ||||||||||||||||||||||
* [Will Safe C++ break my code?](#will-safe-c-break-my-code) | ||||||||||||||||||||||
* [Why does this proposal introduce a whole new standard library (std2)?](#why-does-this-proposal-introduce-a-whole-new-standard-library-std2) | ||||||||||||||||||||||
* [Why do we need to borrow Rust's borrow checker?](#why-do-we-need-to-borrow-rusts-borrow-checker) | ||||||||||||||||||||||
* [Why not use Hylo's approach?](#why-not-use-hylos-approach) | ||||||||||||||||||||||
* [Why not use safety profiles?](#why-not-use-safety-profiles) | ||||||||||||||||||||||
* [Why do the safe language alternatives to unsafe c++ language constructs use Rust names rather than existing C++ names?](#why-do-the-safe-language-alternatives-to-unsafe-c-language-constructs-use-rust-names-rather-than-existing-c-names) | ||||||||||||||||||||||
* [I do not like the proposed syntax, why is it so ugly?](#i-do-not-like-the-proposed-syntax-why-is-it-so-ugly) | ||||||||||||||||||||||
* [Why is `std::*` missing from `std2`?](#why-is-std-missing-from-std2) | ||||||||||||||||||||||
* [Won't `std2` lead to an extreme function coloring problem?](#wont-std2-lead-to-an-extreme-function-coloring-problem) | ||||||||||||||||||||||
* [Are there runtime checks?](#are-there-runtime-checks) | ||||||||||||||||||||||
* [There's promising research that could yield a solution that is both more simple and more elegant than rust-style borrow checking. Why not wait?](#theres-promising-research-that-could-yield-a-solution-that-is-both-more-simple-and-more-elegant-than-rust-style-borrow-checking.-why-not-wait) | ||||||||||||||||||||||
* [Why are lifetimes annotated using `/` rather than `'`?](#why-are-lifetimes-annotated-using-rather-than) | ||||||||||||||||||||||
* [Can Safe C++ make my program safer just by recompiling existing code?](#can-safe-c-make-my-program-safer-just-by-recompiling-existing-code) | ||||||||||||||||||||||
* [What is the difference between `cpy x` and `T(const T&)`?](#what-is-the-difference-between-cpy-x-and-tconst-t) | ||||||||||||||||||||||
* [What is the difference between `drp x` and `~T()`?](#what-is-the-difference-between-drp-x-and-t) | ||||||||||||||||||||||
* [What is the difference between `unsafe_cell` and `const_cast`?](#what-is-the-difference-between-unsafe_cell-and-const_cast) | ||||||||||||||||||||||
|
||||||||||||||||||||||
### What is the goal? | ||||||||||||||||||||||
|
||||||||||||||||||||||
The goal is to add to C++ the ability to incrementally opt into zero-overhead memory safety without loss of expressiveness. This ability will enable developers to get rid of various classes of bugs that fall into four categories of safety : lifetime safety, type safety, thread safety and spatial safety. It will also address valid concerns put forward by the security community through the NSA, the CISA, the NCSI and the White house with regards to memory safe languages. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Will Safe C++ break my code? | ||||||||||||||||||||||
|
||||||||||||||||||||||
No. Safe C++ requires explicit opt-in by developers. And even after opting in, Safe C++ is designed to facilitate incremental adoption within large codebases. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Why does this proposal introduce a whole new standard library (std2)? | ||||||||||||||||||||||
|
||||||||||||||||||||||
The existing STL is not memory safe. Making it memory safe would require changes to the API which is a non-starter with regards to the goal of making existing code stay the same. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Why do we need to borrow Rust's borrow checker? | ||||||||||||||||||||||
|
||||||||||||||||||||||
The borrow checker is the best fit that is production-ready to meet our goals. It is a compile time solution that leads to zero overhead. It is a mature and proven technology. It is the safest path to guarantee a successful outcome. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Why not use Hylo's approach? | ||||||||||||||||||||||
|
||||||||||||||||||||||
Hylo's approach uses a borrow checker. Mutable Value Semantics (MVS) then eliminates the need for explicit lifetimes, but that is still a work in progress and is not considered production-ready. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Why not use safety profiles? | ||||||||||||||||||||||
|
||||||||||||||||||||||
Safety profiles is still a work in progress. The lifetime safety profile is the one furthest along. But it still falls well short of what borrow checking can provide. It only adresses one of the four categories of memory safety that this proposal aims to achieve and even within that single category, it doesn't address all potential issues (i.e.: it cannot catch all iterator invalidation cases). | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Why do the safe language alternatives to unsafe c++ language constructs use Rust names rather than existing C++ names? | ||||||||||||||||||||||
|
||||||||||||||||||||||
The safe language alternatives are used in very different ways compared to their unsafe counterparts. For example, while `union` looks like a `struct` that has a single active member, a `choice` can only be interrogated by using a match-expression, guaranteeing safe access to its content. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### I do not like the proposed syntax, why is it so ugly? | ||||||||||||||||||||||
|
||||||||||||||||||||||
Bikeshedding isn't a priority at this stage. The current syntax is the one used by the reference implementation so far. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Why is `std::*` missing from `std2`? | ||||||||||||||||||||||
|
||||||||||||||||||||||
This proposal is a healthy beginning but it’s not comprehensive treatment. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Won't `std2` lead to an extreme function coloring problem? | ||||||||||||||||||||||
|
||||||||||||||||||||||
It won't be: `safe` code can wrap unsafe calls within `unsafe` blocks and `unsafe` code can call `safe` code. Same goes for `std2` and `std` library components. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### Are there runtime checks? | ||||||||||||||||||||||
|
||||||||||||||||||||||
Yes, there are dynamic bound checks for spatial safety. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### There's promising research that could yield a solution that is both more simple and more elegant than rust-style borrow checking. Why not wait? | ||||||||||||||||||||||
|
||||||||||||||||||||||
The security community and regulators are actively pushing developers towards memory safe languages with official guidance since 2022. Does C++ stay on the do-not-use list or does C++ become a memory safe language? | ||||||||||||||||||||||
Comment on lines
+2856
to
+2858
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
### Why are lifetimes annotated using `/` rather than `'`? | ||||||||||||||||||||||
|
||||||||||||||||||||||
C supports multi-character literals. This cursed feature, in which literals like 'abcd' evaluate to constants of type int, makes lexing Rust-style lifetime arguments very messy. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
### Can Safe C++ make my program safer just by recompiling existing code? | ||||||||||||||||||||||
### What is the difference between `cpy x` and `T(const T&)`? | ||||||||||||||||||||||
### What is the difference between `drp x` and `~T()`? | ||||||||||||||||||||||
### What is the difference between `unsafe_cell` and `const_cast`? | ||||||||||||||||||||||
|
||||||||||||||||||||||
--- | ||||||||||||||||||||||
references: | ||||||||||||||||||||||
- id: nsa-guidance | ||||||||||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.