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

Customize format for I32/U32 (issue #1920) #1927

Merged
merged 1 commit into from
Jun 2, 2017

Conversation

krig
Copy link
Contributor

@krig krig commented May 23, 2017

Fixes formatting of I32.min_value().

TODO: the u32 and u64 funs in _format_int.pony could probably be largely re-unified.

Fixes: #1920

@SeanTAllen
Copy link
Member

There was a TravisCI failure that was unrelated to code, it was during dependency install. Restarted that one job.

@@ -65,6 +65,40 @@ primitive _FormatInt
s.reverse_in_place()
end

fun u32(x: U32, neg: Bool, fmt: FormatInt, prefix: PrefixNumber,
prec: USize, width: USize, align: Align, fill: U32
): String iso^ =>
Copy link
Member

@SeanTAllen SeanTAllen May 24, 2017

Choose a reason for hiding this comment

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

see the style guide that is in progress for formatting on this.

#1894

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR. Something like this?

@SeanTAllen
Copy link
Member

That would fit the forthcoming style guide @krig. Yes.

@krig
Copy link
Contributor Author

krig commented May 25, 2017

Alright, great. Fixed one small formatting mistake in the previous update.

@@ -96,8 +96,10 @@ primitive Format
_FormatInt.u128(x.u128(), false, fmt, prefix, prec, width, align, fill)
elseif x is I128 then
_FormatInt.u128(abs.u128(), neg, fmt, prefix, prec, width, align, fill)
else
elseif (x is U64) or (x is I64) then
Copy link
Member

@SeanTAllen SeanTAllen May 31, 2017

Choose a reason for hiding this comment

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

there's a bug that predates your code @krig. These should be using a match expression or an iftype. The latter is preferred.

The is doesn't work as it compares identity rather than checking the type.

So x is I128 will only be triggered for the value 0. otherwise the else will always be used.

iftype A <: U128 then
  _FormatInt.u128(x.u128(), false, fmt, prefix, prec, width, align, fill)
elseif A <: I128 then
  _FormatInt.u128(abs.u128(), neg, fmt, prefix, prec, width, align, fill)
else
  _FormatInt.u64(abs.u64(), neg, fmt, prefix, prec, width, align, fill)
end

Can you make that update @krig?

@krig
Copy link
Contributor Author

krig commented May 31, 2017

@SeanTAllen I fixed the if/iftype bug, at least I think so. At the same time I thought to test if formatting min_value works for I8/I16 as well, since I suspected it didn't. And it didn't. So I implemented those as well. Ideas for how to reduce the duplication across the various int functions are welcome, I'm still very much a pony newbie :)

@krig
Copy link
Contributor Author

krig commented May 31, 2017

Hm. It also doesn't work properly for ISize or ILong. Not sure how to solve those.

@jemc
Copy link
Member

jemc commented May 31, 2017

@krig Thanks for digging into this!

For implementing the variable-sized types (ISize, USize, ILong, ULong) properly, you'll want to use ifdef to detect ilp32 and/or llp64 in order to infer the bit width of the type on the current platform. To see what I mean, please take a look at the implementations of their respective bitwidth methods - you can copy the same ifdef condition they use in those methods to infer whether to treat them as 32-bit or 64-bit in the formatting code. For example, check out the definition of ILong.bitwidth.

@krig
Copy link
Contributor Author

krig commented May 31, 2017

@jemc Ah, perfect! I'll update it.

_FormatInt.u16(abs.u16(), neg, fmt, prefix, prec, width, align, fill)
elseif A <: (U8 | I8) then
_FormatInt.u8(abs.u8(), neg, fmt, prefix, prec, width, align, fill)
elseif A <: (USize | ISize | ULong | ILong) then
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, this isn't quite right - the *Size types have different bitwidth semantics from the *Long types. Please see the definition of ISize.bitwidth().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see, thanks.

@jemc
Copy link
Member

jemc commented Jun 1, 2017

Sorry, looks like there's one more issue in the tests, where you're testing ISize but using the ifdef rule for ILong.

It's causing failures on the windows CI builds.

Fixes formatting of I32.min_value(), I16.min_value(),
etc.

TODO: the various type-specific  funs in
_format_int.pony could probably be
largely re-unified.

Update formatting to follow style
guide proposal (ponylang#1894).

Fixes: ponylang#1920
@krig
Copy link
Contributor Author

krig commented Jun 1, 2017

Good thing I added the test.. alright, this should do it.

jemc added a commit that referenced this pull request Jun 1, 2017
This is meant to prevent confusion with respect to other primitives
whose value can be compared using `is ${PrimitiveName}`. Machine words
are special primitives that can have multiple values, and comparing
with `is ${MachineWord}` is currently equivalent to comparing to zero.

Incidentally, fixing this also alerts us to the bug in #1920.

We should hold off on merging this PR until after #1927 is merged.
@jemc jemc changed the title Customize format for I32/U32 (#1920) Customize format for I32/U32 (issue #1920) Jun 2, 2017
@jemc jemc merged commit d1a8f63 into ponylang:master Jun 2, 2017
@jemc
Copy link
Member

jemc commented Jun 2, 2017

Great, thanks for bringing this one home!

@jemc jemc added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Jun 2, 2017
jemc added a commit that referenced this pull request Jun 2, 2017
@krig
Copy link
Contributor Author

krig commented Jun 2, 2017

Cool, thank you both!

@krig krig deleted the format-bug1920 branch June 2, 2017 13:22
@SeanTAllen
Copy link
Member

Awesome to see this merged! Thanks @krig. You rock.

jemc added a commit that referenced this pull request Jun 3, 2017
This is meant to prevent confusion with respect to other primitives
whose value can be compared using `is ${PrimitiveName}`. Machine words
are special primitives that can have multiple values, and comparing
with `is ${MachineWord}` is currently equivalent to comparing to zero.

Incidentally, fixing this also alerts us to the bug in #1920.

We should hold off on merging this PR until after #1927 is merged.
SeanTAllen pushed a commit that referenced this pull request Jun 3, 2017
This is meant to prevent confusion with respect to other primitives
whose value can be compared using `is ${PrimitiveName}`. Machine words
are special primitives that can have multiple values, and comparing
with `is ${MachineWord}` is currently equivalent to comparing to zero.

Incidentally, fixing this also alerts us to the bug in #1920.

We should hold off on merging this PR until after #1927 is merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants