-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
more than one kind of "unsafe" #1160
Comments
This would solve many of the problems voiced in #1066 . |
Panics are not a kind of undefined behaviour. It is safe for code to intentionally panic. |
@arielb1 true, but it might also be useful to be able to mark things (blocks or functions) as non-panicable, I believe this has at least been discussed in the past. @torpak it might make sense to place the question of marking panic-producing (or non-panic producing) code in a seperate issue as it seems to be a slightly different concern. |
A prototype could likely show these off using lints and attributes. On Sun, Jun 14, 2015, 11:13 AM Cody Schafer notifications@github.com
|
On Sunday, June 14, 2015 11:06:00 arielb1 wrote:
That's part of what i mean. I think more in the direction of the literal And while i think it is to late to change the meaning of the keyword in any When i have to mark code as unsafe, for example to do some optimization, that With my proposal: I wish noleak nopanic and whatever footgun avoidance else the compiler could thus my proposal. |
On Sunday, June 14, 2015 11:13:36 Cody Schafer wrote:
I intentionally named nopanic as one example. Whenever my code does something i don't expect it's bad. But manually checking all my code for anything that could go wrong is tedious Now if i state an expectation for a block like no I know that each of these expectations is hard to implement and each will need But i'm relatively sure for many of these hazards it's possible to prove their |
You might be interested in https://github.com/rust-lang/rfcs/pull/73/files this kind of thing is usually called an 'effects system' |
ah that is very close to what i meant. |
Currently as far as i understand it the unsafe keyword only applys to potentialy breaking memory safety guarantees.
Some people argued that other types of guarantees like leak-safety, safety from panics, ... would be useful and violating those should be considered unsafe too.
The most important argument against this seems to be that this would weaken memory safety because it would lead to an inflationary use of unsafe.
My ideal solution to this would be not having just one unsafe keyword but at least three, maybe many:
Code that can not accept one or more of those types of unsafety could opt out of each specifically.
Since 1.0 is out this scenario is not realistic any more.
But maybe we could have something like:
Since a practical compiler has to run in finite time it can on it's own only ever prove the most trivial cases. A mechanism would be needed to assist the compiler.
The most simple form would be corresponding attributes wontpanic and wontleak.
For example i want to call a function that could theoretically panic inside a nopanic block, then i would make sure that i call this function only in ways that are guaranteed not to panic and wrap the call inside a wontpanic block.
Use of reference counting inside a noleak block could be done the same way.
This could be added in a backward compatible way and nopanic and noleak... should be added where ever possible.
The text was updated successfully, but these errors were encountered: