-
Notifications
You must be signed in to change notification settings - Fork 292
Remove Polyfill NuGet package dependency #7597
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
Open
Evangelink
wants to merge
6
commits into
main
Choose a base branch
from
remove-polyfill-dependency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a3c0ba7
Remove Polyfill NuGet package dependency
Evangelink a04524d
Fixes
Evangelink 34e635a
More issues
Evangelink 3cc434f
Address review comments and fix WaitAsync polyfill timeout behavior
Evangelink 5cdfcba
Add backward-compatible Polyfills stubs and fix TrxReportEngine unuse…
Evangelink 2282e2d
Fixes
Evangelink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 1 addition & 7 deletions
8
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,4 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| #if NETFRAMEWORK | ||
| namespace Microsoft.CodeAnalysis; | ||
|
|
||
| internal sealed partial class EmbeddedAttribute : Attribute | ||
| { | ||
| } | ||
| #endif | ||
| // EmbeddedAttribute is now provided by eng/Polyfills.cs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| // Polyfill extension methods for the Adapter projects which target | ||
| // net462 and need APIs not available on .NET Framework. | ||
| #if !NET5_0_OR_GREATER | ||
|
|
||
| [global::Microsoft.CodeAnalysis.EmbeddedAttribute] | ||
| internal static class AdapterPolyfillExtensions | ||
| { | ||
| public static bool Contains(this string s, char c) => s.IndexOf(c) >= 0; | ||
|
|
||
| public static bool StartsWith(this string s, char c) => s.Length > 0 && s[0] == c; | ||
|
|
||
| public static bool EndsWith(this string s, char c) => s.Length > 0 && s[s.Length - 1] == c; | ||
|
|
||
| public static void Deconstruct<TKey, TValue>(this System.Collections.Generic.KeyValuePair<TKey, TValue> pair, out TKey key, out TValue value) | ||
| { | ||
| key = pair.Key; | ||
| value = pair.Value; | ||
| } | ||
|
|
||
| public static bool IsAssignableTo(this System.Type type, System.Type? targetType) | ||
| => targetType?.IsAssignableFrom(type) ?? false; | ||
|
|
||
| public static bool TryAdd<TKey, TValue>(this System.Collections.Generic.Dictionary<TKey, TValue> dictionary, TKey key, TValue value) | ||
| where TKey : notnull | ||
| { | ||
| if (!dictionary.ContainsKey(key)) | ||
| { | ||
| dictionary.Add(key, value); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public static System.Text.StringBuilder AppendJoin(this System.Text.StringBuilder sb, string separator, System.Collections.Generic.IEnumerable<string> values) | ||
| { | ||
| bool first = true; | ||
| foreach (string value in values) | ||
| { | ||
| if (!first) | ||
| { | ||
| sb.Append(separator); | ||
| } | ||
|
|
||
| sb.Append(value); | ||
| first = false; | ||
| } | ||
|
|
||
| return sb; | ||
| } | ||
|
|
||
| public static System.Text.StringBuilder AppendJoin(this System.Text.StringBuilder sb, char separator, System.Collections.Generic.IEnumerable<string> values) => | ||
| sb.AppendJoin(separator.ToString(), values); | ||
|
|
||
| public static TValue GetOrAdd<TKey, TValue, TArg>(this System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> dictionary, TKey key, System.Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument) | ||
| where TKey : notnull | ||
| => dictionary.GetOrAdd(key, k => valueFactory(k, factoryArgument)); | ||
|
|
||
| public static string[] Split(this string s, char separator, System.StringSplitOptions options) => | ||
| s.Split([separator], options); | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| #if !NET8_0_OR_GREATER | ||
|
|
||
| [global::Microsoft.CodeAnalysis.EmbeddedAttribute] | ||
| internal static class AdapterCancellationTokenSourcePolyfill | ||
| { | ||
| public static System.Threading.Tasks.Task CancelAsync(this System.Threading.CancellationTokenSource cts) | ||
| { | ||
| if (cts.IsCancellationRequested) | ||
| { | ||
| return System.Threading.Tasks.Task.CompletedTask; | ||
| } | ||
|
|
||
| var task = System.Threading.Tasks.Task.Run(cts.Cancel); | ||
|
|
||
| while (!cts.IsCancellationRequested) | ||
| { | ||
| } | ||
|
|
||
| return task; | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| // Polyfill extension methods specific to the Analyzers project (which targets netstandard2.0 | ||
| // only and does not reference Microsoft.Testing.Platform). | ||
|
|
||
| [global::Microsoft.CodeAnalysis.EmbeddedAttribute] | ||
| internal static class AnalyzerPolyfillExtensions | ||
| { | ||
| public static bool IsAssignableTo(this System.Type type, System.Type? targetType) | ||
| => targetType?.IsAssignableFrom(type) ?? false; | ||
|
|
||
| public static void Deconstruct<TKey, TValue>(this System.Collections.Generic.KeyValuePair<TKey, TValue> pair, out TKey key, out TValue value) | ||
| { | ||
| key = pair.Key; | ||
| value = pair.Value; | ||
| } | ||
|
|
||
| public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue) | ||
| where TKey : notnull | ||
| => dictionary.TryGetValue(key, out TValue? value) ? value : defaultValue; | ||
|
|
||
| public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue) | ||
| where TKey : notnull | ||
| => dictionary.TryGetValue(key, out TValue? value) ? value : defaultValue; | ||
|
|
||
| public static bool Contains(this string s, char c) => s.IndexOf(c) >= 0; | ||
|
|
||
| public static bool StartsWith(this string s, char c) => s.Length > 0 && s[0] == c; | ||
|
|
||
| public static bool EndsWith(this string s, char c) => s.Length > 0 && s[s.Length - 1] == c; | ||
| } |
35 changes: 2 additions & 33 deletions
35
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,5 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under dual-license. See LICENSE.PLATFORMTOOLS.txt file in the project root for full license information. | ||
|
|
||
| #if !NETCOREAPP | ||
| #pragma warning disable SA1403 // File may only contain a single namespace | ||
| #pragma warning disable SA1642 // Constructor summary documentation should begin with standard text | ||
| #pragma warning disable SA1623 // Property summary documentation should match accessors | ||
|
|
||
| using System.ComponentModel; | ||
|
|
||
| namespace System.Runtime.CompilerServices | ||
| { | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| internal static class IsExternalInit; | ||
| } | ||
|
|
||
| // This was copied from https://github.com/dotnet/coreclr/blob/60f1e6265bd1039f023a82e0643b524d6aaf7845/src/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs | ||
| // and updated to have the scope of the attributes be internal. | ||
| namespace System.Diagnostics.CodeAnalysis | ||
| { | ||
| /// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary> | ||
| [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] | ||
| internal sealed class NotNullWhenAttribute : Attribute | ||
| { | ||
| /// <summary>Initializes the attribute with the specified return value condition.</summary> | ||
| /// <param name="returnValue"> | ||
| /// The return value condition. If the method returns this value, the associated parameter will not be null. | ||
| /// </param> | ||
| public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; | ||
|
|
||
| /// <summary>Gets the return value condition.</summary> | ||
| public bool ReturnValue { get; } | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
| // Polyfills for IsExternalInit and NotNullWhenAttribute are provided by eng/Polyfills.cs. | ||
| // This file is kept for reference but no longer defines those types. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
AdapterCancellationTokenSourcePolyfill.CancelAsynccontains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already haveTask.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.