[browser][non-icu] Revert `HybridGlobalization` normalization. (#87007)
authorIlona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>
Mon, 5 Jun 2023 11:47:54 +0000 (13:47 +0200)
committerGitHub <noreply@github.com>
Mon, 5 Jun 2023 11:47:54 +0000 (13:47 +0200)
* revert

* Keep perf tests but with smaller buffers

src/libraries/Common/src/Interop/Browser/Interop.Normalization.cs [deleted file]
src/libraries/System.Globalization.Extensions/tests/Hybrid/System.Globalization.Extensions.Hybrid.WASM.Tests.csproj [deleted file]
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.WebAssembly.cs [deleted file]
src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.cs
src/mono/sample/wasm/browser-bench/String.cs
src/mono/wasm/runtime/corebindings.c
src/mono/wasm/runtime/es6/dotnet.es6.lib.js
src/mono/wasm/runtime/exports-linker.ts
src/mono/wasm/runtime/hybrid-globalization/normalization.ts [deleted file]

diff --git a/src/libraries/Common/src/Interop/Browser/Interop.Normalization.cs b/src/libraries/Common/src/Interop/Browser/Interop.Normalization.cs
deleted file mode 100644 (file)
index b55cf53..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Runtime.CompilerServices;
-using System.Text;
-
-internal static partial class Interop
-{
-    internal static unsafe partial class JsGlobalization
-    {
-        [MethodImplAttribute(MethodImplOptions.InternalCall)]
-        internal static extern unsafe int IsNormalized(NormalizationForm normalizationForm, in string source, out int exceptionalResult, out object result);
-
-        [MethodImplAttribute(MethodImplOptions.InternalCall)]
-        internal static extern unsafe int NormalizeString(NormalizationForm normalizationForm, in string source, char* dstBuffer, int dstBufferCapacity, out int exceptionalResult, out object result);
-    }
-}
diff --git a/src/libraries/System.Globalization.Extensions/tests/Hybrid/System.Globalization.Extensions.Hybrid.WASM.Tests.csproj b/src/libraries/System.Globalization.Extensions/tests/Hybrid/System.Globalization.Extensions.Hybrid.WASM.Tests.csproj
deleted file mode 100644 (file)
index 0e7c98c..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-  <PropertyGroup>
-    <TargetFrameworks>$(NetCoreAppCurrent)-browser</TargetFrameworks>
-    <TestRuntime>true</TestRuntime>
-    <HybridGlobalization>true</HybridGlobalization>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\Normalization\NormalizationAll.cs" />
-    <Compile Include="..\Normalization\StringNormalizationTests.cs" />
-  </ItemGroup>
-
-  <ItemGroup>
-    <EmbeddedResource Include="..\Normalization\Data\win8.txt">
-      <LogicalName>NormalizationDataWin8</LogicalName>
-    </EmbeddedResource>
-    <EmbeddedResource Include="..\Normalization\Data\win7.txt">
-      <LogicalName>NormalizationDataWin7</LogicalName>
-    </EmbeddedResource>
-  </ItemGroup>
-</Project>
index a330cad6f8f45213eb2ad179d548d91d05ac3d8d..d80ad76e071a21bf1a061de3743a0999a77afe53 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Normalization.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Normalization.Icu.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Normalization.Nls.cs" />
-    <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Normalization.WebAssembly.cs" Condition="'$(TargetsBrowser)' == 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\NumberFormatInfo.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\NumberStyles.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\Ordinal.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\WeakReference.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\WeakReference.T.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\ComAwareWeakReference.cs" />
-    <Compile Include="$(CommonPath)Interop\Browser\Interop.Normalization.cs" Condition="'$(TargetsBrowser)' == 'true'">
-      <Link>Common\Interop\Interop.Normalization.cs</Link>
-    </Compile>
     <Compile Include="$(CommonPath)Interop\Browser\Interop.CompareInfo.cs" Condition="'$(TargetsBrowser)' == 'true'">
       <Link>Common\Interop\Interop.CompareInfo.cs</Link>
     </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.WebAssembly.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.WebAssembly.cs
deleted file mode 100644 (file)
index b930f68..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Buffers;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace System.Globalization
-{
-    internal static partial class Normalization
-    {
-        private static unsafe bool JsIsNormalized(string strInput, NormalizationForm normalizationForm)
-        {
-            Debug.Assert(!GlobalizationMode.Invariant);
-            Debug.Assert(!GlobalizationMode.UseNls);
-
-            ValidateArguments(strInput, normalizationForm);
-
-            int ret = Interop.JsGlobalization.IsNormalized(normalizationForm, strInput, out int exception, out object ex_result);
-            if (exception != 0)
-                throw new Exception((string)ex_result);
-
-            return ret == 1;
-        }
-
-        private static unsafe string JsNormalize(string strInput, NormalizationForm normalizationForm)
-        {
-            Debug.Assert(!GlobalizationMode.Invariant);
-            Debug.Assert(!GlobalizationMode.UseNls);
-
-            ValidateArguments(strInput, normalizationForm);
-
-            char[]? toReturn = null;
-            try
-            {
-                const int StackallocThreshold = 512;
-
-                Span<char> buffer = strInput.Length <= StackallocThreshold
-                    ? stackalloc char[StackallocThreshold]
-                    : (toReturn = ArrayPool<char>.Shared.Rent(strInput.Length));
-
-                for (int attempt = 0; attempt < 2; attempt++)
-                {
-                    int realLen;
-                    fixed (char* pDest = &MemoryMarshal.GetReference(buffer))
-                    {
-                        realLen = Interop.JsGlobalization.NormalizeString(normalizationForm, strInput, pDest, buffer.Length, out int exception, out object ex_result);
-                        if (exception != 0)
-                            throw new Exception((string)ex_result);
-                    }
-
-                    if (realLen <= buffer.Length)
-                    {
-                        ReadOnlySpan<char> result = buffer.Slice(0, realLen);
-                        return result.SequenceEqual(strInput)
-                            ? strInput
-                            : new string(result);
-                    }
-
-                    Debug.Assert(realLen > StackallocThreshold);
-
-                    if (attempt == 0)
-                    {
-                        if (toReturn != null)
-                        {
-                            // Clear toReturn first to ensure we don't return the same buffer twice
-                            char[] temp = toReturn;
-                            toReturn = null;
-                            ArrayPool<char>.Shared.Return(temp);
-                        }
-
-                        buffer = toReturn = ArrayPool<char>.Shared.Rent(realLen);
-                    }
-                }
-
-                throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex, nameof(strInput));
-            }
-            finally
-            {
-                if (toReturn != null)
-                {
-                    ArrayPool<char>.Shared.Return(toReturn);
-                }
-            }
-        }
-    }
-}
index 2bc6107b5dad6cfcc9d88804de89118598ceff41..d120302a8aa8e78feb85581aaff07abce4311447 100644 (file)
@@ -19,10 +19,6 @@ namespace System.Globalization
 
             return GlobalizationMode.UseNls ?
                 NlsIsNormalized(strInput, normalizationForm) :
-#if TARGET_BROWSER
-            GlobalizationMode.Hybrid ?
-                JsIsNormalized(strInput, normalizationForm) :
-#endif
                 IcuIsNormalized(strInput, normalizationForm);
         }
 
@@ -37,10 +33,6 @@ namespace System.Globalization
 
             return GlobalizationMode.UseNls ?
                 NlsNormalize(strInput, normalizationForm) :
-#if TARGET_BROWSER
-            GlobalizationMode.Hybrid ?
-                JsNormalize(strInput, normalizationForm) :
-#endif
                 IcuNormalize(strInput, normalizationForm);
         }
     }
index 224604fd692a78f0bfda9f412c58d6791944280f..c00448632fc16d859b169a4feef3a8f845c2833d 100644 (file)
@@ -76,12 +76,14 @@ namespace Sample
 
         public class NormalizeMeasurement : StringMeasurement
         {
+            protected new int len = 8 * 1024;
             public override string Name => "Normalize";
             public override void RunStep() => str.Normalize();
         }
 
         public class IsNormalizedMeasurement : StringMeasurement
         {
+            protected new int len = 8 * 1024;
             public override string Name => "IsNormalized";
             public override void RunStep() => str.IsNormalized();
         }
@@ -101,7 +103,8 @@ namespace Sample
         }
 
         public class NormalizeMeasurementASCII : ASCIIStringMeasurement
-        {
+        {        
+            protected new int len = 8 * 1024;
             public override string Name => "Normalize ASCII";
             public override void RunStep() => str.Normalize();
         }
index 1a6494a101cf3154b3f916b024e877393d3bfa7a..a6d0f39deb39d6dac5c7888b177fccd71a2d00e2 100644 (file)
@@ -50,8 +50,6 @@ extern int mono_wasm_compare_string(MonoString **culture, const uint16_t* str1,
 extern mono_bool mono_wasm_starts_with(MonoString **culture, const uint16_t* str1, int32_t str1Length, const uint16_t* str2, int32_t str2Length, int32_t options, int *is_exception, MonoObject** ex_result);
 extern mono_bool mono_wasm_ends_with(MonoString **culture, const uint16_t* str1, int32_t str1Length, const uint16_t* str2, int32_t str2Length, int32_t options, int *is_exception, MonoObject** ex_result);
 extern int mono_wasm_index_of(MonoString **culture, const uint16_t* str1, int32_t str1Length, const uint16_t* str2, int32_t str2Length, int32_t options, mono_bool fromBeginning, int *is_exception, MonoObject** ex_result);
-extern mono_bool mono_wasm_is_normalized(int32_t normalizationForm, MonoString **src, int *is_exception, MonoObject** ex_result);
-extern int mono_wasm_normalize_string(int32_t normalizationForm, MonoString **src, uint16_t* dst, int32_t dstLength, int *is_exception, MonoObject** ex_result);
 
 void bindings_initialize_internals (void)
 {
@@ -84,6 +82,4 @@ void bindings_initialize_internals (void)
        mono_add_internal_call ("Interop/JsGlobalization::StartsWith", mono_wasm_starts_with);
        mono_add_internal_call ("Interop/JsGlobalization::EndsWith", mono_wasm_ends_with);
        mono_add_internal_call ("Interop/JsGlobalization::IndexOf", mono_wasm_index_of);
-       mono_add_internal_call ("Interop/JsGlobalization::IsNormalized", mono_wasm_is_normalized);
-       mono_add_internal_call ("Interop/JsGlobalization::NormalizeString", mono_wasm_normalize_string);
 }
index 9a525a57e24507b251a7d2e0c95c7a5d60e9d73b..3f5fcabf6265652b1aaafd9fadcbd1b1c5a70c4b 100644 (file)
@@ -112,10 +112,6 @@ let linked_functions = [
     "mono_wasm_starts_with",
     "mono_wasm_ends_with",
     "mono_wasm_index_of",
-    "mono_wasm_is_normalized",
-    "mono_wasm_normalize_string",
-    "mono_wasm_to_Unicode",
-    "mono_wasm_to_ASCII",
 
     "icudt68_dat",
 ];
index 63d1e98a8d359aded4be960de67f3e65ee9b163a..b56fe3684fcc06cf9a85b39553d77fdff06c1b9d 100644 (file)
@@ -29,7 +29,6 @@ import {
 } from "./net6-legacy/method-calls";
 import { mono_wasm_change_case, mono_wasm_change_case_invariant } from "./hybrid-globalization/change-case";
 import { mono_wasm_compare_string, mono_wasm_ends_with, mono_wasm_starts_with, mono_wasm_index_of } from "./hybrid-globalization/collations";
-import { mono_wasm_is_normalized, mono_wasm_normalize_string } from "./hybrid-globalization/normalization";
 
 // the methods would be visible to EMCC linker
 // --- keep in sync with dotnet.cjs.lib.js ---
@@ -105,8 +104,6 @@ export function export_linker(): any {
         mono_wasm_starts_with,
         mono_wasm_ends_with,
         mono_wasm_index_of,
-        mono_wasm_is_normalized,
-        mono_wasm_normalize_string,
 
         // threading exports, if threading is enabled
         ...mono_wasm_threads_exports,
diff --git a/src/mono/wasm/runtime/hybrid-globalization/normalization.ts b/src/mono/wasm/runtime/hybrid-globalization/normalization.ts
deleted file mode 100644 (file)
index 2faf9e0..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-import { mono_wasm_new_external_root } from "../roots";
-import { monoStringToString, stringToUTF16 } from "../strings";
-import { MonoObject, MonoObjectRef, MonoString, MonoStringRef } from "../types/internal";
-import { Int32Ptr } from "../types/emscripten";
-import { wrap_error_root, wrap_no_error_root } from "../invoke-js";
-
-const NORMALIZATION_FORM_MAP = [undefined, "NFC", "NFD", undefined, undefined, "NFKC", "NFKD"];
-const ERROR = -1;
-
-export function mono_wasm_is_normalized(normalizationForm: number, inputStr: MonoStringRef, is_exception: Int32Ptr, ex_address: MonoObjectRef): number {
-    const inputRoot = mono_wasm_new_external_root<MonoString>(inputStr),
-        exceptionRoot = mono_wasm_new_external_root<MonoObject>(ex_address);
-    try {
-        const jsString = monoStringToString(inputRoot);
-        if (!jsString)
-            throw new Error("Invalid string was received.");
-
-        const normalization = normalization_to_string(normalizationForm);
-        const result = jsString.normalize(normalization);
-        wrap_no_error_root(is_exception, exceptionRoot);
-        return result === jsString ? 1 : 0;
-    }
-    catch (ex) {
-        wrap_error_root(is_exception, ex, exceptionRoot);
-        return ERROR;
-    } finally {
-        inputRoot.release();
-        exceptionRoot.release();
-    }
-}
-
-export function mono_wasm_normalize_string(normalizationForm: number, inputStr: MonoStringRef, dstPtr: number, dstLength: number, is_exception: Int32Ptr, ex_address: MonoObjectRef): number {
-    const inputRoot = mono_wasm_new_external_root<MonoString>(inputStr),
-        exceptionRoot = mono_wasm_new_external_root<MonoObject>(ex_address);
-    try {
-        const jsString = monoStringToString(inputRoot);
-        if (!jsString)
-            throw new Error("Invalid string was received.");
-
-        const normalization = normalization_to_string(normalizationForm);
-        const result = jsString.normalize(normalization);
-
-        // increase the dest buffer
-        if (result.length > dstLength)
-            return result.length;
-        stringToUTF16(dstPtr, dstPtr + 2 * dstLength, result);
-        return result.length;
-    } catch (ex) {
-        wrap_error_root(is_exception, ex, exceptionRoot);
-        return ERROR;
-    } finally {
-        inputRoot.release();
-        exceptionRoot.release();
-    }
-}
-
-const normalization_to_string = (normalizationForm: number): string => NORMALIZATION_FORM_MAP[normalizationForm] ?? "NFC";
-