From 544fa8a40b08f1693650b1c53502543824459d91 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 14 Jan 2022 16:19:53 -0800 Subject: [PATCH 01/13] Update out-of-band generators to explicitly reference pinned versions of Roslyn so we can update our Roslyn version for generators that will either ship in .NET 7 or are for internal use only without accidentally breaking back-compat VS support. --- eng/Versions.props | 12 ++++++++---- ...t.Extensions.Logging.Generators.Roslyn3.11.csproj | 2 +- ...ft.Extensions.Logging.Generators.Roslyn4.0.csproj | 2 +- ...nsions.Logging.Generators.Roslyn3.11.Tests.csproj | 2 +- ...ensions.Logging.Generators.Roslyn4.0.Tests.csproj | 2 +- ...stem.Text.Json.SourceGeneration.Roslyn3.11.csproj | 4 ++-- ...ystem.Text.Json.SourceGeneration.Roslyn4.0.csproj | 2 +- ...son.SourceGeneration.Roslyn3.11.Unit.Tests.csproj | 2 +- ...Json.SourceGeneration.Roslyn4.0.Unit.Tests.csproj | 2 +- 9 files changed, 17 insertions(+), 13 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 8bc9373cc09ac7..6b6089820f32a7 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -39,18 +39,22 @@ + - - 3.11.0 - 4.0.1 - 4.0.1 + 3.11.0 + 4.0.1 3.3.2 4.0.1 + 4.0.1 4.0.1 7.0.0-preview1.21613.1 + 4.0.1 2.0.0-alpha.1.21525.11 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 4a0f7955215914..3396f4b39c095e 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 50e939c50b1985..5a5a2819a44534 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 e3ac6c40c52f26..40e10de4b24194 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 074da27c19e029..297b29404914ad 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.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 5168388eb18916..48ac8d6904c5d5 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 b088862764623d..5efc9ea5b77ab9 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/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 af08a0ae33acce..bf0c7d43254319 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 709f667c267a24..feaff89e020bb5 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 From 1e4f98fadd7d693a0ab5830de1120a988ac7bff1 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 18 Jan 2022 16:46:26 -0800 Subject: [PATCH 02/13] Update Roslyn and update the DllImportGenerator incremental generation tests to use the Incremental Step Tracking API. Blocked on dotnet/roslyn#58937 --- eng/Versions.props | 12 +- .../Internal/Cryptography/SymmetricPadding.cs | 2 +- ...icrosoft.Extensions.Hosting.Systemd.csproj | 2 + .../src/System/Globalization/IdnMapping.cs | 2 +- .../DllImportGenerator/DllImportGenerator.cs | 53 ++----- .../IncrementalGenerationTests.cs | 139 +++++++++--------- .../DllImportGenerator.UnitTests/TestUtils.cs | 5 +- 7 files changed, 99 insertions(+), 116 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 6b6089820f32a7..07700ac5321157 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -19,6 +19,7 @@ true false false + true $(AssemblyVersion) - 3.3.2 - 4.0.1 - 4.0.1 - 4.0.1 + 3.3.3 + 4.2.0-1.22068.2 + 4.2.0-1.22068.2 + 4.2.0-1.22068.2 7.0.0-preview1.21613.1 - 4.0.1 + 4.2.0-1.22068.2 + 4.2.0-1.22068.2 2.0.0-alpha.1.21525.11 diff --git a/src/libraries/Common/src/Internal/Cryptography/SymmetricPadding.cs b/src/libraries/Common/src/Internal/Cryptography/SymmetricPadding.cs index 1a2ae3d984bd9d..70350cfdf464ca 100644 --- a/src/libraries/Common/src/Internal/Cryptography/SymmetricPadding.cs +++ b/src/libraries/Common/src/Internal/Cryptography/SymmetricPadding.cs @@ -150,7 +150,7 @@ public static bool DepaddingRequired(PaddingMode padding) public static int GetPaddingLength(ReadOnlySpan block, PaddingMode paddingMode, int blockSize) { - int padBytes = 0; + int padBytes; // See PadBlock for a description of the padding modes. switch (paddingMode) diff --git a/src/libraries/Microsoft.Extensions.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj b/src/libraries/Microsoft.Extensions.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj index b9faefd40f2f07..9918456a0cedae 100644 --- a/src/libraries/Microsoft.Extensions.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj +++ b/src/libraries/Microsoft.Extensions.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj @@ -8,6 +8,8 @@ false true true + + $(NoWarn);CS8981 diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs index 81b20d53e55a48..ba627e59dbbb87 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs @@ -438,7 +438,7 @@ private static string PunycodeEncode(string unicode) /* handled already. Find the next larger one: */ int j; int m; - int test = 0; + int test; for (m = c_maxint, j = iAfterLastDot; j < iNextDot; j += IsSupplementary(test) ? 2 : 1) diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs index 2987b174a564a7..01d7efacbb5e74 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs @@ -47,31 +47,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 @@ -146,34 +129,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)); - } + (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); - } + (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); - }) + (data, ct) => (data.Item1.NormalizeWhitespace().ToFullString(), data.Item2)) + .WithTrackingName(StepNames.NormalizeWhitespace) .Collect() .WithComparer(Comparers.GeneratedSourceSet) .Select((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("// "); @@ -185,12 +158,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) => { - IncrementalTracker?.RecordExecutedStep(new IncrementalityTracker.ExecutedStepInfo(IncrementalityTracker.StepName.OutputSourceFile, data)); foreach (Diagnostic diagnostic in data.Item2) { context.ReportDiagnostic(diagnostic); 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 d14773de2f07f9..a2dc19115bc8d8 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,20 +83,26 @@ 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.Cached, output.Reason)); + }, + step => + { + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.New, output.Reason)); + }); } [ConditionalFact] @@ -105,20 +113,25 @@ public async Task ReplacingFileWithNewGeneratedDllImport_DoesNotRegenerateStubsI 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.Cached, output.Reason)); + }, + step => + { + Assert.Collection(step.Outputs, + output => Assert.Equal(IncrementalStepRunReason.Modified, output.Reason)); + }); } [ConditionalFact] @@ -137,41 +150,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 +183,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 154af90a4c1405..1ee9b843840b3e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/TestUtils.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/TestUtils.cs @@ -207,11 +207,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 From 1f5ea02e23f0537215a3cf0cbe5d23c193ab4651 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 20 Jan 2022 16:43:03 -0800 Subject: [PATCH 03/13] Bump Roslyn to get the bugfix and finish updating the incremental generation tests. Make the remaining Select callbacks static now that we aren't using any state on the generator object. --- eng/Versions.props | 10 +++++----- .../gen/DllImportGenerator/DllImportGenerator.cs | 16 ++++++++-------- .../IncrementalGenerationTests.cs | 8 +++----- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 07700ac5321157..4ba8609b50f0eb 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -51,12 +51,12 @@ 3.3.3 - 4.2.0-1.22068.2 - 4.2.0-1.22068.2 - 4.2.0-1.22068.2 + 4.2.0-1.22070.6 + 4.2.0-1.22070.6 + 4.2.0-1.22070.6 7.0.0-preview1.21613.1 - 4.2.0-1.22068.2 - 4.2.0-1.22068.2 + 4.2.0-1.22070.6 + 4.2.0-1.22070.6 2.0.0-alpha.1.21525.11 diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs index 01d7efacbb5e74..e41de538c9fa4a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs @@ -106,7 +106,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) @@ -129,23 +129,23 @@ public void Initialize(IncrementalGeneratorInitializationContext context) Environment = data.Right }) .Select( - (data, ct) => (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) => 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) => (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) => { StringBuilder source = new(); // Mark in source that the file is auto-generated. @@ -162,7 +162,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .WithTrackingName(StepNames.ConcatenateStubs); context.RegisterSourceOutput(methodSourceAndDiagnostics, - (context, data) => + static (context, data) => { foreach (Diagnostic diagnostic in data.Item2) { @@ -420,7 +420,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) @@ -475,7 +475,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation(IMethod return (PrintGeneratedSource(originalSyntax, dllImportStub.StubContext, code), dllImportStub.Diagnostics.AddRange(diagnostics.Diagnostics)); } - private MemberDeclarationSyntax PrintForwarderStub(MethodDeclarationSyntax userDeclaredMethod, IncrementalStubGenerationContext stub) + private static MemberDeclarationSyntax PrintForwarderStub(MethodDeclarationSyntax userDeclaredMethod, IncrementalStubGenerationContext stub) { SyntaxTokenList modifiers = StripTriviaFromModifiers(userDeclaredMethod.Modifiers); modifiers = AddToModifiers(modifiers, SyntaxKind.ExternKeyword); 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 a2dc19115bc8d8..c3125b0544f6f4 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/IncrementalGenerationTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/IncrementalGenerationTests.cs @@ -96,7 +96,7 @@ public async Task AddingFileWithNewGeneratedDllImport_DoesNotRegenerateOriginalM step => { Assert.Collection(step.Outputs, - output => Assert.Equal(IncrementalStepRunReason.Cached, output.Reason)); + output => Assert.Equal(IncrementalStepRunReason.Unchanged, output.Reason)); }, step => { @@ -108,8 +108,6 @@ public async Task AddingFileWithNewGeneratedDllImport_DoesNotRegenerateOriginalM [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(); @@ -125,12 +123,12 @@ public async Task ReplacingFileWithNewGeneratedDllImport_DoesNotRegenerateStubsI step => { Assert.Collection(step.Outputs, - output => Assert.Equal(IncrementalStepRunReason.Cached, output.Reason)); + output => Assert.Equal(IncrementalStepRunReason.Modified, output.Reason)); }, step => { Assert.Collection(step.Outputs, - output => Assert.Equal(IncrementalStepRunReason.Modified, output.Reason)); + output => Assert.Equal(IncrementalStepRunReason.Unchanged, output.Reason)); }); } From 8cdb7d0bc2aacf7c58d1c535e61529ded59ffedd Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 4 Feb 2022 15:23:36 -0800 Subject: [PATCH 04/13] Escape per CS8981 throughout the repo. --- .../Interop/FreeBSD/Interop.Process.GetProcInfo.cs | 10 +++++----- .../procfs/Interop.ProcFsStat.ParseMapModules.cs | 2 +- .../Common/src/Interop/OSX/Interop.Libraries.cs | 5 ++--- src/libraries/Common/src/Interop/OSX/Interop.libc.cs | 2 +- .../Common/src/Interop/OSX/Interop.libobjc.cs | 2 +- .../OSX/Interop.libproc.GetProcessInfoById.cs | 2 +- .../Common/src/Interop/OSX/Interop.libproc.cs | 12 ++++++------ .../Interop.ProcFsStat.TryReadProcessStatusInfo.cs | 2 +- .../Common/src/Interop/Unix/Interop.Libraries.cs | 2 +- .../src/Interop/Unix/libc/Interop.GetParentPid.cs | 4 ++-- .../TestUtilities/System/PlatformDetection.Unix.cs | 8 ++++---- .../src/Microsoft.Extensions.Hosting.Systemd.csproj | 2 -- .../tests/TestAssets/NativeExports/Error.cs | 2 +- .../Coreclr.TestWrapper/CoreclrTestWrapperLib.cs | 2 +- 14 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs b/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs index 09f7c97d302237..2136145dc577ed 100644 --- a/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs +++ b/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs @@ -50,14 +50,14 @@ internal struct gid_t public uint id; } [StructLayout(LayoutKind.Sequential)] - public struct timeval + public struct @timeval { public IntPtr tv_sec; public IntPtr tv_usec; } [StructLayout(LayoutKind.Sequential)] - private struct vnode + private struct @vnode { public long tv_sec; public long tv_usec; @@ -65,7 +65,7 @@ private struct vnode // sys/resource.h [StructLayout(LayoutKind.Sequential)] - internal struct rusage + internal struct @rusage { public timeval ru_utime; /* user time used */ public timeval ru_stime; /* system time used */ @@ -164,9 +164,9 @@ public unsafe struct kinfo_proc public int ki_numthreads; /* XXXKSE number of threads in total */ public int ki_tid; /* XXXKSE thread id */ private fixed byte ki_pri[4]; /* process priority */ - public rusage ki_rusage; /* process rusage statistics */ + public rusage ki_rusage; /* process @rusage statistics */ /* XXX - most fields in ki_rusage_ch are not (yet) filled in */ - private rusage ki_rusage_ch; /* rusage of children processes */ + private rusage ki_rusage_ch; /* @rusage of children processes */ private void* ki_pcb; /* kernel virtual addr of pcb */ private void* ki_kstack; /* kernel virtual addr of stack */ private void* ki_udata; /* User convenience pointer */ diff --git a/src/libraries/Common/src/Interop/Linux/procfs/Interop.ProcFsStat.ParseMapModules.cs b/src/libraries/Common/src/Interop/Linux/procfs/Interop.ProcFsStat.ParseMapModules.cs index 0f2287ce4164bd..4d4c23f6140ffe 100644 --- a/src/libraries/Common/src/Interop/Linux/procfs/Interop.ProcFsStat.ParseMapModules.cs +++ b/src/libraries/Common/src/Interop/Linux/procfs/Interop.ProcFsStat.ParseMapModules.cs @@ -11,7 +11,7 @@ internal static partial class Interop { - internal static partial class procfs + internal static partial class @procfs { private const string MapsFileName = "/maps"; diff --git a/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs b/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs index dc5602bb0c66ce..1a08cfb46da04b 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs @@ -8,13 +8,12 @@ internal static partial class Libraries internal const string CoreFoundationLibrary = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"; internal const string CoreServicesLibrary = "/System/Library/Frameworks/CoreServices.framework/CoreServices"; internal const string CFNetworkLibrary = "/System/Library/Frameworks/CFNetwork.framework/CFNetwork"; - internal const string libobjc = "/usr/lib/libobjc.dylib"; - internal const string libproc = "/usr/lib/libproc.dylib"; + internal const string @libobjc = "/usr/lib/libobjc.dylib"; + internal const string @libproc = "/usr/lib/libproc.dylib"; internal const string Odbc32 = "libodbc.2.dylib"; internal const string OpenLdap = "libldap.dylib"; 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/OSX/Interop.libc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libc.cs index 973dc0109842bb..8157ef8c9a5b1c 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.libc.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.libc.cs @@ -6,7 +6,7 @@ internal static partial class Interop { - internal static partial class libc + internal static partial class @libc { [StructLayout(LayoutKind.Sequential)] internal struct AttrList diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs index 175b8abd3d790c..c338e87bfc0635 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs @@ -6,7 +6,7 @@ internal static partial class Interop { - internal static partial class libobjc + internal static partial class @libobjc { [StructLayout(LayoutKind.Sequential)] private struct NSOperatingSystemVersion diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libproc.GetProcessInfoById.cs b/src/libraries/Common/src/Interop/OSX/Interop.libproc.GetProcessInfoById.cs index f667641d27c996..ccac9c97439596 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.libproc.GetProcessInfoById.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.libproc.GetProcessInfoById.cs @@ -8,7 +8,7 @@ internal static partial class Interop { - internal static partial class libproc + internal static partial class @libproc { // Constants from sys\param.h private const int MAXCOMLEN = 16; diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs index a51adbb79c0835..5543a994145ae2 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs @@ -11,7 +11,7 @@ internal static partial class Interop { - internal static partial class libproc + internal static partial class @libproc { // Constants from sys\param.h private const int MAXPATHLEN = 1024; @@ -350,9 +350,9 @@ internal static unsafe string proc_pidpath(int pid) } /// - /// Gets the rusage information for the process identified by the PID + /// Gets the @rusage information for the process identified by the PID /// - /// The process to retrieve the rusage for + /// The process to retrieve the @rusage for /// Specifies the type of struct that is passed in to buffer. Should be RUSAGE_INFO_V3 to specify a rusage_info_v3 struct. /// A buffer to be filled with rusage_info data /// Returns 0 on success; on fail, -1 and errno is set with the error code @@ -363,9 +363,9 @@ private static unsafe partial int proc_pid_rusage( rusage_info_v3* buffer); /// - /// Gets the rusage information for the process identified by the PID + /// Gets the @rusage information for the process identified by the PID /// - /// The process to retrieve the rusage for + /// The process to retrieve the @rusage for /// On success, returns a struct containing info about the process; on /// failure or when the caller doesn't have permissions to the process, throws a Win32Exception /// @@ -379,7 +379,7 @@ internal static unsafe rusage_info_v3 proc_pid_rusage(int pid) rusage_info_v3 info = default; - // Get the PIDs rusage info + // Get the PIDs @rusage info int result = proc_pid_rusage(pid, RUSAGE_INFO_V3, &info); if (result < 0) { diff --git a/src/libraries/Common/src/Interop/SunOS/procfs/Interop.ProcFsStat.TryReadProcessStatusInfo.cs b/src/libraries/Common/src/Interop/SunOS/procfs/Interop.ProcFsStat.TryReadProcessStatusInfo.cs index bbfa14b3f7b12b..2a71db0aa82c9c 100644 --- a/src/libraries/Common/src/Interop/SunOS/procfs/Interop.ProcFsStat.TryReadProcessStatusInfo.cs +++ b/src/libraries/Common/src/Interop/SunOS/procfs/Interop.ProcFsStat.TryReadProcessStatusInfo.cs @@ -5,7 +5,7 @@ internal static partial class Interop { - internal static partial class procfs + internal static partial class @procfs { /// /// Attempts to get status info for the specified process ID. diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs index 1a0114cca21895..f154020553e9ee 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 95b27abf158287..f43f81fb09c29b 100644 --- a/src/libraries/Common/src/Interop/Unix/libc/Interop.GetParentPid.cs +++ b/src/libraries/Common/src/Interop/Unix/libc/Interop.GetParentPid.cs @@ -5,9 +5,9 @@ internal static partial class Interop { - internal static partial class libc + 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 207cd17f3b538b..5524fd8266d6b3 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.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj b/src/libraries/Microsoft.Extensions.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj index 9918456a0cedae..b9faefd40f2f07 100644 --- a/src/libraries/Microsoft.Extensions.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj +++ b/src/libraries/Microsoft.Extensions.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj @@ -8,8 +8,6 @@ false true true - - $(NoWarn);CS8981 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 a71a29696a0073..6d2af4968b2b0e 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(); diff --git a/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs b/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs index 91e7f8c461c196..23bbdc5ca48bf2 100644 --- a/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs +++ b/src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs @@ -61,7 +61,7 @@ public unsafe struct ProcessEntry32W public static extern bool Process32NextW(IntPtr snapshot, ref ProcessEntry32W entry); } - static class libproc + static class @libproc { [DllImport(nameof(libproc))] private static extern int proc_listchildpids(int ppid, int[] buffer, int byteSize); From c40fcb28320ecc4a63ae62674cff25980bc7932e Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 7 Feb 2022 15:33:49 -0800 Subject: [PATCH 05/13] Fix build --- .../tests/TestAssets/NativeExports/Error.cs | 4 ++-- .../ConstructorTests.ParameterMatching.cs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) 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 6d2af4968b2b0e..cbbac4e31d2b36 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/Error.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/Error.cs @@ -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/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs b/src/libraries/System.Text.Json/tests/Common/ConstructorTests/ConstructorTests.ParameterMatching.cs index 66f1c3c912d10f..c1417fee5b2d71 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 @@ -1356,6 +1356,11 @@ public struct StructWithPropertyInit { public long A { get; set; } = 42; public long B { get; set; } + + public StructWithPropertyInit() + { + B = default; + } } [Fact] @@ -1371,6 +1376,11 @@ public struct StructWithFieldInit { public long A; public long B = 42; + + public StructWithFieldInit() + { + A = default; + } } [Fact] From 0b06bd9931e5a49622e47357c3aa4c4f38265538 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 9 Feb 2022 09:56:53 -0800 Subject: [PATCH 06/13] Import test_dependencies' nuget-generated props/targets since we don't generate them for each of the individual test projects. --- src/tests/Directory.Build.props | 1 + src/tests/Directory.Build.targets | 1 + 2 files changed, 2 insertions(+) diff --git a/src/tests/Directory.Build.props b/src/tests/Directory.Build.props index 0ae53ee940850f..a3e84fae4db3dd 100644 --- a/src/tests/Directory.Build.props +++ b/src/tests/Directory.Build.props @@ -195,4 +195,5 @@ + diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index 6eda7ef53f14d1..68690e579fa695 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -254,6 +254,7 @@ $(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\project.assets.json + true From cd57d2b122eb38d8a14a1f3765b692674bb5f510 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 9 Feb 2022 15:45:13 -0800 Subject: [PATCH 07/13] Unify roslyn version. --- eng/Versions.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 721a279c93b17e..78401bb71e5c21 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -52,9 +52,9 @@ 3.3.3 - 4.2.0-1.22070.6 - 4.2.0-1.22070.6 - 4.2.0-1.22070.6 + 4.2.0-2.22105.4 + 4.2.0-2.22105.4 + 4.2.0-2.22105.4 7.0.0-preview1.22067.1 4.2.0-2.22105.4 From 4a7b84d08a029bde17c3954930679eaac955eeaf Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 9 Feb 2022 15:46:44 -0800 Subject: [PATCH 08/13] Remove some extraneous escapes in comments --- .../src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs | 4 ++-- .../Common/src/Interop/OSX/Interop.libproc.cs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs b/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs index e9da6f99fa7e53..2d1861e4ee9c71 100644 --- a/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs +++ b/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.GetProcInfo.cs @@ -164,9 +164,9 @@ public unsafe struct @kinfo_proc public int ki_numthreads; /* XXXKSE number of threads in total */ public int ki_tid; /* XXXKSE thread id */ private fixed byte ki_pri[4]; /* process priority */ - public rusage ki_rusage; /* process @rusage statistics */ + public rusage ki_rusage; /* process rusage statistics */ /* XXX - most fields in ki_rusage_ch are not (yet) filled in */ - private rusage ki_rusage_ch; /* @rusage of children processes */ + private rusage ki_rusage_ch; /* rusage of children processes */ private void* ki_pcb; /* kernel virtual addr of pcb */ private void* ki_kstack; /* kernel virtual addr of stack */ private void* ki_udata; /* User convenience pointer */ diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs index 5543a994145ae2..929eb9acca871e 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs @@ -350,9 +350,9 @@ internal static unsafe string proc_pidpath(int pid) } /// - /// Gets the @rusage information for the process identified by the PID + /// Gets the rusage information for the process identified by the PID /// - /// The process to retrieve the @rusage for + /// The process to retrieve the rusage for /// Specifies the type of struct that is passed in to buffer. Should be RUSAGE_INFO_V3 to specify a rusage_info_v3 struct. /// A buffer to be filled with rusage_info data /// Returns 0 on success; on fail, -1 and errno is set with the error code @@ -363,9 +363,9 @@ private static unsafe partial int proc_pid_rusage( rusage_info_v3* buffer); /// - /// Gets the @rusage information for the process identified by the PID + /// Gets the rusage information for the process identified by the PID /// - /// The process to retrieve the @rusage for + /// The process to retrieve the rusage for /// On success, returns a struct containing info about the process; on /// failure or when the caller doesn't have permissions to the process, throws a Win32Exception /// @@ -379,7 +379,7 @@ internal static unsafe rusage_info_v3 proc_pid_rusage(int pid) rusage_info_v3 info = default; - // Get the PIDs @rusage info + // Get the PIDs rusage info int result = proc_pid_rusage(pid, RUSAGE_INFO_V3, &info); if (result < 0) { From ea30f83dd807c1d654294f2a9eecf30c761076e5 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 10 Feb 2022 10:28:20 -0800 Subject: [PATCH 09/13] Fix build failures other than the binary/text issue. --- .../ConstructorTests.ParameterMatching.cs | 10 ---------- .../GC/Features/HeapExpansion/bestfit-threaded.cs | 12 ++++++------ 2 files changed, 6 insertions(+), 16 deletions(-) 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 f5b9747274e8b0..59a05d7be91207 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 @@ -1357,11 +1357,6 @@ public struct StructWithPropertyInit public StructWithPropertyInit() { B = 0; } public long A { get; set; } = 42; public long B { get; set; } - - public StructWithPropertyInit() - { - B = default; - } } [Fact] @@ -1378,11 +1373,6 @@ public struct StructWithFieldInit public StructWithFieldInit() { A = 0; } public long A; public long B = 42; - - public StructWithFieldInit() - { - A = default; - } } [Fact] diff --git a/src/tests/GC/Features/HeapExpansion/bestfit-threaded.cs b/src/tests/GC/Features/HeapExpansion/bestfit-threaded.cs index 7125ad42b4f534..1317ee5361234d 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; From 1bb9514c5ae5fb6ccd207d413fee257c966a51c6 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 18 Feb 2022 15:40:59 -0800 Subject: [PATCH 10/13] Update compiler toolset to get dotnet/roslyn#59578 --- eng/Versions.props | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 71b1a8f3b7b9b4..378a830ca274b6 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -52,13 +52,16 @@ 3.3.3 - 4.2.0-2.22105.4 - 4.2.0-2.22105.4 - 4.2.0-2.22105.4 + 4.2.0-2.22118.4 + 4.2.0-2.22118.4 + 4.2.0-2.22118.4 7.0.0-preview1.22115.3 - 4.2.0-2.22105.4 - - 4.2.0-2.22105.4 + 4.2.0-2.22118.4 + + 4.2.0-2.22118.4 7.0.0-preview1.22107.2 2.0.0-alpha.1.21525.11 From bfb31159f869de2b5e0cea1c06a9ac96144d15a0 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 23 Feb 2022 14:23:48 -0800 Subject: [PATCH 11/13] Update Roslyn version again to get latest fix. --- eng/Versions.props | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 378a830ca274b6..a640894a07a72d 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -52,16 +52,16 @@ 3.3.3 - 4.2.0-2.22118.4 - 4.2.0-2.22118.4 - 4.2.0-2.22118.4 + 4.2.0-2.22123.2 + 4.2.0-2.22123.2 + 4.2.0-2.22123.2 7.0.0-preview1.22115.3 - 4.2.0-2.22118.4 + 4.2.0-2.22123.2 - 4.2.0-2.22118.4 + 4.2.0-2.22123.2 7.0.0-preview1.22107.2 2.0.0-alpha.1.21525.11 From b44c0ece74cd7c950325e3194c4e7f6d994c00b6 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 28 Feb 2022 10:23:35 -0800 Subject: [PATCH 12/13] PR feedback and update Roslyn again now that Chris has actually put in a fix that will work --- eng/Versions.props | 14 ++++++-------- .../Common/src/Interop/OSX/Interop.Libraries.cs | 4 ++-- .../Common/src/Interop/Unix/Interop.Libraries.cs | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index b28e1f3f03de3f..b6f5df9dbb3260 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -19,7 +19,6 @@ true false false - true $(AssemblyVersion) true @@ -34,17 +33,16 @@ 3.3.3 - 4.2.0-2.22123.2 - 4.2.0-2.22123.2 - 4.2.0-2.22123.2 + 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.22123.2 + 4.2.0-2.22128.1 - 4.2.0-2.22123.2 - 7.0.0-preview1.22107.2 + 4.2.0-2.22128.1 2.0.0-alpha.1.21525.11 diff --git a/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs b/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs index 1a08cfb46da04b..36cdea9e1bd9a4 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs @@ -8,8 +8,8 @@ internal static partial class Libraries internal const string CoreFoundationLibrary = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"; internal const string CoreServicesLibrary = "/System/Library/Frameworks/CoreServices.framework/CoreServices"; internal const string CFNetworkLibrary = "/System/Library/Frameworks/CFNetwork.framework/CFNetwork"; - internal const string @libobjc = "/usr/lib/libobjc.dylib"; - internal const string @libproc = "/usr/lib/libproc.dylib"; + internal const string libobjc = "/usr/lib/libobjc.dylib"; + internal const string libproc = "/usr/lib/libproc.dylib"; internal const string Odbc32 = "libodbc.2.dylib"; internal const string OpenLdap = "libldap.dylib"; internal const string SystemConfigurationLibrary = "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration"; diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs index f154020553e9ee..7ec51da64f2541 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"; From cc60244ef175b5862ba76e5d7ceac6f8035b0494 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 2 Mar 2022 13:10:19 -0800 Subject: [PATCH 13/13] Disable capitalization warning in the src/tests tree --- src/tests/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/Directory.Build.props b/src/tests/Directory.Build.props index a3e84fae4db3dd..af65022e4d4f54 100644 --- a/src/tests/Directory.Build.props +++ b/src/tests/Directory.Build.props @@ -122,7 +122,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