-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[wasm] Throw exception if culture data does not exist in icu #47301
Conversation
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Outdated
Show resolved
Hide resolved
Add PredefinedOnly GlobalizationMode Modified tests if Culture Data not found
@@ -11,6 +11,8 @@ internal static partial class GlobalizationMode | |||
|
|||
internal static bool UseNls => false; | |||
|
|||
internal static bool PredefinedOnly { get; } = GetSwitchValue("System.Globalization.PredefinedOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_ONLY"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PredefinedOnly [](start = 29, length = 14)
are you adding this for Linux only? looks the calling site will call it even running on Windows. maybe you need to move this to the file GlobalizationMode.cs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for Browser only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need to restrict this to the browser only? We may enable this flag globally if we need to. Note the calling site of this property is called from shared code which runs with ICU and Nls. Give me a few minutes and I can send you what I propose.
Also, does the browser always runs with Icu?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I just assumed only Browser would need this use case, but I can definitely move to GlobalizationMode.cs. And yes, the browser always runs with icu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to move the checks
runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.Nls.cs
Line 14 in f1ad1b9
if (CultureData.GetLocaleInfoExInt(name, Interop.Kernel32.LOCALE_ICONSTRUCTEDLOCALE) == 1) |
and
runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.Icu.cs
Line 14 in f1ad1b9
if (!Interop.Globalization.IsPredefinedLocale(name)) |
to its own methods, something like
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static IcuIsEnsurePredefinedLocaleName(string name) // may put this in CultureData.Icu.cs
{
Debug.Assert(!GlobalizationMode.UseNls);
if (!Interop.Globalization.IsPredefinedLocale(name))
{
throw new CultureNotFoundException(nameof(name), SR.Format(SR.Argument_InvalidPredefinedCultureName, name));
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static NlsIsEnsurePredefinedLocaleName(string name) // may put this in CultureData.Nls.cs
{
Debug.Assert(GlobalizationMode.UseNls);
if (CultureData.GetLocaleInfoExInt(name, Interop.Kernel32.LOCALE_ICONSTRUCTEDLOCALE) == 1)
{
throw new CultureNotFoundException(nameof(name), SR.Format(SR.Argument_InvalidPredefinedCultureName, name));
}
}
Then replace the code here with
if (GlobalizationMode.PredefinedOnly)
{
if (GlobalizationMode.UseNls)
{
NlsIsEnsurePredefinedLocaleName(cultureName);
}
else
{
IcuIsEnsurePredefinedLocaleName(cultureName);
}
}
Last, replace the checks in the links I mentioned above with the new methods calls. and move the code in GlobalizationMode.Unix.cs to GlobalizationMode.cs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok yes that makes sense.
@@ -1904,6 +1904,9 @@ var MonoSupportLib = { | |||
|
|||
if (invariantMode) | |||
this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1"); | |||
|
|||
// Set globalization mode to PredefinedOnly | |||
this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_ONLY", "1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it env variable if it's always set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just leaving the option open if we don't want it always set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be easy to change and it'll cost us on size. I think we should just compile the setting in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want it always set for wasm but I'm not sure if other OS want this option by default. @tarekgh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outside WASM, we shouldn't turn this option on by default. Whoever need it would need to opt-in to get it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do this by setting a default value for the flag and making that default value be true for wasm based on an OS check when you are setting the PredefinedCulturesOnly
flag. Or, just if def the code for WASM to always be ON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a place where we do something similar for WASM:
runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs
Line 26 in e6105a1
if (loaded == 0 && !OperatingSystem.IsBrowser()) |
So we could do something like:
GetSwitchValue("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY") || OperatingSystem.IsBrowser()
CC @safern |
src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.Unix.cs
Outdated
Show resolved
Hide resolved
Could you please replace the checks in runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.Nls.cs Line 14 in f1ad1b9
and runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.Icu.cs Line 14 in f1ad1b9
with the new introduced method calls? thank you! |
One last ask, could you please add a new test (not specific to the browser) to test the new environment variable? here is some test example which doing similar idea (testing setting environment variable). runtime/src/libraries/System.Threading.Tasks.Extensions/tests/AsyncValueTaskMethodBuilderTests.cs Line 568 in e63969d
|
Modify Globalization tests to catch unsupported locales Change var names
I don't think RemoteExcutor or System.Diagnostics.Process are supported on wasm right now. I'm going to store the current env var and reset it back to that after the test? |
Yes, just exclude the added test from running on WASM. just mark the test with the attribute |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tqiu8 I have added one more comment I hope you address it.
Also, please track documenting the new environment variable too. Thanks!
Thank you so much for your feedback! |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Show resolved
Hide resolved
src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/Assembly/AssemblyTests.cs
Outdated
Show resolved
Hide resolved
This is looking good but the failures look like they might be related. |
…Tests/Assembly/AssemblyTests.cs Co-authored-by: Larry Ewing <lewing@microsoft.com>
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Nls.cs
Outdated
Show resolved
Hide resolved
…otnet#47301)" This reverts commit 128c757.
Fix #47068
Fix #46327
Throw exception if culture data doesn't exist. Currently defaults to
en-us
.