Closed Bug 1701695 Opened 3 years ago Closed 3 years ago

Use intl::NumberFormat to format numbers in SpiderMonkey

Categories

(Core :: Internationalization, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
90 Branch
Tracking Status
firefox90 --- fixed

People

(Reporter: dminor, Assigned: dminor)

References

(Blocks 1 open bug)

Details

(Whiteboard: [i18n-unification])

Attachments

(9 files, 1 obsolete file)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Once the "unified" intl::NumberFormat implementation lands in Bug 1695937, the next step will be to support the full Intl.NumberFormat API, and switch SpiderMonkey over to using it.

This temporarily adds intl::NumberFormatterSkeleton to the public API so that
we can use it in PluralRules. This allows us to remove the SpiderMonkey
NumberFormatterSkeleton implementation when we convert SpiderMonkey to use
intl::NumberFormat.

We can remove intl::NumberFormatterSkeleton from the public API when we
implement intl::PluralRules in Bug 1704509.

Depends on D111886

Depends on D111887

The SpiderMonkey call sites need both the pointer and the length when
copying/deflating the string, so this changes the API to expose the underlying
string_view.

Attachment #9215542 - Attachment description: WIP: Bug 1701695 - Add support for format to parts to intl::NumberFormat → Bug 1701695 - Add support for format to parts to intl::NumberFormat
Attachment #9215543 - Attachment description: WIP: Bug 1701695 - Use intl::NumberFormatterSkeleton in PluralRules → Bug 1701695 - Use intl::NumberFormatterSkeleton in PluralRules
Attachment #9215544 - Attachment description: WIP: Bug 1701695 - Use intl::NumberFormat in SpiderMonkey (WIP) → Bug 1701695 - Use intl::NumberFormat in SpiderMonkey
Attachment #9217162 - Attachment description: Bug 1701695 - Return std::u16string_view instead of char16_t* in intl::NumberFormat → WIP: Bug 1701695 - Return std::u16string_view instead of char16_t* in intl::NumberFormat
Attachment #9215542 - Attachment description: Bug 1701695 - Add support for format to parts to intl::NumberFormat → WIP: Bug 1701695 - Add support for format to parts to intl::NumberFormat
Attachment #9215543 - Attachment description: Bug 1701695 - Use intl::NumberFormatterSkeleton in PluralRules → WIP: Bug 1701695 - Use intl::NumberFormatterSkeleton in PluralRules
Attachment #9215544 - Attachment description: Bug 1701695 - Use intl::NumberFormat in SpiderMonkey → WIP: Bug 1701695 - Use intl::NumberFormat in SpiderMonkey
Attachment #9217163 - Attachment description: Bug 1701695 - Remove unused unitStyle parameter from intl_FormatNumber → WIP: Bug 1701695 - Remove unused unitStyle parameter from intl_FormatNumber
Attachment #9217162 - Attachment description: WIP: Bug 1701695 - Return std::u16string_view instead of char16_t* in intl::NumberFormat → Bug 1701695 - Return std::u16string_view instead of char16_t* in intl::NumberFormat
Attachment #9215542 - Attachment description: WIP: Bug 1701695 - Add support for format to parts to intl::NumberFormat → Bug 1701695 - Add support for format to parts to intl::NumberFormat
Attachment #9215543 - Attachment description: WIP: Bug 1701695 - Use intl::NumberFormatterSkeleton in PluralRules → Bug 1701695 - Use intl::NumberFormatterSkeleton in PluralRules
Attachment #9215544 - Attachment description: WIP: Bug 1701695 - Use intl::NumberFormat in SpiderMonkey → Bug 1701695 - Use intl::NumberFormat in SpiderMonkey
Attachment #9217163 - Attachment description: WIP: Bug 1701695 - Remove unused unitStyle parameter from intl_FormatNumber → Bug 1701695 - Remove unused unitStyle parameter from intl_FormatNumber

This should be CurrencyDisplay to be consistent with ecma-402.

Depends on D112801

I foolishly dropped these when bringing the code over from SpiderMonkey.

Depends on D113557

This adds a fallible factory method to create new NumberFormat instances. This
allows us to report initialization errors at time of initialization, rather than
when format is called, and remove internal checks in the implementation for
successful initialization.

To support using the SpiderMonkey allocators, the TryCreate method optionally
takes an allocator as an argument and a DeletePolicy as template argument.
Default values are provided so that these do not need to be specified in Gecko
code.

The existing fluent code assumes that creating a NumberFormat instance always
succeeds. This patch updates that code to handle failures.

Depends on D113145

Blocks: 1709880

This adds a fallible factory method to create new NumberFormat instances. This
allows us to report initialization errors at time of initialization, rather than
when format is called, and remove internal checks in the implementation for
successful initialization.

The existing fluent code assumes that creating a NumberFormat instance always
succeeds. This patch updates that code to handle failures.

Depends on D113145

Attachment #9219222 - Attachment is obsolete: true
Pushed by dminor@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/9c0dbc73dad2
Return std::u16string_view instead of char16_t* in intl::NumberFormat r=gregtatum
https://hg.mozilla.org/integration/autoland/rev/89ff5f91d8e9
Rename NumberFormatOptions::CurrencyDisplayStyle; r=gregtatum
https://hg.mozilla.org/integration/autoland/rev/216472b634b9
Restore [[nodiscard]] annotations to NumberFormatterSkeleton; r=gregtatum
https://hg.mozilla.org/integration/autoland/rev/4239fe67d69f
Add support for format to parts to intl::NumberFormat r=gregtatum,tcampbell,anba
https://hg.mozilla.org/integration/autoland/rev/abcf774d3b58
Use intl::NumberFormatterSkeleton in PluralRules r=tcampbell
https://hg.mozilla.org/integration/autoland/rev/fdf12ac55593
Use intl::NumberFormat in SpiderMonkey r=tcampbell
https://hg.mozilla.org/integration/autoland/rev/11f97bc74622
Remove unused unitStyle parameter from intl_FormatNumber r=tcampbell,anba
https://hg.mozilla.org/integration/autoland/rev/823ed70ef5fe
Add documentation to NumberFormat.h; r=gregtatum,nordzilla
https://hg.mozilla.org/integration/autoland/rev/e88dd41c0a90
Add NumberFormat::TryCreate; r=tcampbell

The problem is with these changes: https://phabricator.services.mozilla.com/D112801. I've only seen it on Android so far. The ICU calls seem to all succeed, an Ok() is returned from formatResult(), but on the FluentBundle side it looks we get an Err, and return a nullptr which results in an empty string in Fluent.

Flags: needinfo?(dminor)

Moving the Buffer definition out of the FluentBuiltInNumberFormatterFormat fixes things for me locally and on try [1]. I would not have expected that to make a difference, but since this was a change we had planned to make anyway to support DateTimeFormat, I'll take it.

[1] https://treeherder.mozilla.org/jobs?repo=try&revision=86fa769f5651d4d9b7163532dc8e32af9e5e3ac1

Pushed by dminor@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/56618c50daff
Return std::u16string_view instead of char16_t* in intl::NumberFormat r=gregtatum
https://hg.mozilla.org/integration/autoland/rev/e787260f77b9
Rename NumberFormatOptions::CurrencyDisplayStyle; r=gregtatum
https://hg.mozilla.org/integration/autoland/rev/f3a30633d181
Restore [[nodiscard]] annotations to NumberFormatterSkeleton; r=gregtatum
https://hg.mozilla.org/integration/autoland/rev/1c26ef25db84
Add support for format to parts to intl::NumberFormat r=gregtatum,tcampbell,anba
https://hg.mozilla.org/integration/autoland/rev/382a076bc5a0
Use intl::NumberFormatterSkeleton in PluralRules r=tcampbell
https://hg.mozilla.org/integration/autoland/rev/da5fdc32ae9b
Use intl::NumberFormat in SpiderMonkey r=tcampbell
https://hg.mozilla.org/integration/autoland/rev/666e43ab82df
Remove unused unitStyle parameter from intl_FormatNumber r=tcampbell,anba
https://hg.mozilla.org/integration/autoland/rev/ecd5abbb0ffc
Add documentation to NumberFormat.h; r=gregtatum,nordzilla
https://hg.mozilla.org/integration/autoland/rev/67f15404db7c
Add NumberFormat::TryCreate; r=tcampbell
Blocks: 1719672
Whiteboard: [i18n-unification]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: