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: Float-free libcore #1596
Conversation
rkruppe
reviewed
Apr 28, 2016
| # 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. |
This comment has been minimized.
This comment has been minimized.
rkruppe
Apr 28, 2016
Member
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?
This comment has been minimized.
This comment has been minimized.
strake
Apr 29, 2016
Author
Contributor
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, ...
rkruppe
reviewed
Apr 28, 2016
| # Alternatives | ||
| [alternatives]: #alternatives | ||
|
|
||
| * Delete all floating-point code from libcore |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
oli-obk
Apr 28, 2016
Contributor
well.. there could be a basic_core crate whose contents are the float-free part of libcore and whose contents are re-exported in libcore
This comment has been minimized.
This comment has been minimized.
strake
Apr 29, 2016
Author
Contributor
Noted.
This will never happen.
I believe this is true of many alternatives to RFCs ☺
rkruppe
reviewed
Apr 28, 2016
| # Unresolved questions | ||
| [unresolved]: #unresolved-questions | ||
|
|
||
| None so far |
This comment has been minimized.
This comment has been minimized.
rkruppe
Apr 28, 2016
Member
I can think of one: If compiling code with cfg(target_has_floating_point), is it legal to use the f32 and f64 types?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
cc @phil-opp |
strake
added some commits
Apr 29, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @emk who was also interested in this |
aturon
added
T-libs
final-comment-period
labels
Apr 29, 2016
aturon
self-assigned this
Apr 29, 2016
mcarton
referenced this pull request
Apr 29, 2016
Closed
Lint basic arithmetic on integers or floating point arithmetic #887
This comment has been minimized.
This comment has been minimized.
ketsuban
commented
Apr 29, 2016
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. |
This comment has been minimized.
This comment has been minimized.
|
There was an interesting idea proposed in the internals thread:
Like |
This comment has been minimized.
This comment has been minimized.
eternaleye
commented
May 2, 2016
•
|
@Amanieu, I disagree it's a "cleaner" solution:
Splitting |
aturon
removed
the
final-comment-period
label
May 2, 2016
strake
added some commits
May 3, 2016
This comment has been minimized.
This comment has been minimized.
|
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: |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
DemiMarie
commented
May 4, 2016
|
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. |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
I'm thinking we ought await the judgement of PR 1133, which, if accepted, might mitigate some of the worries raised here. |
This comment has been minimized.
This comment has been minimized.
phil-opp
commented
May 13, 2016
|
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 |
This comment has been minimized.
This comment has been minimized.
|
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 = falseGiven backwards compatibility, I think that opt-out is the best we can do. |
This comment has been minimized.
This comment has been minimized.
emk
commented
May 15, 2016
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 |
This comment has been minimized.
This comment has been minimized.
|
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! |
This comment has been minimized.
This comment has been minimized.
jdub
commented
Jul 31, 2016
|
Worth checking recent activity in #1364 re: soft-float. |
This comment has been minimized.
This comment has been minimized.
|
Note: there's now an RFC for a portability lint, which should pave the way for handling this case. |
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/libs: at what point are we comfortable moving forward with RFCs like this, given the state of play with the portability lint? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 1, 2017
•
|
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. |
This comment has been minimized.
This comment has been minimized.
|
@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 |
This comment has been minimized.
This comment has been minimized.
emk
commented
Feb 7, 2017
|
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 |
This comment has been minimized.
This comment has been minimized.
phil-opp
commented
Feb 7, 2017
|
@emk I use |
This comment has been minimized.
This comment has been minimized.
emk
commented
Feb 7, 2017
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
I second @phil-opp here; we have no issues with using libcore today. |
This comment has been minimized.
This comment has been minimized.
|
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. |
strake commentedApr 28, 2016
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.