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

std.format: Make formatting 0.0 100% @nogc. #8000

Merged
merged 2 commits into from
Apr 24, 2021

Conversation

berni44
Copy link
Contributor

@berni44 berni44 commented Apr 23, 2021

Followup on #7971; see there for the roadmap.

The calls to printFloat0 are replaced by a calls to writeAligned which does the same more general and without allocating.

writeAligned needed another parameter: fractional digits are yet another stretchable element due to trailing zeros. The interpretation of precision for floating point values differs from the interpretation of it for integral values. Therefore I added an enum PrecisionType to distinguish the various meanings of precision. Eventually it will replace the boolean parameter integer_precision - for the time being I added an additional wrapper.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @berni44! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
21836 normal std.format: grouping may cause RangeError

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#8000"

@@ -925,6 +925,12 @@ if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
assert(format("%a", r) == "0x1p-20");
}

// https://issues.dlang.org/show_bug.cgi?id=21836
@safe pure unittest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nogc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not @nogc since some code paths in the called function allocate, even though those paths are not taken when called with the argument in the unit test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have an assertGCNotCalled test helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a @nogc-test in std.format.internal.floats. I think, it can be made @nogc once the three followups on this are merged and formatting floats is completely @nogc, not only zeros, nans and infs.


return result;
}

// check no allocations
@system unittest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is this test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants