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 upRFC: Stabilize the #![no_std] attribute #1184
Conversation
alexcrichton
self-assigned this
Jun 30, 2015
alexcrichton
added
the
T-libs
label
Jun 30, 2015
eddyb
reviewed
Jul 1, 2015
| addition to the interface that it will be stabilized with. Each lang item will | ||
| no longer be defined with the `#[lang = "..."]` syntax but will instead receive | ||
| a dedicated attribute (e.g. `#[panic_fmt]`) to be attached to functions to | ||
| identify an implementation. |
This comment has been minimized.
This comment has been minimized.
eddyb
Jul 1, 2015
Member
These are already special-cased as "weak lang items" so using a mechanism different from regular lang items is not that much of a compromise IMO, but it would be nice if the existing situation was mentioned in the RFC.
This comment has been minimized.
This comment has been minimized.
nagisa
Jul 1, 2015
Contributor
Why?
I really like how current #[lang] works and that it is easy to grep for it, etc. I also believe it would be not too hard to stabilise #[lang="*"] only for certain *. That being said, I
This comment has been minimized.
This comment has been minimized.
eddyb
Jul 1, 2015
Member
They aren't really lang items, but rather a minimal set of compiler-sanctioned weak import/exports.
Libraries could be allowed to define custom "pluggable items" and then these 3 would not be known to the language, just libcore and its users.
This comment has been minimized.
This comment has been minimized.
|
Can we avoid stabilizing the lang items but do the rest? That will mean libcore is only stable to use when std is also linked, but I don't think that is a problem (for now). We still get the benefits of making the macros use core, and anybody actually writing kernel code will need unstable core features anyways. There is a lot of jank in some those lang items as the RFC admits, and |
This comment has been minimized.
This comment has been minimized.
Tobba
commented
Jul 1, 2015
|
I propose that |
Tobba
reviewed
Jul 1, 2015
| ``` | ||
|
|
||
| This differs with the `panic_fmt` function today in that the file and line | ||
| number arguments are omitted. The libcore library will continue to provide |
This comment has been minimized.
This comment has been minimized.
Tobba
Jul 1, 2015
What's the rationale behind this change? This was convenient for formatting reasons, and I don't see why it should go.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 1, 2015
Author
Member
We don't necessarily want to commit to providing a filename/line number in all panic messages as there have been musings in the past that a measurable overhead in terms of binary size and runtime is incurred from having all these strings/numbers in the binary.
Tobba
reviewed
Jul 1, 2015
| instead of taking it by value, and the purpose of this is to ensure that the | ||
| function has a clearly defined ABI on all platforms in case that is required. | ||
|
|
||
| #### `eh_personality` |
This comment has been minimized.
This comment has been minimized.
Tobba
Jul 1, 2015
Both this and stack_exhausted seem like rather bad candidates for stabilization: they're both implementation details of the platform and compiler.
This comment has been minimized.
This comment has been minimized.
Tobba
commented
Jul 1, 2015
|
Proposal: don't stabilize any lang items at all, due to the aforementioned arguments. One of the current major problems of no_std is that writing libraries that work across both settings is very tedious - it currently involves maintaining a tangled mess of #[cfg] attributes which is rarely tested before release. Stabilizing lang items do nothing to improve this situation anyways. |
This comment has been minimized.
This comment has been minimized.
|
I agree about not stabilizing any language items here, if this is just for allowing However - if stabilizing these language items will allow compilation of no_std binaries (using an externally defined entrypoint, instead of |
This comment has been minimized.
This comment has been minimized.
|
Overall, I'm convinced over the long haul we can reduce the complexity of these implementation details (w.g.. with crate functors, stabilized rust without exceptions), so I rather leave them unstable as long as possible. Complexity is worse than instability for the foreseeable future. |
This comment has been minimized.
This comment has been minimized.
|
@Tobba I thought |
This comment has been minimized.
This comment has been minimized.
Tobba
commented
Jul 1, 2015
|
@eddyb As far as I know it only works for referencing the current crate. |
petrochenkov
reviewed
Jul 1, 2015
|
|
||
| ```rust | ||
| #[panic_fmt] | ||
| pub extern fn panic_fmt(msg: &core::fmt::Arguments) -> !; |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Jul 1, 2015
Contributor
It doesn't feel right for me that functions deeply internal to Rust are stabilized as extern "C". Is anybody going to import them from C code? Do they need more ABI stability than any other functions?
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 1, 2015
Author
Member
A possible extension one day could be to allow to define these kinds of lang items in other languages (e.g. C), so I figured it would be nice to have a defined ABI to leave the door open to that possibility.
nagisa
reviewed
Jul 1, 2015
|
|
||
| ```rust | ||
| #[stack_exhausted] | ||
| pub extern fn stack_exhausted() -> !; |
This comment has been minimized.
This comment has been minimized.
nagisa
Jul 1, 2015
Contributor
This being a diverging function restricts
the implementation of what happens on stack overflow
to terminating the program. I don’t see how you could reallocate a bigger stack and return to normal execution. for example.
This comment has been minimized.
This comment has been minimized.
eddyb
Jul 1, 2015
Member
That's not supported, our abuse of segmented stacks will be removed as soon as LLVM gets proper support for stack probes across all platforms.
IIRC there are some patches waiting to be reviewed and merged (cc @Zoxc).
This comment has been minimized.
This comment has been minimized.
nagisa
Jul 1, 2015
Contributor
our abuse of segmented stacks will be removed as soon as LLVM gets proper support for stack probes across all platforms.
Aware. What I’m just pointing out the function doesn’t exactly work as advertised just above it.
On Windows, where this abuse is not done, this “language item” is not used at all, so I’m doubtful this needs to be stabilised.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 1, 2015
Author
Member
I agree with @eddyb that there's really no way this function could ever return, adding segmented stacks back is likely to be a much more invasive change than just affecting this function.
This comment has been minimized.
This comment has been minimized.
huonw
Jul 1, 2015
Member
We can presumably generalise the signature in future if we find use-cases for other ones.
steveklabnik
reviewed
Jul 1, 2015
| library. This means that users of `#![no_std]` will have to reimplement all of | ||
| this functionality themselves. | ||
|
|
||
| This RFC does not yet pave a way forward for using `#![no_std]` and producing an |
This comment has been minimized.
This comment has been minimized.
steveklabnik
Jul 1, 2015
Member
I would argue that it is paving a way forward, but it's just not there yet. These are the first steps.
alexcrichton
added some commits
Jul 1, 2015
This comment has been minimized.
This comment has been minimized.
|
@Ericson2314, @Tobba, @thepowersgang
This is certainly an alternative! (which I have now added) The consequence of this decision is there will be no stable method of producing a staticlib or dylib which uses
Unfortunately I think this is not backwards compatible.
That's a good point, I've added a drawback to this RFC. |
alexcrichton
referenced this pull request
Jul 2, 2015
Closed
Always depends on std when built with cargo #14
This comment has been minimized.
This comment has been minimized.
|
What's the point of stabilizing It makes zero sense to require users to provide an implementation of A variant of the |
This comment has been minimized.
This comment has been minimized.
|
@eefriedman libcore can panic (and thus unwind), that's why this weak lang item contraption exists in the first place. |
This comment has been minimized.
This comment has been minimized.
|
@eddyb libcore can panic, sure, but without libstd's implementation of panic_fmt, it isn't possible to actually unwind. |
This comment has been minimized.
This comment has been minimized.
|
@eefriedman As a practical matter, I think rustc demands
Again, I don't think instability around Rust in the kernel is a problem, now or in the foreseeable future. Stabilizing |
This comment has been minimized.
This comment has been minimized.
daboross
commented
Jul 4, 2015
|
Would it make sense to just have one attribute, something like |
This comment has been minimized.
This comment has been minimized.
|
@daboross |
This comment has been minimized.
This comment has been minimized.
Virtlink
commented
Jul 7, 2015
|
All crates (including libstd) should be treated equally. There should be nothing that libstd can do that any other crate can't. Firstly, I'd agree with @eddyb: introduce Then for at least Finally, by default any Rust crate would implicitly include |
This comment has been minimized.
This comment has been minimized.
The question about what to do with preludes is somewhat orthogonal to the
The problem with this is that Rust isn't very useful without |
This comment has been minimized.
This comment has been minimized.
|
My first priority is not stabilizing those lang items, but I'd prefer @eddyb's end goal too. Treating all crates as equally as possible an admirable goal, and one In fact if we had proper glob-import priority like @eddyb requests, we could just do something like: extern crate core;
use core::prelude_v1::*;Even simpler! Edit: proper glob-import priority, and crate-wide imports for exactly that. |
alexcrichton commentedJun 30, 2015
Stabilize the
#![no_std]attribute while also improving the ergonomics ofusing libcore by default. Additionally add a new
#![no_core]attribute to optout of linking to libcore.
rendered