-
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
RFC: Float-free libcore #1596
RFC: Float-free libcore #1596
Conversation
# Detailed design | ||
[design]: #detailed-design | ||
|
||
Add an optional `has_floating_point` property, default true, gated as `cfg_target_has_floating_point`. Disable all floating-point use in libcore if this flag is false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in the motivation section, this flag needs to affect code generation, not only Rust code. Throwing cfg(target_has_floating_point)
is the easy part, what's the detailed design for the code generation changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The notion is, this flag merely disables all floating-point code in libcore, and the "features" flag affects code generation. So one would define a target with has_floating_point: false and features: -mmx, -sse, ...
cc @phil-opp |
cc @emk who was also interested in this |
My gut instinct is to say no, with the provision that a future RFC can specify soft-float lang items which if provided would unlock these types in “float-free” code. |
There was an interesting idea proposed in the internals thread:
Like |
@Amanieu, I disagree it's a "cleaner" solution:
Splitting |
Responding to @brson's comment in internals thread: I tried to clarify and noted the points you made. About this in particular:
I had an idea, noted briefly as alternative in RFC: |
I definitely prefer the feature route, as eloquently articulated in @eternaleye's post. Additionally, with the current route, code can be "silently" non-portable which is never a good thing. It may still be good to add the field to the target spec insofar as that allows one to indicate the feature is unavailable on platforms without it. |
I think there should also be an unsafe way that a library that does use floating point can be explicitly linked into an otherwise float-free kernel codebase. Specifically, Linux allows for the use of floating point on some architectures by explicitly saving and restoring the FPU/SIMD/etc state, and Rust should allow this. |
@drbo Cargo assumes its always safe to build deps with more features than required, and since the the float feature would simply add more definitions, this is actually the case. The whole build can be performed with the float-supporting target configuration and things should just work. |
I'm thinking we ought await the judgement of PR 1133, which, if accepted, might mitigate some of the worries raised here. |
I think the fundamental issue is: Rust assumes that all targets support Almost all targets have floating point support (either in hardware or in software), but there are a few exceptions (e.g. We have the following options:
Personally, I'm happy with option 3, because only few special-purpose targets have neither hard- nor soft-float. However, I think there should be some way to build This could be either a cargo feature or an option in the target file. Personally, I prefer the target file option because… well, it's a property of the target. It allows other library authors to conditionally exclude floats if they want to. It also makes it easy to build a cross sysroot using xargo. This RFC does not make anything worse. It just adds a new target property to describe that a target supports neither hard- nor soft-floats. Then it uses this property to allow compiling |
I should also add, this is one of the downsides of having our primitive types always in scope, rather than just exposed as lang items. Had we taken the latter route, we could just cfg them too out in libcore, and not only would the operations on those types be gone, but the type itself would be too. @phil-opp The slight area where this makes things worse is downstream crates don't express whether they need float support or not from core. That is what I meant by "'silently' unportable" in #1596 (comment) in the Cargo file or even source---of the downstream crate opts-in to non-portability. But if core had a float feature, enabled by default, downstream crates can signify they are float-free, by doing something like: [dependencies.core]
default-features = false Given backwards compatibility, I think that opt-out is the best we can do. |
Yeah, essentially you can divide targets into two types:
This issue comes up because Rust is just an absolutely terrific language for (2), and people want to use it there. (And it's only going to become more tempting with recent improvements to cross-compilation.) But in this case, they're probably also using
Opt-out is appropriate here, I think. Rust and Cargo should assume that |
Heads-up: I've opened a discuss thread for talking about how we want to handle some of these API questions in general. Please join in! |
Worth checking recent activity in #1364 re: soft-float. |
Note: there's now an RFC for a portability lint, which should pave the way for handling this case. |
@rust-lang/libs: at what point are we comfortable moving forward with RFCs like this, given the state of play with the portability lint? |
Team member @aturon 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. |
@Amanieu while that is true generally, someone has been having a lot of trouble with it lately: https://users.rust-lang.org/t/kernel-modules-made-from-rust/9191/11 |
I would be reluctant to close this issue unless @steveklabnik and other people doing embedded work can actually confirm that @Amanieu's proposal works in practice. Does anybody have a good test case with |
@emk I use |
@phil-opp Thank you, that sounds great! As one of the original interested parties, I'm personally content with a fix using This probably means that if somebody needs to port Rust an embedded platform, they might also need to fix LLVM |
I second @phil-opp here; we have no issues with using libcore today. |
OK, we discussed this in libs triage, and it appears that for the time being everyone is happy with soft floats as a solution. We're happy to revisit this later if it turns out there's a need for it. I'm closing in the meantime. |
phil-opp made the PR on rust-lang/rust repo, but this is blocking me so i wrote the RFC. phil-opp is welcome to claim this from me if they wish.