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

Make AsciiSet values instead of refs - non-breaking version #976

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joshka
Copy link
Contributor

@joshka joshka commented Sep 26, 2024

Refs take 8 bytes, whereas the values are only 16 bytes, so there is not
a huge benefit to using references rather than values. PercentEncoding
is changed to store the AsciiSet as a value, and the functions that take
AsciiSet now take Into instead of &'static AsciiSet. This
allows existing code to continue to work without modification. The
AsciiSet consts (CONTROLS and NON_ALPHANUMERIC) are also changed to be
values, which is a breaking change, but will only affect code that
attempts to dereference them.

Discussion about the rationale for this is change is at
#970 (comment)

@@ -114,10 +114,10 @@ pub fn percent_encode_byte(byte: u8) -> &'static str {
/// assert_eq!(percent_encode(b"foo bar?", NON_ALPHANUMERIC).to_string(), "foo%20bar%3F");
/// ```
#[inline]
pub fn percent_encode<'a>(input: &'a [u8], ascii_set: &'static AsciiSet) -> PercentEncode<'a> {
pub fn percent_encode<'a, T: Into<AsciiSet>>(input: &'a [u8], ascii_set: T) -> PercentEncode<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

ah, I see

thought: I'm not a huge fan of making things generic just for ref-or-value support, callers should handle that. So I'd rather this just be a non-generic function taking an AsciiSet. I do feel that the current use of refs is suboptimal. @valenting what do you think of doing a breaking release for percent-encoding? I don't think it's used directly by many, and I think it's an internal dep for rust-url so can be freely updated (though please check that)

Copy link
Contributor Author

@joshka joshka Sep 26, 2024

Choose a reason for hiding this comment

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

I agree it's worth considering breaking this, as the fix is often going to be simple and compiler error driven.

Edit: Reverse deps: https://crates.io/crates/percent-encoding/reverse_dependencies (900 crates) :/

Copy link
Member

Choose a reason for hiding this comment

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

Hm. Still fine to do a breaking 3.x bump, and I don't think rust-url or any of the other libraries in this crate export it as a public dependency, so it can be bumped without changing everything.

But yes, not ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A breaking version of this change is in #978

@joshka
Copy link
Contributor Author

joshka commented Sep 26, 2024

ugh - I realized that this includes code which is already merged. Will rebase and push

@Manishearth
Copy link
Member

@joshka Would you be down to landing all the other changes except for moving things away from Ref as a separate PR? Those seem rather straightforward to land and it would be nice to get them.

@joshka
Copy link
Contributor Author

joshka commented Sep 26, 2024

@joshka Would you be down to landing all the other changes except for moving things away from Ref as a separate PR? Those seem rather straightforward to land and it would be nice to get them.

Definitely

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@710e1e7). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #976   +/-   ##
=======================================
  Coverage        ?   82.23%           
=======================================
  Files           ?       22           
  Lines           ?     3563           
  Branches        ?        0           
=======================================
  Hits            ?     2930           
  Misses          ?      633           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joshka
Copy link
Contributor Author

joshka commented Sep 26, 2024

Rebased on the refactoring PR and removed the already landed commits

Refs take 8 bytes, whereas the values are only 16 bytes, so there is not
a huge benefit to using references rather than values. PercentEncoding
is changed to store the AsciiSet as a value, and the functions that take
AsciiSet now take Into<AsciiSet> instead of &'static AsciiSet. This
allows existing code to continue to work without modification. The
AsciiSet consts (CONTROLS and NON_ALPHANUMERIC) are also changed to be
values, which is a breaking change, but will only affect code that
attempts to dereference them.

Discussion about the rationale for this is change is at
<servo#970 (comment)>
joshka added a commit to joshka/rust-url that referenced this pull request Sep 27, 2024
Refs take 8 bytes, whereas the values are only 16 bytes, so there is not
a huge benefit to using references rather than values. PercentEncoding
is changed to store the AsciiSet as a value, and the functions that
previously accepted a reference now accept a value. This is a breaking
change for users who were passing a reference to AsciiSet to the
functions in the public API.

The AsciiSet consts (CONTROLS, NON_ALPHANUMERIC, etc.) are also changed
to be values.

This is an alternative to the non-breaking change in
<servo#976>

Discussion about the rationale for this is change is at
<servo#970 (comment)>
@joshka joshka changed the title Make AsciiSet value instead of Ref Make AsciiSet values instead of refs - non-breaking version Sep 27, 2024
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.

2 participants