Skip to content
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

Unsafe blocks and sub-language #413

Closed
graydon opened this issue May 26, 2011 · 8 comments
Closed

Unsafe blocks and sub-language #413

graydon opened this issue May 26, 2011 · 8 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-type-system Area: Type system

Comments

@graydon
Copy link
Contributor

graydon commented May 26, 2011

Add a new raw-pointer-to-T type constructor *T, and a lexical block type 'unsafe { ... }' in which a few new operations become allowed: forming a raw pointer with unary &, dereferencing a raw pointer with unary *, casting a raw pointer to another raw pointer with binary 'as', indexing into raw pointers with ".()" (soon to be []), and performing arithmetic on raw pointers.

@ghost ghost assigned espindola May 26, 2011
@brson
Copy link
Contributor

brson commented Sep 2, 2011

I've been talking to pcwalton about this and he's of the opinion that we should do these unsafe operators through library functions, via intrinsics, some of which we already have and use. I can see the advantage of that, in that it's easier than supporting more language features. It does demand cross-crate inlining though.

In either case we still need a way to mark the boundaries of unsafety.

I believe what he likes, and what I agree seems nice, is that:

  1. Native and intrinsics are implicitly unsafe
  2. Functions that are declared unsafe may call other unsafe functions
  3. Functions that are not declared unsafe may wrap calls to unsafe functions in unsafe blocks, thereby wrapping the unsafety in safety

I think this closely parallels what we're doing with purity/checking; if not it should.

@graydon
Copy link
Contributor Author

graydon commented Sep 2, 2011

it needs a special case to cover for the "scrubbing" of an unsafe function into a safe one by taking a first-class reference to it. This should be prohibited; you have to make a "safe" function (un-annotated) with an unsafe{...} block that calls the known-unsafe one.

Otherwise there's not much point checking it. This is ... really an "effect" system that doesn't handle 1st class functions. Not a very strong one; mostly just for documentation purposes.

@brson
Copy link
Contributor

brson commented Sep 2, 2011

If we went the direction of using intrinsics for unsafe pointer operations we would probably want to get rid of pointer assignment and dereferencing operations and make them intrinsics as well, for consistency.

@graydon
Copy link
Contributor Author

graydon commented Sep 6, 2011

Seems like overkill to me to be including assignment in this list. Surely "x = y" on pointer types is not a costly language feature to support. Or do you mean address-taking (unary & in C)?

Or are you thinking of removing raw pointer types altogether? Can you write down a list of the operations and types you think are important, and mark your preferred implementation technique for each (library call, language operator, type, etc.)?

@brson
Copy link
Contributor

brson commented Sep 6, 2011

I was thinking that, if we implement pointer operations mostly as library functions, then it would make sense to try not to implement pointer types in the language at all - just make them a type-parameterized tag containing an address.

@nikomatsakis
Copy link
Contributor

At this point, I have implemented unsafe functions and blocks and will be submitting pull requests today. Unsafe operations include invoking unsafe functions and dereferencing pointer types. Native functions are not unsafe by default---that was considered too much overhead for insufficient gain---but can be marked as unsafe if desired, just like other functions.

@brson
Copy link
Contributor

brson commented Oct 13, 2011

So this seems pretty well done. Do you think we're ready to close it, niko?

@nikomatsakis
Copy link
Contributor

yep. May turn out that there are a few more unsafe operations to add but that will be simple to do.

@brson brson closed this as completed Oct 13, 2011
keeperofdakeys pushed a commit to keeperofdakeys/rust that referenced this issue Dec 12, 2017
Define CLONE_NEWCGROUP

Should be fairly self explanatory.
dlrobertson pushed a commit to dlrobertson/rust that referenced this issue Nov 29, 2018
Newline in link refs to fix them
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Oct 26, 2020
Fixes rust-lang#413 and increases compatibility with cg_llvm
ZuseZ4 pushed a commit to EnzymeAD/rust that referenced this issue Mar 7, 2023
GuillaumeGomez pushed a commit to GuillaumeGomez/rust that referenced this issue Feb 21, 2024
calebzulawski added a commit to calebzulawski/rust that referenced this issue Jan 18, 2025
document PartialOrd difference to simd_min and simd_max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

4 participants