Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSafe intrinsics RFC #1248
Conversation
This comment has been minimized.
This comment has been minimized.
|
Should we instead make intrinsics safe by default and then add an |
nikomatsakis
added
the
T-lang
label
Aug 11, 2015
This comment has been minimized.
This comment has been minimized.
|
I'm marking this as T-lang, since I feel like the approach to intrinsics is fundamentally a language decision, but obviously this impacts libs too. |
This comment has been minimized.
This comment has been minimized.
|
I feel like intrinsics and lang items serve very similar purposes and I am not convinced we should have both of them. It feels like we could remove all intrinsics and replace them with lang items, which can assume arbitrary signatures -- we could then have the compiler have particular semantics when it calls a lang item. Frequently, I would imagine, the body of those lang items would be irrelevant, as the compiler will supply it (perhaps just |
This comment has been minimized.
This comment has been minimized.
|
This would rather mess the plan for SIMD intrinsics. Maybe allow "#[safe]" for FFI functions too? Why not just write a wrapper? Thinking about it, maybe an |
This comment has been minimized.
This comment has been minimized.
|
I agree that it's somewhat annoying that safe intrinsics have to be declare unsafe, but having to write a wrapper generally seems like it's just a bit of an annoyance. Two thoughts:
|
This comment has been minimized.
This comment has been minimized.
|
LLVM does not notice |
This comment has been minimized.
This comment has been minimized.
True, though I guess I've never been crazy about the ducktyping part of the plan anyway. That said, you can imagine handling SIMD intrinsics through some other attribute like UPDATE: Edited for clarity. |
This comment has been minimized.
This comment has been minimized.
...or just allow a "simd" lang item to be defined any number of times. |
This comment has been minimized.
This comment has been minimized.
|
It seems a bit strange to me to have hundred/thousands of lines of code like #[simd_operation(x86_mm_sad_epu8)]
fn x86_mm_sad_epu8(x: u8x16, y: u8x16) -> u8x16 { panic!() } |
This comment has been minimized.
This comment has been minimized.
|
What if you tie (default) unsafety to the calling convention rather than whether it is in an |
nrc
reviewed
Aug 13, 2015
|
|
||
| * Remove the restriction that the attribute is only valid on intrinsics. This runs counter to the | ||
| idea that functions we don't know the bodies of are presumed unsafe. | ||
| * Hard-code the safety for each intrinsic. This ensures consistency since you can declare the |
This comment has been minimized.
This comment has been minimized.
nrc
Aug 13, 2015
Member
IS this suggestion saying that we treat intrinsics as safe by default and then add unsafe keywords to the unsafe one? If not, is that a possibility? It seems nice in that we treat intrinsics like other functions (although not like FFI functions which are arguably more similar) and it doesn't need a new attribute.
This comment has been minimized.
This comment has been minimized.
eddyb
Aug 13, 2015
Member
I believe it's saying "leave the declarations in libcore exactly as they are and compute the unsafety of the fn type based on the name".
This comment has been minimized.
This comment has been minimized.
Good case for a macro? We probably want one anyway, since libraries that re-declare these intrinsics will need a similar array of such declarations. Anyway, taking a step back, clearly I'm proposing something somewhat orthogonal to this RFC, except that:
|
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis If we stop using extern "C++" {
fn vector_push<T>(v: *mut stl::vector<T>, x: T) {
v->push_back(x);
}
}I believe @mystor's crate is somewhat similar, although implemented via a plugin. |
This comment has been minimized.
This comment has been minimized.
mystor
commented
Aug 13, 2015
|
@eddyb, rust-cpp is similar in idea (body of code is C++, types declared in Rust & translated using simple-ish set of rules), however definitely doesn't support generics, or anything complicated, yet (I imagine that that would take more compiler support/hackery) ^.^ (sorry about off-topic) |
nikomatsakis
self-assigned this
Aug 13, 2015
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp close I move that we close this RFC. Not because I disagree with the sentiment: I think we will want to eventually have both safe and stable intrinsics. However, I would like to change the way we achieve that: I think it'd be better to just merge the idea of "intrinsics" and "lang items" -- so that an intrinsic is just a function with a suitable attribute. I think the usual form would be as follows (hat tip to @eddyb): #[lang name="special"]
fn special(x, y, z) -> T {
special(x, y, z)
}Having the fn calls itself is basically a convenient hack. This way, the compiler can detect direct calls to |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 11, 2016
•
|
Team member @nikomatsakis has proposed to close this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis I'm in favor of a merger between lang items and intrinsics. This is a question we'll want to be thinking about as part of the recent work on SIMD, of course. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Dec 1, 2016
|
|
rfcbot
added
the
final-comment-period
label
Dec 1, 2016
This comment has been minimized.
This comment has been minimized.
That's basically how |
This comment has been minimized.
This comment has been minimized.
|
@arielb1 Yeah, I think it's effectively the exact same idea. |
aturon
referenced this pull request
Dec 13, 2016
Closed
rfcbot is not posting that FCP is complete #117
This comment has been minimized.
This comment has been minimized.
|
The RFC bot seems to be stuck, but at this point the final comment period has elapsed. Nothing has changed since the earlier summary, so I'm going to go ahead and close the RFC. Let's revisit with a merger with lang items. Thanks, @Aatch, for the RFC! |
aturon
closed this
Dec 13, 2016
dtolnay
referenced this pull request
Nov 14, 2017
Closed
likely/unlikely intrinsics don't need unsafe #45445
This comment has been minimized.
This comment has been minimized.
|
Is there an issue tracking the idea to merge "intrinsics" and "lang items"? |
This comment has been minimized.
This comment has been minimized.
|
@dtolnay I don't think they'll ever be merged since they represent opposite directions of communication between the compiler and libraries. However, I still think |
Aatch commentedAug 11, 2015
Allow intrinsics to be marked as safe, overriding the implicit
unsafefrom being in anexternblock.Rendered