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

Add RFC for new intrinsic design #8

Merged
merged 2 commits into from
Apr 7, 2014
Merged

Conversation

brson
Copy link
Contributor

@brson brson commented Mar 15, 2014

@bnoordhuis
Copy link

Seems reasonable to me FWIW. One question, the RFC mentions:

rustc is forced to inline a great number of tiny intrinsic wrappers, which is bad for both compile-time performance and runtime performance without optimizations.

Does that mean that the #[intrinsic] attribute is implicitly #[inline(always)], #[inline(never)] or neither?

@brson
Copy link
Contributor Author

brson commented Mar 15, 2014

@bnoordhuis it's inline(always) but the inlining is done in the front end.


The compiler will type check and translate intrinsics the same as today.
Additionally, when trans sees a "Rust" extern tagged as an intrinsic
it will not emit a function declaration to LLVM bitcode.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could paragraph could mention that forced inlining is done in the front-end. That wasn't obvious (to me at least) until @brson clarified it.

@Aatch
Copy link
Contributor

Aatch commented Mar 25, 2014

Hmm, looks ok to me, but is very sparse on the details.

I'd like to see intrinsics given a little more room in the language, as they are (to me at least) inherently there for bypassing the language semantics (or producing faster code, but that's just a bonus). However currently they are significantly hamstrung by the fact that the typechecker and other parts treat them the same as any other function call, meaning that you either get "type" errors in trans or an explosion of functions that shouldn't really exist.

@nikomatsakis
Copy link
Contributor

@brson while this looks relatively ok to me, I feel like this is missing a big part of what we discussed: in particular, didn't we intend to impose constraints on the type parameters with which transmute can be instantiated? I had hoped to address the problem of transmuting between types of different sizes this way, but also possibly to remove the possibility of "const-casts" (which are undefined behavior) so as to channel interior mutability through Unsafe<T>. (See rust-lang/rust#13146.)

@huonw
Copy link
Member

huonw commented Mar 26, 2014

@nikomatsakis would that theoretically require a new kind like T: SameSizeAs<u64> for transmute to be used on generics?

I'd guess one can use macros in those cases, especially since it seems highly likely that any generic function that transmutes a plain generic (i.e. not behind a pointer or anything) is just a small helper, which a macro is perfect for.

@nikomatsakis
Copy link
Contributor

@huonw if we wanted to enable it, then yes, something like that -- or maybe TransmutableTo. In general, transmute applied to raw generic types is a dangerous sign -- but it can be used legitimately, if the caller controls all types that it will ever be used on.

Private traits still offer a reasonable alternative. You can create a private trait like:

trait TransmutableTo<T> { 
    unsafe fn transmute_to(from: self) -> T;
}

and replace your calls to transmute with TransmutableTo::transmute_to().

Then you just impl that trait for each of the types you expect to use it with:

impl TransmutableTo<Target> for Source {
    unsafe fn transmute_to(self) -> Target { cast::transmute() }
}
...

This is more-or-less what you suggested, but I am not advocating it as a public trait, just something people can use in specific cases. I'd be interested to know if there are legit use cases involving a family of types but not involving pointer indirection.

(Note that the ability to transmute &T to &U, if supported, naturally limits our ability to prevent const casts, but it's still worth trying imo.)

@brson
Copy link
Contributor Author

brson commented Mar 28, 2014

@nikomatsakis I consider the restrictions on transmute to be a seperate issue: rust-lang/rust#12898

@nikomatsakis
Copy link
Contributor

@brson oh, ok, I forgot about that (even though I apparently commented)

@alexcrichton alexcrichton merged commit ef22d54 into rust-lang:master Apr 7, 2014
huonw added a commit to huonw/rfcs that referenced this pull request May 17, 2014
huonw added a commit to huonw/rfcs that referenced this pull request May 17, 2014
glaebhoerl pushed a commit to glaebhoerl/rfcs that referenced this pull request Aug 8, 2014
withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
alexcrichton pushed a commit that referenced this pull request Jul 13, 2017
@Centril Centril added A-intrinsic Proposals relating to intrinsics. A-typesystem Type system related proposals & ideas A-machine Proposals relating to Rust's abstract machine. A-syntax Syntax related proposals & ideas A-attributes Proposals relating to attributes labels Nov 23, 2018
epage pushed a commit to epage/rfcs that referenced this pull request Nov 13, 2023
Update summary to focus on `::` semantics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Proposals relating to attributes A-intrinsic Proposals relating to intrinsics. A-machine Proposals relating to Rust's abstract machine. A-syntax Syntax related proposals & ideas A-typesystem Type system related proposals & ideas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants