From 498b5e6165ad48984591d3e6a58e2b8892034419 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Jul 2022 10:26:54 -0700 Subject: [PATCH 1/5] Polyfill the incremental generator ForAttributeWithMetadataName from roslyn (for LibraryImportGenerator). --- .../LibraryImportGenerator.cs | 34 +++++-------------- .../LibraryImportGenerator.csproj | 15 ++++++++ .../Generic/ValueListBuilder.Pop.cs | 20 +++++++++++ 3 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 src/libraries/System.Runtime.InteropServices/src/System/Collections/Generic/ValueListBuilder.Pop.cs diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs index c262c2e0017ec..ac1ce59a47aaa 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.DotnetRuntime.Extensions; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; [assembly: System.Resources.NeutralResourcesLanguage("en-US")] @@ -61,19 +62,13 @@ public static class StepNames public void Initialize(IncrementalGeneratorInitializationContext context) { var attributedMethods = context.SyntaxProvider - .CreateSyntaxProvider( - static (node, ct) => ShouldVisitNode(node), - static (context, ct) => - { - MethodDeclarationSyntax syntax = (MethodDeclarationSyntax)context.Node; - if (context.SemanticModel.GetDeclaredSymbol(syntax, ct) is IMethodSymbol methodSymbol - && methodSymbol.GetAttributes().Any(static attribute => attribute.AttributeClass?.ToDisplayString() == TypeNames.LibraryImportAttribute)) - { - return new { Syntax = syntax, Symbol = methodSymbol }; - } - - return null; - }) + .ForAttributeWithMetadataName( + context, + TypeNames.LibraryImportAttribute, + static (node, ct) => node is MethodDeclarationSyntax, + static (context, ct) => context.TargetSymbol is IMethodSymbol methodSymbol + ? new { Syntax = (MethodDeclarationSyntax)context.TargetNode, Symbol = methodSymbol } + : null) .Where( static modelData => modelData is not null); @@ -584,19 +579,6 @@ static ExpressionSyntax CreateEnumExpressionSyntax(T value) where T : Enum } } - private static bool ShouldVisitNode(SyntaxNode syntaxNode) - { - // We only support C# method declarations. - if (syntaxNode.Language != LanguageNames.CSharp - || !syntaxNode.IsKind(SyntaxKind.MethodDeclaration)) - { - return false; - } - - // Filter out methods with no attributes early. - return ((MethodDeclarationSyntax)syntaxNode).AttributeLists.Count > 0; - } - private static Diagnostic? GetDiagnosticIfInvalidMethodForGeneration(MethodDeclarationSyntax methodSyntax, IMethodSymbol method) { // Verify the method has no generic types or defined implementation diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj index 5806bf43f581c..0d6c923602b13 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj @@ -35,4 +35,19 @@ + + + + + + + + + + + + + + + diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Collections/Generic/ValueListBuilder.Pop.cs b/src/libraries/System.Runtime.InteropServices/src/System/Collections/Generic/ValueListBuilder.Pop.cs new file mode 100644 index 0000000000000..c5aa6bbff3a6d --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/src/System/Collections/Generic/ValueListBuilder.Pop.cs @@ -0,0 +1,20 @@ +// 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; + +namespace System.Collections.Generic +{ + /// + /// These public methods are required by RegexWriter. + /// + internal ref partial struct ValueListBuilder + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public T Pop() + { + _pos--; + return _span[_pos]; + } + } +} From 6cade39596c0f7ddccb0ab8b3fb4b678c8d03125 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Jul 2022 11:06:10 -0700 Subject: [PATCH 2/5] Move common code to shared location --- .../Generic/ValueListBuilder.Pop.cs | 0 .../LibraryImportGenerator.csproj | 2 +- ...m.Text.RegularExpressions.Generator.csproj | 2 +- .../Generic/ValueListBuilder.Pop.cs | 20 ------------------- 4 files changed, 2 insertions(+), 22 deletions(-) rename src/libraries/{System.Runtime.InteropServices => System.Private.CoreLib}/src/System/Collections/Generic/ValueListBuilder.Pop.cs (100%) delete mode 100644 src/libraries/System.Text.RegularExpressions/src/System/Collections/Generic/ValueListBuilder.Pop.cs diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Collections/Generic/ValueListBuilder.Pop.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.Pop.cs similarity index 100% rename from src/libraries/System.Runtime.InteropServices/src/System/Collections/Generic/ValueListBuilder.Pop.cs rename to src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.Pop.cs diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj index 0d6c923602b13..ab8172b697907 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj @@ -47,7 +47,7 @@ - + diff --git a/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj b/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj index ff5a56cee8569..bf14a855c9014 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj +++ b/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj @@ -34,7 +34,7 @@ - + diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Collections/Generic/ValueListBuilder.Pop.cs b/src/libraries/System.Text.RegularExpressions/src/System/Collections/Generic/ValueListBuilder.Pop.cs deleted file mode 100644 index c5aa6bbff3a6d..0000000000000 --- a/src/libraries/System.Text.RegularExpressions/src/System/Collections/Generic/ValueListBuilder.Pop.cs +++ /dev/null @@ -1,20 +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; - -namespace System.Collections.Generic -{ - /// - /// These public methods are required by RegexWriter. - /// - internal ref partial struct ValueListBuilder - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public T Pop() - { - _pos--; - return _span[_pos]; - } - } -} From 6ed1066a9aa7db313764b2a39a334be0de759391 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Jul 2022 11:43:12 -0700 Subject: [PATCH 3/5] Update projects --- .../src/System.Text.RegularExpressions.csproj | 2 +- .../UnitTests/System.Text.RegularExpressions.Unit.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Text.RegularExpressions/src/System.Text.RegularExpressions.csproj b/src/libraries/System.Text.RegularExpressions/src/System.Text.RegularExpressions.csproj index 952ab67d9f9c9..56a71e7e8126f 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System.Text.RegularExpressions.csproj +++ b/src/libraries/System.Text.RegularExpressions/src/System.Text.RegularExpressions.csproj @@ -5,7 +5,6 @@ - @@ -91,6 +90,7 @@ + diff --git a/src/libraries/System.Text.RegularExpressions/tests/UnitTests/System.Text.RegularExpressions.Unit.Tests.csproj b/src/libraries/System.Text.RegularExpressions/tests/UnitTests/System.Text.RegularExpressions.Unit.Tests.csproj index eb35b0bcd294a..62948390630d3 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/UnitTests/System.Text.RegularExpressions.Unit.Tests.csproj +++ b/src/libraries/System.Text.RegularExpressions/tests/UnitTests/System.Text.RegularExpressions.Unit.Tests.csproj @@ -24,7 +24,7 @@ - + From 65fbf2dcbaef4d74f8c3b8650f1bfb533765c682 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 7 Jul 2022 10:59:38 -0700 Subject: [PATCH 4/5] Update Roslyn version for the generators that ship with the ref pack to the public version that matches the SDK that arcade's global.json is referencing (also the public version used by VS 17.3 Preview 2) --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 26772fc07ff54..eafe62b3c92ad 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -36,7 +36,7 @@ This version is a moving target until we ship. It should never go ahead of the Roslyn version included in the SDK version in dotnet/arcade's global.json to avoid causing breaks in product construction. --> - 4.2.0-2.final + 4.3.0-2.final From c5ff411f0b6665e1badc04e7df2fb75136c798b4 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 7 Jul 2022 13:49:25 -0700 Subject: [PATCH 5/5] Update the version of Roslyn that the tests reference to match at least MicrosoftCodeAnalysisVersion_4_X --- eng/Versions.props | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 3961a095dde37..11ccae56bd51f 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -41,11 +41,11 @@ 3.3.3 - 4.3.0-1.22206.2 - 4.3.0-1.22206.2 - 4.3.0-1.22206.2 + 4.3.0-2.final + 4.3.0-2.final + 4.3.0-2.final 7.0.0-preview1.22329.1 - 4.3.0-1.22206.2 + 4.3.0-2.final