-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Initial changes for globalization hybrid mode #81470
Conversation
Tagging subscribers to this area: @dotnet/area-system-globalization Issue DetailsImplemented
Changes for #80689
|
Tagging subscribers to 'os-ios': @steveisok, @akoeplinger Issue DetailsImplemented
Changes for #80689
|
src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs
Outdated
Show resolved
Hide resolved
|
||
return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName); | ||
#if TARGET_IOS | ||
return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) |
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.
GlobalizationMode.UseNls
is always going to be false on iOS. It is Windows-specific property. You can omit it for iOS-specific code.
@@ -13,13 +13,15 @@ internal static partial class GlobalizationMode | |||
private static partial class Settings | |||
{ | |||
internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); | |||
internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); |
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.
Should this be under iOS ifdef - since all uses are under iOS ifdef as well?
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.
Yes, plus wasm and wasi as well.
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.
For now I will put under ioslike platforms. For wasm we have seperate PR.
@@ -9,6 +9,8 @@ PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLeng | |||
|
|||
PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength); | |||
|
|||
PALEXPORT const char* NativeGetLocaleName(const char* localeName, int32_t valueLength); |
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 should still have GlobalizationNative_
prefix to follow the coding conventions.
https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/interop-guidelines.md#unix-shims: all exports should have a prefix that corresponds to the Libraries' name, e.g. "SystemNative_" or "CryptoNative_"
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
If the expectation is that GlobalizationMode.Invariant and GlobalizationMode.Hybrid cannot both be true, do we have some measures to check that both feature flags are not both true, and throw somewhere if they are?
src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Globalization/tests/Hybrid/Hybrid.Tests.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs
Outdated
Show resolved
Hide resolved
For now there are checks in CultureData.OSX.cs like Debug.Assert(!GlobalizationMode.Invariant); |
If invariant mode is on, the runtime will not load ICU at all. There should not be a scenario where if invariant mode is true and hybrid is true that they somehow collide. |
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
@mdh1418 @akoeplinger Please give this another pass when you have a moment. |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.OSX.cs
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.
Overall looking good to me. Just some things we should do before merging
Double check ILLink trimming ILLink.Substitutions.Shared.xml
is behaving as anticipated in the different feature switch scenarios. Or if someone more familiar with that signs off on it
The comment about _sWindowsName
.
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
@@ -13,6 +13,7 @@ configurations but their defaults might vary as any SDK can set the defaults dif | |||
| EnableUnsafeBinaryFormatterSerialization | System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization | BinaryFormatter serialization support is trimmed when set to false | | |||
| EventSourceSupport | System.Diagnostics.Tracing.EventSource.IsSupported | Any EventSource related code or logic is trimmed when set to false | | |||
| InvariantGlobalization | System.Globalization.Invariant | All globalization specific code and data is trimmed when set to true | | |||
| HybridGlobalization | System.Globalization.Hybrid | Loading ICU + native implementations | |
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.
Are we still planning to add the feature switch HybridGlobalization
? Reading up on https://github.com/dotnet/designs/blob/main/accepted/2020/feature-switch.md a bit more, it seems like feature switches primarily help control the size of libraries by trimming out areas we know will not be reached under certain conditions (when a particular feature switch is on). For example, when the InvariantGlobalization feature switch is on (true), the GlobalizationMode/Settings class is trimmed out.
So for HybridGlobalization, is there anything we want to/can trim out if its known that HybridGlobalization is being used? From what I am understanding, HybridGlobalization is to help reduce the reliance on ICU. When its true, it doesn't make any other code completely unreachable right now does it? Or is IcuGetLocaleInfo(..., LocalStringData ..., ...)
all supposed to be unreachable now?
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 need to have feature switch HybridGlobalization as without it we will not understand to load fully icu or no. In ideal case IcuGetLocaleInfo should not be used in HybridGlobalization when all functionalities will be implemented by native functions. Also for HybridGlobalization we will load smaller icu files (trimmed out the functionalities that are implemented by native functions), this will be done in upcoming PRs.
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.
@mkhamoyan the feature switches listed here are linker feature switches, i.e. where the linker replaces/hardcodes the value of the corresponding AppContext switch so that unused code can be trimmed out.
We don't need that, we have a regular AppContext switch that is unaffected by trimming so having it listed in this doc is confusing.
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.
Will remove it from here. Do we have doc for regular AppContext switches?
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.
As far as I know we just have the public docs where we could add it: https://learn.microsoft.com/en-us/dotnet/core/runtime-config/globalization
Note that in our case we'd just have runtimeconfig.json and environment variable options since the MSBuild property would need wiring up in the dotnet/sdk.
@@ -13,13 +13,19 @@ internal static partial class GlobalizationMode | |||
private static partial class Settings | |||
{ | |||
internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"); | |||
#if TARGET_OSX || TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS | |||
internal static bool Hybrid { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Hybrid", "DOTNET_SYSTEM_GLOBALIZATION_HYBRID"); |
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.
If HybridGlobalization
is not going to be a feature switch, should this be using AppContextConfigHelper.GetBooleanConfig
? Will the switch System.Globalization.Hybrid
ever be set? I think System.Globalization.Invariant
and System.Globalization.PredefinedCulturesOnly
switches are probably set in the TrimmingTests
runtime/src/libraries/System.Runtime/tests/TrimmingTests/System.Runtime.TrimmingTests.proj
Lines 16 to 19 in 9b38f2a
<DisabledFeatureSwitches>System.Globalization.Invariant</DisabledFeatureSwitches> | |
</TestConsoleAppSourceFiles> | |
<TestConsoleAppSourceFiles Include="InvariantGlobalizationTrue.cs"> | |
<EnabledFeatureSwitches>System.Globalization.Invariant;System.Globalization.PredefinedCulturesOnly</EnabledFeatureSwitches> |
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.
Once more functionalities will be implemented this will be used and we can have tests in TrimmingTests for hybrid mode.
Test failures are not related to the PR. |
Implemented
LocaleStringData
LocalizedDisplayName,
EnglishDisplayName,
NativeDisplayName ,
LocalizedLanguageName,
EnglishLanguageName,
NativeLanguageName,
EnglishCountryName,
NativeCountryName,
DecimalSeparator,
ThousandSeparator,
Digits, // maybe value = "0123456789" ?
MonetarySymbol,
CurrencyEnglishName,
CurrencyNativeName,
Iso4217MonetarySymbol, // check currencyISOCode
MonetaryDecimalSeparator,
MonetaryThousandSeparator,
AMDesignator,
PMDesignator,
PositiveSign,
NegativeSign,
Iso639LanguageTwoLetterName,
Iso639LanguageThreeLetterName, // check ISOLanguageCodes
Iso3166CountryName,
Iso3166CountryName2, // maybe [currentLocale.countryCode UTF8String] ?
NaNSymbol,
PositiveInfinitySymbol,
NegativeInfinitySymbol,
ParentName,
PercentSymbol,
PerMilleSymbol
GlobalizationNative_GetLocaleNameNative
Changes for #80689