Skip to content

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

Open
joshka wants to merge 1 commit into
servo:mainfrom
joshka:jm/asciiset-value
Open

joshka wants to merge 1 commit into
servo:mainfrom
joshka:jm/asciiset-value

Conversation

@joshka

@joshka joshka commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

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)

Comment thread percent_encoding/src/lib.rs Outdated
/// ```
#[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
Copy Markdown
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)

@joshka joshka Sep 26, 2024

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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

joshka commented Sep 26, 2024

Copy link
Copy Markdown
Contributor Author

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

@Manishearth

Copy link
Copy Markdown
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

joshka commented Sep 26, 2024

Copy link
Copy Markdown
Contributor Author

@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

@codecov

codecov Bot commented Sep 26, 2024

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@00a6ce5). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #976   +/-   ##
=======================================
  Coverage        ?   86.93%           
=======================================
  Files           ?       26           
  Lines           ?     5264           
  Branches        ?        0           
=======================================
  Hits            ?     4576           
  Misses          ?      688           
  Partials        ?        0           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshka

joshka commented Sep 26, 2024

Copy link
Copy Markdown
Contributor Author

Rebased on the refactoring PR and removed the already landed commits

@joshka
joshka force-pushed the jm/asciiset-value branch 2 times, most recently from d025bd8 to 888596e Compare September 27, 2024 00:39
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
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 4, 2026
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)>
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