From 1e529bcbb641db19b1b9cc28a2213f8f90ef36a7 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 2 Mar 2022 17:07:43 -0800 Subject: [PATCH] Update Roslyn and use new step tracking API in incremental tests. (#63978) --- eng/Versions.props | 25 ++-- eng/formatting/format.sh | 1 + .../src/Interop/OSX/Interop.Libraries.cs | 1 - .../src/Interop/Unix/Interop.Libraries.cs | 2 +- .../Interop/Unix/libc/Interop.GetParentPid.cs | 2 +- .../System/PlatformDetection.Unix.cs | 8 +- ...sions.Logging.Generators.Roslyn3.11.csproj | 2 +- ...nsions.Logging.Generators.Roslyn4.0.csproj | 2 +- ...Logging.Generators.Roslyn3.11.Tests.csproj | 2 +- ....Logging.Generators.Roslyn4.0.Tests.csproj | 2 +- .../DllImportGenerator/DllImportGenerator.cs | 63 +++----- .../IncrementalGenerationTests.cs | 141 +++++++++--------- .../DllImportGenerator.UnitTests/TestUtils.cs | 5 +- .../tests/TestAssets/NativeExports/Error.cs | 6 +- ...xt.Json.SourceGeneration.Roslyn3.11.csproj | 4 +- ...ext.Json.SourceGeneration.Roslyn4.0.csproj | 2 +- .../ConstructorTests.ParameterMatching.cs | 4 +- ...rceGeneration.Roslyn3.11.Unit.Tests.csproj | 2 +- ...urceGeneration.Roslyn4.0.Unit.Tests.csproj | 2 +- src/tests/Directory.Build.props | 3 +- src/tests/Directory.Build.targets | 2 + .../HeapExpansion/bestfit-threaded.cs | 12 +- 22 files changed, 140 insertions(+), 153 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 08785bb49e7f0..9a19144b0bae8 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -22,20 +22,27 @@ $(AssemblyVersion) true + - - 3.11.0 - 4.0.1 - 4.0.1 + 3.11.0 + 4.0.1 - 3.3.2 - 4.0.1 - 4.0.1 + 3.3.3 + 4.2.0-2.22128.1 + 4.2.0-2.22128.1 + 4.2.0-2.22128.1 7.0.0-preview1.22119.1 - - 4.2.0-2.22105.4 + 4.2.0-2.22128.1 + + 4.2.0-2.22128.1 2.0.0-alpha.1.21525.11 diff --git a/eng/formatting/format.sh b/eng/formatting/format.sh index 077bbd750fef5..ac044fef44091 100755 --- a/eng/formatting/format.sh +++ b/eng/formatting/format.sh @@ -14,6 +14,7 @@ if [ -n "$NATIVE_FILES" ]; then # Add back the modified files to staging echo "$NATIVE_FILES" | xargs git add fi + if [ -n "$MANAGED_FILES" ]; then # Format all selected files echo "$MANAGED_FILES" | cat | xargs | sed -e 's/ /,/g' | dotnet format --no-restore --include - diff --git a/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs b/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs index dc5602bb0c66c..36cdea9e1bd9a 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs @@ -15,6 +15,5 @@ internal static partial class Libraries internal const string SystemConfigurationLibrary = "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration"; internal const string AppleCryptoNative = "libSystem.Security.Cryptography.Native.Apple"; internal const string MsQuic = "libmsquic.dylib"; - internal const string libc = "libc"; } } diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs index 1a0114cca2189..7ec51da64f254 100644 --- a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs @@ -5,7 +5,7 @@ internal static partial class Interop { internal static partial class Libraries { - internal const string Libc = "libc"; + internal const string libc = "libc"; // Shims internal const string SystemNative = "libSystem.Native"; diff --git a/src/libraries/Common/src/Interop/Unix/libc/Interop.GetParentPid.cs b/src/libraries/Common/src/Interop/Unix/libc/Interop.GetParentPid.cs index 9e2bd72ea28ff..f43f81fb09c29 100644 --- a/src/libraries/Common/src/Interop/Unix/libc/Interop.GetParentPid.cs +++ b/src/libraries/Common/src/Interop/Unix/libc/Interop.GetParentPid.cs @@ -7,7 +7,7 @@ internal static partial class Interop { internal static partial class @libc { - [GeneratedDllImport(Libraries.Libc, EntryPoint = "getppid")] + [GeneratedDllImport(Libraries.libc, EntryPoint = "getppid")] internal static partial int GetParentPid(); } } diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs index 207cd17f3b538..5524fd8266d6b 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs @@ -51,7 +51,7 @@ public static partial class PlatformDetection public static bool IsNotFedoraOrRedHatFamily => !IsFedora && !IsRedHatFamily; public static bool IsNotDebian10 => !IsDebian10; - public static bool IsSuperUser => IsBrowser || IsWindows ? false : Libc.geteuid() == 0; + public static bool IsSuperUser => IsBrowser || IsWindows ? false : libc.geteuid() == 0; public static Version OpenSslVersion => !IsOSXLike && !IsWindows && !IsAndroid ? GetOpenSslVersion() : @@ -77,7 +77,7 @@ public static string LibcRelease try { - return Marshal.PtrToStringAnsi(Libc.gnu_get_libc_release()); + return Marshal.PtrToStringAnsi(libc.gnu_get_libc_release()); } catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException) { @@ -101,7 +101,7 @@ public static string LibcVersion try { - return Marshal.PtrToStringAnsi(Libc.gnu_get_libc_version()); + return Marshal.PtrToStringAnsi(libc.gnu_get_libc_version()); } catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException) { @@ -324,7 +324,7 @@ private struct DistroInfo public Version VersionId { get; set; } } - private static partial class Libc + private static partial class @libc { [GeneratedDllImport("libc", SetLastError = true)] public static unsafe partial uint geteuid(); diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Microsoft.Extensions.Logging.Generators.Roslyn3.11.csproj b/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Microsoft.Extensions.Logging.Generators.Roslyn3.11.csproj index 4a0f795521591..3396f4b39c095 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Microsoft.Extensions.Logging.Generators.Roslyn3.11.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Microsoft.Extensions.Logging.Generators.Roslyn3.11.csproj @@ -2,7 +2,7 @@ 3.11 - $(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11) + $(MicrosoftCodeAnalysisVersion_3_11) diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Microsoft.Extensions.Logging.Generators.Roslyn4.0.csproj b/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Microsoft.Extensions.Logging.Generators.Roslyn4.0.csproj index 50e939c50b198..5a5a2819a4453 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Microsoft.Extensions.Logging.Generators.Roslyn4.0.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Microsoft.Extensions.Logging.Generators.Roslyn4.0.csproj @@ -2,7 +2,7 @@ 4.0 - $(MicrosoftCodeAnalysisCSharpWorkspacesVersion) + $(MicrosoftCodeAnalysisVersion_4_0) $(DefineConstants);ROSLYN4_0_OR_GREATER diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/Microsoft.Extensions.Logging.Generators.Roslyn3.11.Tests.csproj b/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/Microsoft.Extensions.Logging.Generators.Roslyn3.11.Tests.csproj index d5535724481db..477019528c026 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/Microsoft.Extensions.Logging.Generators.Roslyn3.11.Tests.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/Microsoft.Extensions.Logging.Generators.Roslyn3.11.Tests.csproj @@ -1,7 +1,7 @@ - $(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11) + $(MicrosoftCodeAnalysisVersion_3_11) true diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/Microsoft.Extensions.Logging.Generators.Roslyn4.0.Tests.csproj b/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/Microsoft.Extensions.Logging.Generators.Roslyn4.0.Tests.csproj index 43161fe76593e..2c991cca742c3 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/Microsoft.Extensions.Logging.Generators.Roslyn4.0.Tests.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/tests/Microsoft.Extensions.Logging.Generators.Tests/Microsoft.Extensions.Logging.Generators.Roslyn4.0.Tests.csproj @@ -1,7 +1,7 @@ - $(MicrosoftCodeAnalysisCSharpWorkspacesVersion) + $(MicrosoftCodeAnalysisVersion_4_0) $(DefineConstants);ROSLYN4_0_OR_GREATER true -O1 diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs index 908f32e3d8fff..6d46ce5f01379 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs @@ -44,31 +44,14 @@ public override int GetHashCode() } } - public class IncrementalityTracker + public static class StepNames { - public enum StepName - { - CalculateStubInformation, - GenerateSingleStub, - NormalizeWhitespace, - ConcatenateStubs, - OutputSourceFile - } - - public record ExecutedStepInfo(StepName Step, object Input); - - private readonly List _executedSteps = new(); - public IEnumerable ExecutedSteps => _executedSteps; - - internal void RecordExecutedStep(ExecutedStepInfo step) => _executedSteps.Add(step); + public const string CalculateStubInformation = nameof(CalculateStubInformation); + public const string GenerateSingleStub = nameof(GenerateSingleStub); + public const string NormalizeWhitespace = nameof(NormalizeWhitespace); + public const string ConcatenateStubs = nameof(ConcatenateStubs); } - /// - /// This property provides a test-only hook to enable testing the incrementality of the source generator. - /// This will be removed when https://github.com/dotnet/roslyn/issues/54832 is implemented and can be consumed. - /// - public IncrementalityTracker? IncrementalTracker { get; set; } - public void Initialize(IncrementalGeneratorInitializationContext context) { var attributedMethods = context.SyntaxProvider @@ -128,7 +111,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) }); IncrementalValueProvider stubOptions = context.AnalyzerConfigOptionsProvider - .Select((options, ct) => new DllImportGeneratorOptions(options.GlobalOptions)); + .Select(static (options, ct) => new DllImportGeneratorOptions(options.GlobalOptions)); IncrementalValueProvider stubEnvironment = compilationAndTargetFramework .Combine(stubOptions) @@ -151,34 +134,24 @@ public void Initialize(IncrementalGeneratorInitializationContext context) Environment = data.Right }) .Select( - (data, ct) => - { - IncrementalTracker?.RecordExecutedStep(new IncrementalityTracker.ExecutedStepInfo(IncrementalityTracker.StepName.CalculateStubInformation, data)); - return (data.Syntax, StubContext: CalculateStubInformation(data.Symbol, data.Environment, ct)); - } + static (data, ct) => (data.Syntax, StubContext: CalculateStubInformation(data.Symbol, data.Environment, ct)) ) .WithComparer(Comparers.CalculatedContextWithSyntax) + .WithTrackingName(StepNames.CalculateStubInformation) .Combine(stubOptions) .Select( - (data, ct) => - { - IncrementalTracker?.RecordExecutedStep(new IncrementalityTracker.ExecutedStepInfo(IncrementalityTracker.StepName.GenerateSingleStub, data)); - return GenerateSource(data.Left.StubContext, data.Left.Syntax, data.Right); - } + static (data, ct) => GenerateSource(data.Left.StubContext, data.Left.Syntax, data.Right) ) .WithComparer(Comparers.GeneratedSyntax) + .WithTrackingName(StepNames.GenerateSingleStub) // Handle NormalizeWhitespace as a separate stage for incremental runs since it is an expensive operation. .Select( - (data, ct) => - { - IncrementalTracker?.RecordExecutedStep(new IncrementalityTracker.ExecutedStepInfo(IncrementalityTracker.StepName.NormalizeWhitespace, data)); - return (data.Item1.NormalizeWhitespace().ToFullString(), data.Item2); - }) + static (data, ct) => (data.Item1.NormalizeWhitespace().ToFullString(), data.Item2)) + .WithTrackingName(StepNames.NormalizeWhitespace) .Collect() .WithComparer(Comparers.GeneratedSourceSet) - .Select((generatedSources, ct) => + .Select(static (generatedSources, ct) => { - IncrementalTracker?.RecordExecutedStep(new IncrementalityTracker.ExecutedStepInfo(IncrementalityTracker.StepName.ConcatenateStubs, generatedSources)); StringBuilder source = new(); // Mark in source that the file is auto-generated. source.AppendLine("// "); @@ -190,12 +163,12 @@ public void Initialize(IncrementalGeneratorInitializationContext context) } return (source: source.ToString(), diagnostics: diagnostics.ToImmutable()); }) - .WithComparer(Comparers.GeneratedSource); + .WithComparer(Comparers.GeneratedSource) + .WithTrackingName(StepNames.ConcatenateStubs); context.RegisterSourceOutput(methodSourceAndDiagnostics, - (context, data) => + static (context, data) => { - IncrementalTracker?.RecordExecutedStep(new IncrementalityTracker.ExecutedStepInfo(IncrementalityTracker.StepName.OutputSourceFile, data)); foreach (Diagnostic diagnostic in data.Item2) { context.ReportDiagnostic(diagnostic); @@ -510,7 +483,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation(IMethod return new IncrementalStubGenerationContext(environment, dllImportStub, additionalAttributes.ToImmutableArray(), stubDllImportData, generatorDiagnostics.Diagnostics.ToImmutableArray()); } - private (MemberDeclarationSyntax, ImmutableArray) GenerateSource( + private static (MemberDeclarationSyntax, ImmutableArray) GenerateSource( IncrementalStubGenerationContext dllImportStub, MethodDeclarationSyntax originalSyntax, DllImportGeneratorOptions options) @@ -567,7 +540,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation(IMethod return (PrintGeneratedSource(originalSyntax, dllImportStub.StubContext, code), dllImportStub.Diagnostics.AddRange(diagnostics.Diagnostics)); } - private MemberDeclarationSyntax PrintForwarderStub(MethodDeclarationSyntax userDeclaredMethod, IncrementalStubGenerationContext stub, GeneratorDiagnostics diagnostics) + private static MemberDeclarationSyntax PrintForwarderStub(MethodDeclarationSyntax userDeclaredMethod, IncrementalStubGenerationContext stub, GeneratorDiagnostics diagnostics) { GeneratedDllImportData targetDllImportData = GetTargetDllImportDataFromStubData( stub.DllImportData, diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/IncrementalGenerationTests.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/IncrementalGenerationTests.cs index d14773de2f07f..c3125b0544f6f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/IncrementalGenerationTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/IncrementalGenerationTests.cs @@ -16,6 +16,8 @@ namespace DllImportGenerator.UnitTests { public class IncrementalGenerationTests { + private static readonly GeneratorDriverOptions EnableIncrementalTrackingDriverOptions = new GeneratorDriverOptions(IncrementalGeneratorOutputKind.None, trackIncrementalGeneratorSteps: true); + public const string RequiresIncrementalSyntaxTreeModifySupport = "The GeneratorDriver treats all SyntaxTree replace operations on a Compilation as an Add/Remove operation instead of a Modify operation" + ", so all cached results based on that input are thrown out. As a result, we cannot validate that unrelated changes within the same SyntaxTree do not cause regeneration."; @@ -27,25 +29,23 @@ public async Task AddingNewUnrelatedType_DoesNotRegenerateSource() Compilation comp1 = await TestUtils.CreateCompilation(source); Microsoft.Interop.DllImportGenerator generator = new(); - GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new IIncrementalGenerator[] { generator }); + GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new IIncrementalGenerator[] { generator }, EnableIncrementalTrackingDriverOptions); driver = driver.RunGenerators(comp1); - generator.IncrementalTracker = new IncrementalityTracker(); - Compilation comp2 = comp1.AddSyntaxTrees(CSharpSyntaxTree.ParseText("struct Foo {}", new CSharpParseOptions(LanguageVersion.Preview))); - driver.RunGenerators(comp2); + GeneratorDriver driver2 = driver.RunGenerators(comp2); + GeneratorRunResult runResult = driver2.GetRunResult().Results[0]; - Assert.Collection(generator.IncrementalTracker.ExecutedSteps, + Assert.Collection(runResult.TrackedSteps[StepNames.CalculateStubInformation], step => { - Assert.Equal(IncrementalityTracker.StepName.CalculateStubInformation, step.Step); + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Unchanged, output.Reason)); }); } -#pragma warning disable xUnit1004 // Test methods should not be skipped. These tests will be updated to use the new incremental work tracking APIs and enabled then. - [ConditionalFact(Skip = RequiresIncrementalSyntaxTreeModifySupport)] -#pragma warning restore + [ConditionalFact] public async Task AppendingUnrelatedSource_DoesNotRegenerateSource() { string source = $"namespace NS{{{CodeSnippets.BasicParametersAndModifiers()}}}"; @@ -55,21 +55,23 @@ public async Task AppendingUnrelatedSource_DoesNotRegenerateSource() Compilation comp1 = await TestUtils.CreateCompilation(new[] { syntaxTree }); Microsoft.Interop.DllImportGenerator generator = new(); - GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }); + GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }, EnableIncrementalTrackingDriverOptions); driver = driver.RunGenerators(comp1); - generator.IncrementalTracker = new IncrementalityTracker(); - SyntaxTree newTree = syntaxTree.WithRootAndOptions(syntaxTree.GetCompilationUnitRoot().AddMembers(SyntaxFactory.ParseMemberDeclaration("struct Foo {}")!), syntaxTree.Options); Compilation comp2 = comp1.ReplaceSyntaxTree(comp1.SyntaxTrees.First(), newTree); - driver.RunGenerators(comp2); + GeneratorDriver driver2 = driver.RunGenerators(comp2); + GeneratorRunResult runResult = driver2.GetRunResult().Results[0]; - Assert.Collection(generator.IncrementalTracker.ExecutedSteps, + Assert.Collection(runResult.TrackedSteps[StepNames.CalculateStubInformation], step => { - Assert.Equal(IncrementalityTracker.StepName.CalculateStubInformation, step.Step); + // The input contains symbols and Compilation objects, so it will always be different. + // However, we validate that the calculated stub information is identical. + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Unchanged, output.Reason)); }); } @@ -81,44 +83,53 @@ public async Task AddingFileWithNewGeneratedDllImport_DoesNotRegenerateOriginalM Compilation comp1 = await TestUtils.CreateCompilation(source); Microsoft.Interop.DllImportGenerator generator = new(); - GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }); + GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }, EnableIncrementalTrackingDriverOptions); driver = driver.RunGenerators(comp1); - generator.IncrementalTracker = new IncrementalityTracker(); - Compilation comp2 = comp1.AddSyntaxTrees(CSharpSyntaxTree.ParseText(CodeSnippets.BasicParametersAndModifiers(), new CSharpParseOptions(LanguageVersion.Preview))); - driver.RunGenerators(comp2); - Assert.Equal(2, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.CalculateStubInformation)); - Assert.Equal(1, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.GenerateSingleStub)); - Assert.Equal(1, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.NormalizeWhitespace)); - Assert.Equal(1, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.ConcatenateStubs)); - Assert.Equal(1, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.OutputSourceFile)); + GeneratorDriver driver2 = driver.RunGenerators(comp2); + GeneratorRunResult runResult = driver2.GetRunResult().Results[0]; + + Assert.Collection(runResult.TrackedSteps[StepNames.CalculateStubInformation], + step => + { + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Unchanged, output.Reason)); + }, + step => + { + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.New, output.Reason)); + }); } [ConditionalFact] public async Task ReplacingFileWithNewGeneratedDllImport_DoesNotRegenerateStubsInOtherFiles() { - string source = CodeSnippets.BasicParametersAndModifiers(); - Compilation comp1 = await TestUtils.CreateCompilation(new string[] { CodeSnippets.BasicParametersAndModifiers(), CodeSnippets.BasicParametersAndModifiers() }); Microsoft.Interop.DllImportGenerator generator = new(); - GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }); + GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }, EnableIncrementalTrackingDriverOptions); driver = driver.RunGenerators(comp1); - generator.IncrementalTracker = new IncrementalityTracker(); - Compilation comp2 = comp1.ReplaceSyntaxTree(comp1.SyntaxTrees.First(), CSharpSyntaxTree.ParseText(CodeSnippets.BasicParametersAndModifiers(), new CSharpParseOptions(LanguageVersion.Preview))); - driver.RunGenerators(comp2); + GeneratorDriver driver2 = driver.RunGenerators(comp2); + GeneratorRunResult runResult = driver2.GetRunResult().Results[0]; - Assert.Equal(2, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.CalculateStubInformation)); - Assert.Equal(1, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.GenerateSingleStub)); - Assert.Equal(1, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.NormalizeWhitespace)); - Assert.Equal(1, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.ConcatenateStubs)); - Assert.Equal(1, generator.IncrementalTracker.ExecutedSteps.Count(s => s.Step == IncrementalityTracker.StepName.OutputSourceFile)); + Assert.Collection(runResult.TrackedSteps[StepNames.CalculateStubInformation], + step => + { + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Modified, output.Reason)); + }, + step => + { + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Unchanged, output.Reason)); + }); } [ConditionalFact] @@ -137,41 +148,30 @@ public async Task ChangingMarshallingStrategy_RegeneratesStub() comp1 = comp1.AddSyntaxTrees(customTypeImpl1Tree); Microsoft.Interop.DllImportGenerator generator = new(); - GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }); + GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }, EnableIncrementalTrackingDriverOptions); driver = driver.RunGenerators(comp1); - generator.IncrementalTracker = new IncrementalityTracker(); - Compilation comp2 = comp1.ReplaceSyntaxTree(customTypeImpl1Tree, CSharpSyntaxTree.ParseText(customTypeImpl2, new CSharpParseOptions(LanguageVersion.Preview))); - driver.RunGenerators(comp2); + GeneratorDriver driver2 = driver.RunGenerators(comp2); + GeneratorRunResult runResult = driver2.GetRunResult().Results[0]; - Assert.Collection(generator.IncrementalTracker.ExecutedSteps, - step => - { - Assert.Equal(IncrementalityTracker.StepName.CalculateStubInformation, step.Step); - }, - step => - { - Assert.Equal(IncrementalityTracker.StepName.GenerateSingleStub, step.Step); - }, - step => - { - Assert.Equal(IncrementalityTracker.StepName.NormalizeWhitespace, step.Step); - }, + Assert.Collection(runResult.TrackedSteps[StepNames.CalculateStubInformation], step => { - Assert.Equal(IncrementalityTracker.StepName.ConcatenateStubs, step.Step); - }, + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Modified, output.Reason)); + }); + + Assert.Collection(runResult.TrackedSteps[StepNames.GenerateSingleStub], step => { - Assert.Equal(IncrementalityTracker.StepName.OutputSourceFile, step.Step); + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Modified, output.Reason)); }); } -#pragma warning disable xUnit1004 // Test methods should not be skipped. These tests will be updated to use the new incremental work tracking APIs and enabled then. - [ConditionalFact(Skip = RequiresIncrementalSyntaxTreeModifySupport)] -#pragma warning restore + [ConditionalFact] public async Task ChangingMarshallingAttributes_SameStrategy_DoesNotRegenerate() { string source = CodeSnippets.BasicParametersAndModifiers(); @@ -181,29 +181,32 @@ public async Task ChangingMarshallingAttributes_SameStrategy_DoesNotRegenerate() Compilation comp1 = await TestUtils.CreateCompilation(new[] { syntaxTree }); Microsoft.Interop.DllImportGenerator generator = new(); - GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }); + GeneratorDriver driver = TestUtils.CreateDriver(comp1, null, new[] { generator }, EnableIncrementalTrackingDriverOptions); driver = driver.RunGenerators(comp1); - generator.IncrementalTracker = new IncrementalityTracker(); - SyntaxTree newTree = syntaxTree.WithRootAndOptions( - syntaxTree.GetCompilationUnitRoot().AddMembers( - SyntaxFactory.ParseMemberDeclaration( - CodeSnippets.MarshalAsParametersAndModifiers(System.Runtime.InteropServices.UnmanagedType.Bool))!), + SyntaxFactory.ParseCompilationUnit( + CodeSnippets.MarshalAsParametersAndModifiers(System.Runtime.InteropServices.UnmanagedType.Bool)), syntaxTree.Options); Compilation comp2 = comp1.ReplaceSyntaxTree(comp1.SyntaxTrees.First(), newTree); - driver.RunGenerators(comp2); - Assert.Collection(generator.IncrementalTracker.ExecutedSteps, + GeneratorDriver driver2 = driver.RunGenerators(comp2); + GeneratorRunResult runResult = driver2.GetRunResult().Results[0]; + + Assert.Collection(runResult.TrackedSteps[StepNames.CalculateStubInformation], step => { - Assert.Equal(IncrementalityTracker.StepName.CalculateStubInformation, step.Step); - }, + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Modified, output.Reason)); + }); + + Assert.Collection(runResult.TrackedSteps[StepNames.GenerateSingleStub], step => { - Assert.Equal(IncrementalityTracker.StepName.GenerateSingleStub, step.Step); + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Unchanged, output.Reason)); }); } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/TestUtils.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/TestUtils.cs index edff3a4a99540..f69862200bd29 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/TestUtils.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/TestUtils.cs @@ -213,11 +213,12 @@ public static Compilation RunGenerators(Compilation comp, AnalyzerConfigOptionsP return d; } - public static GeneratorDriver CreateDriver(Compilation c, AnalyzerConfigOptionsProvider? options, IIncrementalGenerator[] generators) + public static GeneratorDriver CreateDriver(Compilation c, AnalyzerConfigOptionsProvider? options, IIncrementalGenerator[] generators, GeneratorDriverOptions driverOptions = default) => CSharpGeneratorDriver.Create( ImmutableArray.Create(generators.Select(gen => gen.AsSourceGenerator()).ToArray()), parseOptions: (CSharpParseOptions)c.SyntaxTrees.First().Options, - optionsProvider: options); + optionsProvider: options, + driverOptions: driverOptions); // The non-configurable test-packages folder may be incomplete/corrupt. // - https://github.com/dotnet/roslyn-sdk/issues/487 diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/Error.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/Error.cs index a71a29696a007..cbbac4e31d2b3 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/Error.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/Error.cs @@ -17,7 +17,7 @@ private class Kernel32 public static extern int GetLastError(); } - private class Libc + private class @libc { [DllImport("libc")] internal static unsafe extern int* __errno_location(); @@ -54,11 +54,11 @@ private static void SetLastError(int error) } else if (OperatingSystem.IsMacOS()) { - *Libc.__error() = error; + *libc.__error() = error; } else if (OperatingSystem.IsLinux()) { - *Libc.__errno_location() = error; + *libc.__errno_location() = error; } else { diff --git a/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn3.11.csproj b/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn3.11.csproj index 5168388eb1891..48ac8d6904c5d 100644 --- a/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn3.11.csproj +++ b/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn3.11.csproj @@ -2,7 +2,7 @@ 3.11 - $(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11) + $(MicrosoftCodeAnalysisVersion_3_11) @@ -11,4 +11,4 @@ - \ No newline at end of file + diff --git a/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn4.0.csproj b/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn4.0.csproj index b088862764623..5efc9ea5b77ab 100644 --- a/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn4.0.csproj +++ b/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.Roslyn4.0.csproj @@ -3,7 +3,7 @@ true 4.0 - $(MicrosoftCodeAnalysisCSharpWorkspacesVersion) + $(MicrosoftCodeAnalysisVersion_4_0) $(DefineConstants);ROSLYN4_0_OR_GREATER diff --git a/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs index 6ad72300aba2d..59a05d7be9120 100644 --- a/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs +++ b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs @@ -1340,12 +1340,12 @@ public void StructWithPropertyInit_OverrideInitedProperty() var obj = JsonSerializer.Deserialize(json); Assert.Equal(43, obj.A); Assert.Equal(0, obj.B); - + json = @"{""A"":0,""B"":44}"; obj = JsonSerializer.Deserialize(json); Assert.Equal(0, obj.A); Assert.Equal(44, obj.B); - + json = @"{""B"":45}"; obj = JsonSerializer.Deserialize(json); Assert.Equal(42, obj.A); // JSON doesn't set A property so it's expected to be 42 diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj index 578009ece67e3..9fec30cc1d6fa 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj @@ -1,6 +1,6 @@ - $(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11) + $(MicrosoftCodeAnalysisVersion_3_11) true diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.0.Unit.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.0.Unit.Tests.csproj index f32555bc0047d..672ec18537997 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.0.Unit.Tests.csproj +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.0.Unit.Tests.csproj @@ -1,6 +1,6 @@ - $(MicrosoftCodeAnalysisCSharpWorkspacesVersion) + $(MicrosoftCodeAnalysisVersion_4_0) $(DefineConstants);ROSLYN4_0_OR_GREATER true diff --git a/src/tests/Directory.Build.props b/src/tests/Directory.Build.props index 31085efb691b6..606bf57399cbf 100644 --- a/src/tests/Directory.Build.props +++ b/src/tests/Directory.Build.props @@ -123,7 +123,7 @@ false false - 78,162,164,168,169,219,251,252,414,429,618,642,649,652,659,675,1691,1717,1718,3001,3002,3003,3005,3008 + 78,162,164,168,169,219,251,252,414,429,618,642,649,652,659,675,1691,1717,1718,3001,3002,3003,3005,3008,8981 false false true @@ -196,4 +196,5 @@ + diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index 6bfa19ebce109..ca742f725a5f8 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -278,7 +278,9 @@ $(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\project.assets.json + + true diff --git a/src/tests/GC/Features/HeapExpansion/bestfit-threaded.cs b/src/tests/GC/Features/HeapExpansion/bestfit-threaded.cs index 7125ad42b4f53..1317ee5361234 100644 --- a/src/tests/GC/Features/HeapExpansion/bestfit-threaded.cs +++ b/src/tests/GC/Features/HeapExpansion/bestfit-threaded.cs @@ -10,7 +10,7 @@ public class one_pass { - public Random r = new Random(request.RandomSeed); + public Random r = new Random(Request.RandomSeed); [SecuritySafeCritical] public one_pass () @@ -20,7 +20,7 @@ public one_pass () int allocation_volume = 100000; float survival_rate = 0.6f; int steady_state_factor = 5; - request[] requests = new request[n_requests]; + Request[] requests = new Request[n_requests]; int inst_requests = 0; int total_reqs = 0; int nreqs_to_steady = 0; @@ -36,7 +36,7 @@ public one_pass () { inst_requests++; } - requests [i] = new request (allocation_volume, survival_rate); + requests [i] = new Request (allocation_volume, survival_rate); if (inst_requests == n_requests) { @@ -61,14 +61,14 @@ public one_pass () } -public class request +public class Request { Object[] survivors; GCHandle pin; - public Random r = new Random(request.RandomSeed); + public Random r = new Random(Request.RandomSeed); [SecuritySafeCritical] - public request (int alloc_volume, float surv_fraction) + public Request (int alloc_volume, float surv_fraction) { survivors = new Object [1 + (int)(alloc_volume*surv_fraction)/100]; int i = 0;