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

Add support for different sized integers #178

Merged
merged 4 commits into from
Nov 21, 2021

Conversation

matthiasbeyer
Copy link
Collaborator

This also enables support for 128 bit integers.
Nothing is tested, though.


I guess this is a draft for now.

@matthiasbeyer
Copy link
Collaborator Author

This is related to #161 and #167

@Nukesor
Copy link

Nukesor commented Mar 17, 2021

Great to see you taking care of the project!

Cheers

@matthiasbeyer
Copy link
Collaborator Author

Thanks ❤️

@matthiasbeyer
Copy link
Collaborator Author

So, I guess this PR should add a bunch of tests to check

  • Are the right integer types are used
  • Do things fail properly if the size of the types in use are wrong
  • Edgecases (i8::MAX vs u8::MAX) - any maybe we can add u... support as well
  • possibly more

@matthiasbeyer
Copy link
Collaborator Author

Hm, so after some more investigation: Our backend crates do not support integers smaller than i64. So I guess there's no point in supporting them either, is there?

@matthiasbeyer
Copy link
Collaborator Author

@Nukesor and @nagisa - would you like to review my patchset here? There are too few tests, if you can provide some, that'd be awesome, too!

@matthiasbeyer matthiasbeyer marked this pull request as ready for review March 26, 2021 16:13
/// Returns `self` into an i128, if possible.
pub fn into_int128(self) -> Result<i128> {
match self.kind {
ValueKind::I64(value) => Ok(value as i128),
Copy link

Choose a reason for hiding this comment

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

Consider .into() instead of casting.

)),

ValueKind::String(ref s) => {
match s.to_lowercase().as_ref() {
Copy link

Choose a reason for hiding this comment

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

Why do we do this, but don't transparently allow, say, u128 values that are in range of i128 to convert to i128?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess you wanted another line to be commented here? I will investigate where we can do this, yes!

Copy link

Choose a reason for hiding this comment

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

No, I meant to ask why we transparently convert strings like yes or no to integers, but not integers to other integers. Seemed somewhat counterintuitive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, now I see what you mean.

This patch tries to mimic the behavior of the non-int128 code... I agree that this might be not what we want for the next release, but I would introduce a change to that behavior in another PR, not in this one.

@nagisa
Copy link

nagisa commented Mar 26, 2021

This broadly LGTM, but I have no say over this project, really.

@matthiasbeyer
Copy link
Collaborator Author

Still, your opinion matters to me. Thanks for the review!

@matthiasbeyer
Copy link
Collaborator Author

Rebased on master. Still not sure whether I should merge this or not.

This also enables support for 128 bit integers.
Nothing is tested, though.

Signed-off-by: Matthias Beyer <[email protected]>
Signed-off-by: Matthias Beyer <[email protected]>
All our backend crates do not support integers smaller than i64, so
there's no point in supporting them either.

Signed-off-by: Matthias Beyer <[email protected]>
@matthiasbeyer
Copy link
Collaborator Author

Updated to master, will merge if CI succeeds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Accepted PR for hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants