-
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
Allow restricting cultures creation with any arbitrary names in Globalization Invariant Mode #54247
Allow restricting cultures creation with any arbitrary names in Globalization Invariant Mode #54247
Conversation
Tagging subscribers to this area: @tarekgh, @safern Issue DetailsThis change addresses the second part of #43774 This change is allowing restricting creating cultures with any names different than Invariant culture name (which is empty string). The is opt-in behavior which can get by using the config switch Anyone enables this mode will force any code creating a culture with names different than Invariant culture name
|
CC @safern |
src/libraries/System.Globalization/tests/CultureInfo/GetCultureInfo.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.
LGTM. It seems like there are some Globalization trimming tests failing.
src/libraries/System.Globalization/tests/CultureInfo/GetCultureInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/TrimmingTests/InvariantGlobalizationTrue.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml
Show resolved
Hide resolved
Tagging @dotnet/compat for awareness of the breaking change. |
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Globalization/tests/CultureInfo/GetCultureInfo.cs
Outdated
Show resolved
Hide resolved
(Signed off but someone else should check the linker/trimming stuff.) |
I tried setting the environment variable there, but it looks this didn't affect the test.
The last idea I have is to force the value of PredefinedCulturesOnly in the test to false through the reflection. @marek-safar @lewing @radical if you have better idea please let me know. |
Can you share the change you made, and binlog for the test? |
@radical the test change is just creating the envVars and passing it to Dictionary<string, string> envVars = new();
envVars.Add("DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", "false");
RunAndTestWasmApp(buildArgs, expectedExitCode: 42,
test: output => Assert.Contains(expectedOutputString, output), host: host, id: id, envVars: envVars); Looking at the logs, I am seeing the test I guess the best to do now, is to modify the test to catch the exception and use Invariant culture at that time. I'll try that and see how it goes. /cc @eerhardt |
62f2c4f
to
8c503e1
Compare
I fixed the browser test, hopefully this will be last failure :-) |
internal static bool Invariant { get; } = GetInvariantSwitchValue(); | ||
internal static readonly bool PredefinedCulturesOnly = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", Invariant); |
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 are Invariant and PredefinedCulturesOnly not symmetric in their design? e.g. I was expecting to see:
internal static bool Invariant { get; } = GetInvariantSwitchValue();
internal static bool PredefinedCulturesOnly { get; } = GetPredefinedCulturesOnlySwitchValue();
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.
Because we decided to not introduce a new config switch with the new Invariant behavior. @jkotas suggested to use the PredefinedCulturesOnly
switch which make a lot of sense. Now the default Invariant behavior is to throw for any non-Invariant culture. For that we have to have PredefinedCulturesOnly
be true be default for Invariant. and be false by default for non-Invariant mode. The only difference for PredefinedCulturesOnly
is the default value when it is not specified.
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 was asking a style question. GetPredefinedCulturesOnlySwitchValue() would return AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", Invariant);
, exactly what you're already initializing it to.
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.
@stephentoub I am going to merge this change soon. please let me know if you have any concern.
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 just don't see why the shape of these is different. But it's not a blocker, it's just inconsistent.
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.
Sorry my reply crossed your reply. This is how it is done to help the linker for trimming purpose I guess. look at @marek-safar change bc27d49 which introduced that.
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 think this done this way to allow the linker to trim GetInvariantSwitchValue
when Invariant mode is one. Having GetPredefinedCulturesOnlySwitchValue
will require more work from the linker to trim it too. @eerhardt or @marek-safar should have definitive answer here.
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 think this done this way to allow the linker to trim GetInvariantSwitchValue when Invariant mode is one.
I don't believe this is the case. I think it is inconsistent because this code has been refactored multiple times, and no one has made it consistent.
Having GetPredefinedCulturesOnlySwitchValue will require more work from the linker to trim it too.
I don't believe this is true either. Alternatively, the opposite approach could be taken to make the code look consistent:
internal static bool Invariant { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");
internal static bool PredefinedCulturesOnly { get; } = AppContextConfigHelper.GetBooleanConfig("System.Globalization.PredefinedCulturesOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY", Invariant);
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'll try to submit a PR to make this consistent.
This is an attempt to address #47112 based on Egor's suggestion. The changes: - set IsInterpreting MSBuild property to 'true' in case of iOS; - made System.Linq.Expressions.ExpressionCreator class internal static in order not to introduce new public type; otherwise it throws Type 'System.Linq.Expressions.ExpressionCreator<TDelegate>' does not exist in the reference but it does exist in the implementation. -updated the iOS simulator functional test for AOT to verify the fix - added PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly which checks whether the System.Linq.Expressions is built with IsInterpreting property set to true. To do so, it uses reflection to verify the Expression.Accept method doesn't exist. - disabled some failing library tests using ActiveIssue + PlatformDetection. - updated the invariant functional test for the iOS simulator (b/c of Allow restricting cultures creation with any arbitrary names in Globalization Invariant Mode #54247) Co-authored-by: Stephen Toub <stoub@microsoft.com>
The following commit changed the behavior to throw `CultureNotFoundException` when creating cultures in invariant mode. ``` commit 04dac7b Author: Tarek Mahmoud Sayed <tarekms@microsoft.com> Date: Thu Jul 1 11:55:05 2021 -0700 Allow restricting cultures creation with any arbitrary names in Globalization Invariant Mode (dotnet#54247) ``` This commit updates the corresponding test in `Wasm.Build.Tests` to handle that explicitly. Fixes dotnet#55838
The following commit changed the behavior to throw `CultureNotFoundException` when creating cultures in invariant mode. ``` commit 04dac7b Author: Tarek Mahmoud Sayed <tarekms@microsoft.com> Date: Thu Jul 1 11:55:05 2021 -0700 Allow restricting cultures creation with any arbitrary names in Globalization Invariant Mode (#54247) ``` This commit updates the corresponding test in `Wasm.Build.Tests` to handle that explicitly. Fixes #55838
@ericstj the description of this issue already referenced the breaking change issue dotnet/docs#24849 and it is already merged to the docs https://docs.microsoft.com/en-us/dotnet/core/compatibility/globalization/6.0/culture-creation-invariant-mode |
Thanks @tarekgh, removing that label will get it off my list 👍 |
This change addresses the second part of #43774
This change is forcing to throw exception when creating any culture other than Invariant culture when enabling the Globalization Invariant Mode. This will allow easier diagnosis of the failures when turning on the Globalization Invariant Mode.
When turning on the Invariant globalization mode the config switch
System.Globalization.PredefinedCulturesOnly
will be automatically turned on. If anyone for any reason want to get back to the old behavior which is allowing creating any cultures by providing Invariant culture data, can do that by explicitly turning off theSystem.Globalization.PredefinedCulturesOnly
switch.The breaking change doc is tracked by Restrict Cultures Creation in Globalization Invariant Mode issue.