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

Remove unused base64.encode overload #20369

Merged
merged 21 commits into from
Oct 9, 2022

Conversation

AmjadHD
Copy link
Contributor

@AmjadHD AmjadHD commented Sep 16, 2022

No description provided.

lib/pure/base64.nim Outdated Show resolved Hide resolved
@Varriount
Copy link
Contributor

Do we know why this procedure was added in the first place?

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Sep 20, 2022

There was the string overload, then the openarray overload was added in 6901a8c (#646), Ig the author wasn't aware that string is compatible with openArray[char].

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Sep 20, 2022

Is it ok to have an overload for integer types of arbitrary sizes. Shouldn't the input be byte strings.

@Varriount
Copy link
Contributor

Please add a changelog entry, then this can be merged.

Is it ok to have an overload for integer types of arbitrary sizes. Shouldn't the input be byte strings.

Is this a question? And if so, what code are you referencing?

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Sep 21, 2022

Please add a changelog entry, then this can be merged.

Is this needed, from the user's perspective nothing changed.

Is it ok to have an overload for integer types of arbitrary sizes. Shouldn't the input be byte strings.

Is this a question? And if so, what code are you referencing?

Yes, https://github.com/nim-lang/Nim/pull/20369/files#diff-cc4f63a53ac195237326427c11b84c89967c417d474b4cd55ad54b48a09c9a1cL144.
This overload takes arbitrary integer types and wraps the values that do not fit in 1 byte, Is this behaviour desired or should it error instead ?

@Varriount
Copy link
Contributor

Can you give an example of what happens with 1-byte integers, vs multi-byte integers?

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Sep 21, 2022

import std/base64

var x = @[72, 101, 108, 108, 111] # Hello
let e = encode(x)
x[0] += 256
assert encode(x) == e

@Varriount
Copy link
Contributor

Hm. I don't know.
I would expect is one of the following:

  • When given a multi-byte integer, encode would output multiple characters.
  • encode would not accept multi-byte integers.

Both are breaking changes, though the current behavior is arguably a bug. I would implement #2 first, and see how many, if any, packages that breaks.

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Sep 22, 2022

I tried T: range[0..255]|uint8|char but this doesn't work even for encode [10].

@arnetheduck
Copy link
Contributor

for reference, the API we use is: https://github.com/status-im/nim-stew/blob/master/stew/base64.nim (notably, there are many "base64" alphabet standards)

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Sep 26, 2022

Should I change T: byte|char then and deprecate the T: SomeInteger overload ?

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Sep 26, 2022

I tried T: range[0..255]|uint8|char but this doesn't work even for encode [10].

Why doesn't it work ?

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Oct 1, 2022

cc @Varriount ^.

@Araq
Copy link
Member

Araq commented Oct 1, 2022

Instead of T: range[0..255]|uint8|char use T: byte|char

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Oct 1, 2022

@Araq, What about code like encode @[111, 113, 32] ? should it be deprecated ?

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Oct 2, 2022

@Araq is this fine ?

@Araq
Copy link
Member

Araq commented Oct 3, 2022

@Araq, What about code like encode @[111, 113, 32] ? should it be deprecated ?

I think so but there is no RFC for it so better leave it as it is.

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Oct 4, 2022

Can this be merged now ?

@@ -144,40 +146,23 @@ template encodeImpl() {.dirty.} =
proc encode*[T: SomeInteger|char](s: openArray[T], safe = false): string =
Copy link
Member

Choose a reason for hiding this comment

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

So ... you left this one as SomeInteger? Bad idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Araq, What about code like encode @[111, 113, 32] ? should it be deprecated ?

I think so but there is no RFC for it so better leave it as it is.

So code like that just breaks ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, so can you explain why this procedure was left as-is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait, so can you explain why this procedure was left as-is?

@Araq, What about code like encode @[111, 113, 32] ? should it be deprecated ?

I think so but there is no RFC for it so better leave it as it is.

" leave it as it is"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Araq please clarify what you want:

  1. T: byte|char
  2. T: byte|char and deprecate T: SomeInteger and not byte
  3. T: SomeInteger|char

Copy link
Member

Choose a reason for hiding this comment

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

(2)

@AmjadHD
Copy link
Contributor Author

AmjadHD commented Oct 8, 2022

@Araq merge this please.

lib/pure/base64.nim Outdated Show resolved Hide resolved
@Varriount Varriount merged commit 944e4cf into nim-lang:devel Oct 9, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2022

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 944e4cf

Hint: mm: orc; opt: speed; options: -d:release
162851 lines; 9.323s; 614.402MiB peakmem

@AmjadHD AmjadHD deleted the pr-remove-encode-overload branch October 10, 2022 11:56
capocasa pushed a commit to capocasa/Nim that referenced this pull request Mar 31, 2023
* Remove unused `base64.encode` overload

* [skip ci] Remove commented code

* [skip ci] var -> let

* [skip ci] Remove mentions of the string overload

* Remove `SomeInteger` overload

* Fix CI

* Fix CI

* Deprecate `SomeInteger` overload

* [skip ci] Add changelog entry

* Revert "Remove `SomeInteger` overload"

This reverts commit 79a2963.

* Revert "[skip ci] Add changelog entry"

This reverts commit 186f17e.

* Revert "Revert "Remove `SomeInteger` overload""

This reverts commit 8005318.

* Update lib/pure/base64.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants