From 9bc738db42602629daba6463a9eb80bf5370854d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 15 Jul 2024 16:38:51 +0200 Subject: [PATCH] Don't use SyncTextWriter on WASI either (#104798) Follow-up to https://github.com/dotnet/runtime/pull/101221 so we match behavior between single-threaded Browser and WASI. --- src/libraries/System.Console/tests/ReadAndWrite.cs | 6 ++++-- src/libraries/System.Console/tests/SyncTextWriter.cs | 2 +- .../src/System.Private.CoreLib.Shared.projitems | 2 -- .../System.Private.CoreLib/src/System/IO/TextWriter.cs | 2 +- .../tests/System.IO.Tests/StreamReader/StreamReader.cs | 2 +- .../tests/System.IO.Tests/StreamWriter/StreamWriter.cs | 2 +- .../tests/System.IO.Tests/TextWriter/TextWriterTests.cs | 2 +- .../System.Private.CoreLib/System.Private.CoreLib.csproj | 2 -- 8 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Console/tests/ReadAndWrite.cs b/src/libraries/System.Console/tests/ReadAndWrite.cs index 913d85835dbb1..3e165d3826392 100644 --- a/src/libraries/System.Console/tests/ReadAndWrite.cs +++ b/src/libraries/System.Console/tests/ReadAndWrite.cs @@ -158,9 +158,11 @@ public static async Task OutWriteAndWriteLineOverloads() Console.SetOut(sw); TextWriter writer = Console.Out; Assert.NotNull(writer); - // Browser bypasses SyncTextWriter for faster startup - if (!OperatingSystem.IsBrowser()) + // single-threaded WASM bypasses SyncTextWriter for faster startup + if (PlatformDetection.IsThreadingSupported) Assert.NotEqual(writer, sw); // the writer we provide gets wrapped + else + Assert.Equal(writer, sw); // the writer we provide does not get wrapped // We just want to ensure none of these throw exceptions, we don't actually validate // what was written. diff --git a/src/libraries/System.Console/tests/SyncTextWriter.cs b/src/libraries/System.Console/tests/SyncTextWriter.cs index 772e1e2b44a91..bcd0b12ddb426 100644 --- a/src/libraries/System.Console/tests/SyncTextWriter.cs +++ b/src/libraries/System.Console/tests/SyncTextWriter.cs @@ -12,7 +12,7 @@ public class SyncTextWriter { - // Browser bypasses SyncTextWriter for faster startup + // single-threaded WASM bypasses SyncTextWriter for faster startup [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void SyncTextWriterLockedOnThis() { diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 406f3caecba30..9045c03a920b9 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -22,8 +22,6 @@ true true true - true - $(DefineConstants);FEATURE_WASM_MANAGED_THREADS $(DefineConstants);BIGENDIAN diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs b/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs index d949017809f82..c328f858f1edc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs @@ -759,7 +759,7 @@ public static TextWriter Synchronized(TextWriter writer) { ArgumentNullException.ThrowIfNull(writer); -#if !TARGET_BROWSER || FEATURE_WASM_MANAGED_THREADS +#if (!TARGET_BROWSER && !TARGET_WASI) || FEATURE_WASM_MANAGED_THREADS return writer is SyncTextWriter ? writer : new SyncTextWriter(writer); #else return writer; diff --git a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamReader/StreamReader.cs b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamReader/StreamReader.cs index 29677f512d9f7..efdf66257c31c 100644 --- a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamReader/StreamReader.cs +++ b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamReader/StreamReader.cs @@ -29,7 +29,7 @@ public void ObjectClosedReadLineBaseStream() Assert.Throws(() => sr.ReadLine()); } - // Browser bypasses SyncTextWriter for faster startup + // single-threaded WASM bypasses SyncTextWriter for faster startup [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void Synchronized_NewObject() { diff --git a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.cs b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.cs index cc09f1c0d2032..0abbc4d6add34 100644 --- a/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.cs +++ b/src/libraries/System.Runtime/tests/System.IO.Tests/StreamWriter/StreamWriter.cs @@ -7,7 +7,7 @@ namespace System.IO.Tests { public partial class WriteTests { - // Browser bypasses SyncTextWriter for faster startup + // single-threaded WASM bypasses SyncTextWriter for faster startup [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void Synchronized_NewObject() { diff --git a/src/libraries/System.Runtime/tests/System.IO.Tests/TextWriter/TextWriterTests.cs b/src/libraries/System.Runtime/tests/System.IO.Tests/TextWriter/TextWriterTests.cs index 47541635c8eef..08dc045e4a5b5 100644 --- a/src/libraries/System.Runtime/tests/System.IO.Tests/TextWriter/TextWriterTests.cs +++ b/src/libraries/System.Runtime/tests/System.IO.Tests/TextWriter/TextWriterTests.cs @@ -690,7 +690,7 @@ public void DisposeAsync_ExceptionReturnedInTask() Assert.Same(e, vt.AsTask().Exception.InnerException); } - // Browser bypasses SyncTextWriter for faster startup + // single-threaded WASM bypasses SyncTextWriter for faster startup [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public async Task FlushAsync_Precanceled() { diff --git a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj index 9137c694aa4ab..ed02811e9b39a 100644 --- a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -13,8 +13,6 @@ x64;x86;arm;armv6;arm64;riscv64;s390x;wasm;ppc64le true - true - $(DefineConstants);FEATURE_WASM_MANAGED_THREADS