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

Allow CodePointTrie to determine error_value at runtime from data #2301

Merged
merged 32 commits into from
Aug 2, 2022

Conversation

Manishearth
Copy link
Member

Supersedes #2097, fixes #1879

I didn't get rid of DATA_GET_ERROR_VALUE since I'm calling it DEFAULT_ERROR_VALUE, and it can be used for empty CodePointTries.

cc @pandusonu2 to see what changes I made

@Manishearth Manishearth requested a review from a team as a code owner August 1, 2022 16:26
@Manishearth Manishearth requested a review from sffc August 1, 2022 16:26
utils/codepointtrie/src/serde.rs Show resolved Hide resolved
utils/codepointtrie/src/codepointtrie.rs Outdated Show resolved Hide resolved
Comment on lines +115 to +117
#[zerofrom(clone)] // TrieValue is Copy, this allows us to avoid
// a T: ZeroFrom bound
pub(crate) error_value: T,
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: could we make a wrapper around T that implements ZeroFrom, something like

#[repr(transparent)]
pub struct CopyWrap<T: Copy>(pub T);

impl<T: Copy> ZeroFrom for CopyWrap<T> { ... }

and export that wrapper from the ZeroFrom crate?

Given that we don't have specialization in Rust, wrapper structs like this seem like the best path forward in these types of situations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, this is kinda what #[zerofrom(clone)] is for. We could introduce #[zerofrom(copy)] if we really want to be sure, but clone works fine here, it's a Copy type.

Copy link
Member

Choose a reason for hiding this comment

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

#[zerofrom(clone)] has code smell. I like #[zerofrom(copy)], or my CopyWrap suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah but we can introduce that any time.

utils/codepointtrie/src/codepointtrie.rs Outdated Show resolved Hide resolved
utils/codepointtrie/src/codepointtrie.rs Show resolved Hide resolved
utils/codepointtrie/src/serde.rs Outdated Show resolved Hide resolved
@Manishearth Manishearth requested a review from sffc August 1, 2022 23:29
utils/codepointtrie/src/codepointtrie.rs Show resolved Hide resolved
@@ -12,19 +12,19 @@ const SAMPLE_STRING_LATIN1: &str = "Declaration loremips umdolo loremipsompi";
const SAMPLE_STRING_MIXED: &str = "Dèclaråcion ЗАГАЛЬНА 世界人权宣言 𑄟𑄚𑄬𑄭𑄃𑄇𑄴𑄇𑄥𑄧𑄁𑄢𑄴";

fn get_trie_small() -> CodePointTrie<'static, u8> {
CodePointTrie::try_new(
CodePointTrie::try_new_with_error_at_end(
Copy link
Member

Choose a reason for hiding this comment

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

Issue: This is an iai bench and we do not want to allocate in it.

I suggest changing tries::gc_small to have the correct expanded form.

Basically, try to reduce the number of call sites of try_new_with_error_at_end. The only valid call sites I see are:

  • toml.rs
  • casemap try_from_icu
  • maybe test_util.rs

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Kept it in test_util because it's reading toml files

@Manishearth Manishearth requested a review from sffc August 1, 2022 23:55
sffc
sffc previously approved these changes Aug 1, 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.

Thanks! This is mergeable now although I'd still like to see try_new_with_error_at_end and #[zerofrom(clone)] cleaned up at some point

pub struct CaseMappingData(u16);
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
#[cfg_attr(feature = "datagen", databake(path = icu_casemapping::provider))]
pub struct CaseMappingData(pub u16);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: keep the field private and implement CaseMappingData::const_default() if possible

@Manishearth Manishearth merged commit acc48dc into unicode-org:main Aug 2, 2022
@Manishearth Manishearth deleted the cpt-error-value branch August 2, 2022 03:42
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.

Move error_value (and optionally default_value) to the CPT header?
3 participants