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

dec2flt: Clean up float parsing modules #134063

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Dec 9, 2024

This is the first portion of my work adding support for parsing and printing f16. Changes in float.rs replace the magic constants with expressions and add some use of generics to better support the new float types. Everything else is related to documentation or naming; there are no functional changes in this PR.

This can be reviewed by commit.

These constants can be useful outside of their current module. Make them
`pub(crate)` to allow for this.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 9, 2024
Fix or elaborate existing float parsing documentation. This includes
introducing a convention that should make naming more consistent.
This module currently contains two decimal types, `Decimal` and
`Number`. These names don't provide a whole lot of insight into what
exactly they are, and `Number` is actually the one that is more like an
expected `Decimal` type.

In accordance with this, rename the existing `Decimal` to `DecimalSeq`.
This highlights that it contains a sequence of decimal digits, rather
than representing a base-10 floating point (decimal) number.

Additionally, add some tests to validate internal behavior.
The previous commit renamed `Decimal` to `DecimalSeq`. Now, rename the
type that represents a decimal floating point number to be `Decimal`.

Additionally, add some tests for internal behavior.
@tgross35 tgross35 force-pushed the dec2flt-refactoring branch from c2f95c2 to 3fa1f00 Compare December 9, 2024 09:46
@tgross35 tgross35 changed the title dec2fl2: Refactor float parsing dec2fl2: Clean up float parsing modules Dec 9, 2024
@tgross35 tgross35 force-pushed the dec2flt-refactoring branch 2 times, most recently from e4cb494 to 058be88 Compare December 9, 2024 09:58
A lot of the magic constants can be turned into expressions. This
reduces some code duplication.

Additionally, add traits to make these operations fully generic. This
will make it easier to support `f16` and `f128`.
This is just a bit of code cleanup to make use of returning early.
@tgross35 tgross35 force-pushed the dec2flt-refactoring branch from 058be88 to 89f2066 Compare December 9, 2024 09:59
@tgross35 tgross35 marked this pull request as ready for review December 9, 2024 10:04
@tgross35
Copy link
Contributor Author

tgross35 commented Dec 9, 2024

r? libs

@tgross35 tgross35 changed the title dec2fl2: Clean up float parsing modules dec2flt: Clean up float parsing modules Dec 9, 2024
@Noratrieb
Copy link
Member

I'm by no means an expert in float parsing, but this change is mostly mechanical, so I do feel comfortable approving it. I looked through each commit and the changes seemed reasonable. For the float trait refactor I did take a closer look but a mistake there could have definitely slipped by (though I guess that's always true), but I assume you also ran the detailed float parsing tests (I think they don't run in CI) to ensure it still works as intended.

@bors r+

@bors
Copy link
Contributor

bors commented Dec 31, 2024

📌 Commit 89f2066 has been approved by Noratrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 31, 2024
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Dec 31, 2024
…ratrieb

dec2flt: Clean up float parsing modules

This is the first portion of my work adding support for parsing and printing `f16`. Changes in `float.rs` replace the magic constants with expressions and add some use of generics to better support the new float types. Everything else is related to documentation or naming; there are no functional changes in this PR.

This can be reviewed by commit.
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 31, 2024
Rollup of 9 pull requests

Successful merges:

 - rust-lang#132474 (Add more mailmap entries)
 - rust-lang#133486 (borrowck diagnostics: make `add_move_error_suggestions` use the HIR rather than `SourceMap`)
 - rust-lang#134063 (dec2flt: Clean up float parsing modules)
 - rust-lang#134861 (Add GUI test for item info elements color)
 - rust-lang#134968 (Print how to rebless Python formatting in tidy)
 - rust-lang#134971 (chore: fix typos)
 - rust-lang#134972 (add .mailmap entry for myself)
 - rust-lang#134974 (Revert rust-lang#119515 single line where clause style guide)
 - rust-lang#134975 (Revert style guide rhs break)

r? `@ghost`
`@rustbot` modify labels: rollup
@tgross35
Copy link
Contributor Author

but I assume you also ran the detailed float parsing tests (I think they don't run in CI) to ensure it still works as intended.

Just to confirm, these do still pass. We run a few minutes of edge cases in CI but the test-float-parse crate needs to be run locally to get the full few hours of exhaustive (f32) / fuzz (f64) tests.

I'm by no means an expert in float parsing

I don't think anyone here is, I'm doing a lot of reverse engineering and the people who authored this implementation don't seem to be active anymore either 😞 but thanks for the review!

@tgross35
Copy link
Contributor Author

Agh the exhaustive tests pass but one of the newer edge case tests failed when I tested with a rebase. Looks like I need to adjust something here.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants