Skip to content

Add VarZeroLengthlessSlice, use in MultiFieldsULE to optimize #5593

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

Merged
merged 10 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
- `zerofrom`
- `zerotrie`
- `zerovec`
- This release has multiple changes that affect the bit representation of various types. Do not update to this release if you wish to retain stable data formats.
- Optimize `MultiFieldsULE` to not store a length anymore. This breaks data layout for any `#[make_varule]`-using struct with multiple variable-sized fields. (https://github.com/unicode-org/icu4x/pull/5593)
- `writeable`


Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

35 changes: 29 additions & 6 deletions components/experimental/tests/transliterate/data/baked/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components/experimental/tests/transliterate/data/gen.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
cargo run -p icu4x-datagen --features experimental_components -- \
cargo run -p icu4x-datagen --features experimental -- \
--markers TransliteratorRulesV1Marker \
--locales full \
--deduplication none \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include!("baked/macros.rs");
include!("baked/mod.rs");

pub struct TestingProvider;

Expand All @@ -17,5 +17,5 @@ const _: () = {
impl_compatibility_decomposition_supplement_v1_marker!(TestingProvider);
impl_compatibility_decomposition_tables_v1_marker!(TestingProvider);
impl_uts46_decomposition_supplement_v1_marker!(TestingProvider);
impl_transliterator_rules_v1!(TestingProvider);
impl_transliterator_rules_v1_marker!(TestingProvider);
};

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion provider/data/experimental/fingerprints.csv
Original file line number Diff line number Diff line change
Expand Up @@ -97741,5 +97741,5 @@ units/essentials@1, zh/long, 423B, 332B, dc8f6b0dd31ee068
units/essentials@1, zu/long, 476B, 385B, ecb1c4bd6dde6e84
units/essentials@1, zu/narrow, 372B, 281B, a98ff4ca98d94d42
units/essentials@1, zu/short, 370B, 279B, 6679b74467716e8c
units/info@1, <singleton>, 8106B, 8063B, 7de0c4710a635187
units/info@1, <singleton>, 7486B, 7443B, cbf5defdd14c97d5
units/trie@1, <singleton>, 1356B, 1335B, c02e6bb603fb4d72

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions provider/data/locale/data/aliases_v2_marker.rs.data

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provider/data/locale/fingerprints.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
locale/aliases@2, <singleton>, 8623B, 8171B, 6dffa6ad8d35f77b
locale/aliases@2, <singleton>, 8547B, 8095B, 3b5578f2a937e797
locale/exemplarchars/auxiliary@1, <lookup>, 802B, 163 identifiers
locale/exemplarchars/auxiliary@1, <total>, 42551B, 34828B, 144 unique payloads
locale/exemplarchars/auxiliary@1, af, 104B, 50B, cb103acefaf75d10
Expand Down
4 changes: 2 additions & 2 deletions provider/data/locale/stubdata/aliases_v2_marker.rs.data

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions utils/zerovec/derive/src/make_varule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,11 @@ impl<'a> UnsizedFields<'a> {

// Get the corresponding VarULE type that can store all of these
fn varule_ty(&self) -> TokenStream2 {
if self.fields.len() == 1 {
let len = self.fields.len();
if len == 1 {
Comment on lines +464 to +465
Copy link
Member

Choose a reason for hiding this comment

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

Praise: Not many changes in this file making it easy to review

self.fields[0].kind.varule_ty()
} else {
quote!(zerovec::ule::MultiFieldsULE)
quote!(zerovec::ule::MultiFieldsULE::<#len>)
}
}

Expand Down Expand Up @@ -507,7 +508,8 @@ impl<'a> UnsizedFields<'a> {

// Takes all unsized fields on self and encodes them into a byte slice `out`
fn encode_write(&self, out: TokenStream2) -> TokenStream2 {
if self.fields.len() == 1 {
let len = self.fields.len();
if len == 1 {
self.fields[0].encode_func(quote!(encode_var_ule_write), quote!(#out))
} else {
let mut lengths = vec![];
Expand All @@ -523,7 +525,7 @@ impl<'a> UnsizedFields<'a> {
quote!(
let lengths = [#(#lengths),*];
// Todo: index type should be settable by attribute
let mut multi = zerovec::ule::MultiFieldsULE::<zerovec::vecs::Index32>::new_from_lengths_partially_initialized(&lengths, #out);
let mut multi = zerovec::ule::MultiFieldsULE::<#len, zerovec::vecs::Index32>::new_from_lengths_partially_initialized(lengths, #out);
unsafe {
#(#writers;)*
}
Expand All @@ -533,15 +535,16 @@ impl<'a> UnsizedFields<'a> {

// Takes all unsized fields on self and returns the length needed for encoding into a byte slice
fn encode_len(&self) -> TokenStream2 {
if self.fields.len() == 1 {
let len = self.fields.len();
if len == 1 {
self.fields[0].encode_func(quote!(encode_var_ule_len), quote!())
} else {
let mut lengths = vec![];
for field in self.fields.iter() {
lengths.push(field.encode_func(quote!(encode_var_ule_len), quote!()));
}
// Todo: index type should be settable by attribute
quote!(zerovec::ule::MultiFieldsULE::<zerovec::vecs::Index32>::compute_encoded_len_for(&[#(#lengths),*]))
quote!(zerovec::ule::MultiFieldsULE::<#len, zerovec::vecs::Index32>::compute_encoded_len_for([#(#lengths),*]))
}
}

Expand Down Expand Up @@ -597,7 +600,8 @@ impl<'a> UnsizedFields<'a> {
///
/// The code will validate a variable known as `last_field_bytes`
fn varule_validator(&self) -> Option<TokenStream2> {
if self.fields.len() == 1 {
let len = self.fields.len();
if len == 1 {
None
} else {
let mut validators = vec![];
Expand All @@ -607,7 +611,7 @@ impl<'a> UnsizedFields<'a> {
}

Some(quote!(
let multi = zerovec::ule::MultiFieldsULE::parse_byte_slice(last_field_bytes)?;
let multi = zerovec::ule::MultiFieldsULE::<#len>::parse_byte_slice(last_field_bytes)?;
unsafe {
#(#validators)*
}
Expand Down
Loading