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

Initial changes for globalization hybrid mode #81470

Merged
merged 28 commits into from
Mar 28, 2023
Merged

Conversation

mkhamoyan
Copy link
Contributor

@mkhamoyan mkhamoyan commented Feb 1, 2023

Implemented

  • GlobalizationNative_GetLocaleInfoStringNative

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

@ghost
Copy link

ghost commented Feb 1, 2023

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

Issue Details

Implemented

  • GlobalizationNative_GetLocaleInfoString

      NSLocale
      LocaleString_LocalizedDisplayName => localizedStringForLocaleIdentifier
      LocaleString_EnglishDisplayName => localeIdentifier / localizedStringForLocaleIdentifier?
      LocaleString_NativeDisplayName => localeIdentifier / localizedStringForLocaleIdentifier?
      LocaleString_LocalizedLanguageName => localizedStringForLanguageCode
      LocaleString_EnglishLanguageName => localizedStringForLanguageCode
      LocaleString_NativeLanguageName => localizedStringForLanguageCode
      LocaleString_EnglishCountryName => localizedStringForCountryCode
      LocaleString_NativeCountryName => localizedStringForCountryCode
      LocaleString_DecimalSeparator => decimalSeparator
      LocaleString_ThousandSeparator => groupingSeparator
    
  • GlobalizationNative_GetLocaleName

Changes for #80689

Author: mkhamoyan
Assignees: mkhamoyan
Labels:

area-System.Globalization

Milestone: -

@tarekgh tarekgh added the os-ios Apple iOS label Feb 1, 2023
@ghost
Copy link

ghost commented Feb 1, 2023

Tagging subscribers to 'os-ios': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

Implemented

  • GlobalizationNative_GetLocaleInfoString

      NSLocale
      LocaleString_LocalizedDisplayName => localizedStringForLocaleIdentifier
      LocaleString_EnglishDisplayName => localeIdentifier / localizedStringForLocaleIdentifier?
      LocaleString_NativeDisplayName => localeIdentifier / localizedStringForLocaleIdentifier?
      LocaleString_LocalizedLanguageName => localizedStringForLanguageCode
      LocaleString_EnglishLanguageName => localizedStringForLanguageCode
      LocaleString_NativeLanguageName => localizedStringForLanguageCode
      LocaleString_EnglishCountryName => localizedStringForCountryCode
      LocaleString_NativeCountryName => localizedStringForCountryCode
      LocaleString_DecimalSeparator => decimalSeparator
      LocaleString_ThousandSeparator => groupingSeparator
    
  • GlobalizationNative_GetLocaleName

Changes for #80689

Author: mkhamoyan
Assignees: mkhamoyan
Labels:

area-System.Globalization, os-ios

Milestone: -


return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type) : IcuGetLocaleInfo(type, uiCultureName);
#if TARGET_IOS
return GlobalizationMode.UseNls ? NlsGetLocaleInfo(type)
Copy link
Member

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");
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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_"

@mkhamoyan
Copy link
Contributor Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@mdh1418 mdh1418 left a 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?

@mkhamoyan
Copy link
Contributor Author

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?

For now there are checks in CultureData.OSX.cs like Debug.Assert(!GlobalizationMode.Invariant);
Once more functionalities will be added in HybridMode we can add more checks or add more measures.

@steveisok
Copy link
Member

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?

For now there are checks in CultureData.OSX.cs like Debug.Assert(!GlobalizationMode.Invariant); Once more functionalities will be added in HybridMode we can add more checks or add more measures.

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.

@mkhamoyan
Copy link
Contributor Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@steveisok
Copy link
Member

@mdh1418 @akoeplinger Please give this another pass when you have a moment.

Copy link
Member

@mdh1418 mdh1418 left a 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.

@mkhamoyan
Copy link
Contributor Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mkhamoyan
Copy link
Contributor Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

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 |
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@akoeplinger akoeplinger Mar 28, 2023

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.

Copy link
Contributor Author

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?

Copy link
Member

@akoeplinger akoeplinger Mar 29, 2023

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");
Copy link
Member

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

<DisabledFeatureSwitches>System.Globalization.Invariant</DisabledFeatureSwitches>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="InvariantGlobalizationTrue.cs">
<EnabledFeatureSwitches>System.Globalization.Invariant;System.Globalization.PredefinedCulturesOnly</EnabledFeatureSwitches>
.

Copy link
Contributor Author

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.

@mkhamoyan
Copy link
Contributor Author

Test failures are not related to the PR.

@mkhamoyan mkhamoyan changed the title Initial changes for GetLocaleInfoString Initial changes for globalization hybrid mode Mar 28, 2023
@mkhamoyan mkhamoyan merged commit f561a05 into main Mar 28, 2023
@jkotas jkotas deleted the ios_hybrid_globalization branch March 28, 2023 10:32
@ghost ghost locked as resolved and limited conversation to collaborators Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants