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

Making icu_locid_macros into consts #1631

Merged
merged 18 commits into from
Mar 29, 2022
Merged

Conversation

robertbastian
Copy link
Member

@robertbastian robertbastian commented Feb 23, 2022

Fixes #348

@robertbastian robertbastian linked an issue Feb 23, 2022 that may be closed by this pull request
@robertbastian robertbastian marked this pull request as ready for review February 23, 2022 17:04
@robertbastian robertbastian changed the title Making icu_locid_macros macro rules Making icu_locid_macros into consts Feb 23, 2022
@sffc sffc self-requested a review February 23, 2022 17:30
@jira-pull-request-webhook
Copy link

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

sffc
sffc previously approved these changes Feb 24, 2022
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

Looks good from my end! Please wait for @zbraniecki's review.

Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

overall it looks great! Thank you!

I am sad that const limitations make us have to sacrifice readability for const compatibility, but I believe it is a right tradeoff.
We can revisit and refactor the code when Rust const ergonomics are complete (? would help a lot).

I left a couple notes, but my two overarching ones are:

  1. Please, do not forgo the value of runtime parsing. icu_locid should be optimized for scenarios where code receives a string and needs to parse it at runtime. It's a very very hot loop.
  2. It would be great to find a good place to document the fact that we're giving up on readability to get consts and that this code should be refactored back once Rust const ergonomics are in place. Maybe as a comment over LanguageIdentifier main parser function?

components/locid/src/langid.rs Outdated Show resolved Hide resolved
components/locid/src/parser/mod.rs Outdated Show resolved Hide resolved
components/locid/src/subtags/region.rs Outdated Show resolved Hide resolved
@robertbastian
Copy link
Member Author

It would be great to find a good place to document the fact that we're giving up on readability to get consts and that this code should be refactored back once Rust const ergonomics are in place. Maybe as a comment over LanguageIdentifier main parser function?

We haven't done this in other places either, I'm thinking we can assume that if it's a const function it's clear that we don't get ?, for loops, etc.

zbraniecki
zbraniecki previously approved these changes Mar 16, 2022
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

thanks! looks great!

Optionally, you may want to fix (or comment) about the non-canonicalized fast-path on und.

components/locid/src/subtags/language.rs Outdated Show resolved Hide resolved
zbraniecki
zbraniecki previously approved these changes Mar 24, 2022
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

lgtm with one nit!

components/locid/src/parser/mod.rs Outdated Show resolved Hide resolved
components/locid/src/parser/mod.rs Show resolved Hide resolved
Copy link
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

My comment can be resolved in a follow-up if you prefer

@@ -71,6 +71,7 @@ mod helpers;
pub mod extensions;
mod langid;
mod locale;
pub mod macros;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Does it need to be pub? The macros are top-level via #[macro_export]

parse_language_identifier_from_iter(&mut iter, mode)
}

pub const fn parse_language_identifier_without_variants_from_iter(
Copy link
Member

Choose a reason for hiding this comment

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

Note: I didn't review the files in this module in detail; assuming Zibi did that

@robertbastian robertbastian merged commit 421728f into unicode-org:main Mar 29, 2022
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.

Re-write locale macros as const functions
3 participants