未验证 提交 1e529bcb 编写于 作者: J Jeremy Koritzinsky 提交者: GitHub

Update Roslyn and use new step tracking API in incremental tests. (#63978)

上级 1d602463
......@@ -22,20 +22,27 @@
<LastReleasedStableAssemblyVersion>$(AssemblyVersion)</LastReleasedStableAssemblyVersion>
<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
</PropertyGroup>
<!--
For source generator support we need to target multiple versions of Rolsyn in order to be able to run on older versions of Roslyn.
We pin these versions as we need to match them exactly for any scenarios that run Roslyn on .NET Framework, like Visual Studio.
-->
<PropertyGroup>
<!-- For source generator support we need to target multiple versions of Rolsyn in order to be able to run on older versions of Roslyn -->
<MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11>3.11.0</MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11>
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.0.1</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
<MicrosoftCodeAnalysisVersion>4.0.1</MicrosoftCodeAnalysisVersion>
<MicrosoftCodeAnalysisVersion_3_11>3.11.0</MicrosoftCodeAnalysisVersion_3_11>
<MicrosoftCodeAnalysisVersion_4_0>4.0.1</MicrosoftCodeAnalysisVersion_4_0>
</PropertyGroup>
<PropertyGroup>
<!-- Code analysis dependencies -->
<MicrosoftCodeAnalysisAnalyzersVersion>3.3.2</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>4.0.1</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
<MicrosoftCodeAnalysisCSharpVersion>4.0.1</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisAnalyzersVersion>3.3.3</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>4.2.0-2.22128.1</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>4.2.0-2.22128.1</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
<MicrosoftCodeAnalysisCSharpVersion>4.2.0-2.22128.1</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>7.0.0-preview1.22119.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
<!-- TODO: Remove pinned compiler version once arcade supplies runtime with a compiler capable of handling !! -->
<MicrosoftNetCompilersToolsetVersion>4.2.0-2.22105.4</MicrosoftNetCompilersToolsetVersion>
<MicrosoftCodeAnalysisVersion>4.2.0-2.22128.1</MicrosoftCodeAnalysisVersion>
<!--
TODO: Remove pinned compiler version once arcade supplies runtime with a compiler capable of handling !!
and has https://github.com/dotnet/roslyn/pull/59776
-->
<MicrosoftNetCompilersToolsetVersion>4.2.0-2.22128.1</MicrosoftNetCompilersToolsetVersion>
<!-- SDK dependencies -->
<MicrosoftDotNetCompatibilityVersion>2.0.0-alpha.1.21525.11</MicrosoftDotNetCompatibilityVersion>
<!-- Arcade dependencies -->
......
......@@ -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 -
......
......@@ -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";
}
}
......@@ -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";
......
......@@ -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();
}
}
......@@ -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();
......
......@@ -2,7 +2,7 @@
<PropertyGroup>
<AnalyzerRoslynVersion>3.11</AnalyzerRoslynVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_3_11)</RoslynApiVersion>
</PropertyGroup>
<Import Project="Microsoft.Extensions.Logging.Generators.targets" />
......
......@@ -2,7 +2,7 @@
<PropertyGroup>
<AnalyzerRoslynVersion>4.0</AnalyzerRoslynVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_4_0)</RoslynApiVersion>
<DefineConstants>$(DefineConstants);ROSLYN4_0_OR_GREATER</DefineConstants>
</PropertyGroup>
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_3_11)</RoslynApiVersion>
<IsHighAotMemoryUsageTest>true</IsHighAotMemoryUsageTest>
</PropertyGroup>
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_4_0)</RoslynApiVersion>
<DefineConstants>$(DefineConstants);ROSLYN4_0_OR_GREATER</DefineConstants>
<IsHighAotMemoryUsageTest>true</IsHighAotMemoryUsageTest>
<EmccLinkOptimizationFlag Condition="'$(ContinuousIntegrationBuild)' == 'true'">-O1</EmccLinkOptimizationFlag>
......
......@@ -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<ExecutedStepInfo> _executedSteps = new();
public IEnumerable<ExecutedStepInfo> 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);
}
/// <summary>
/// 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.
/// </summary>
public IncrementalityTracker? IncrementalTracker { get; set; }
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var attributedMethods = context.SyntaxProvider
......@@ -128,7 +111,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
});
IncrementalValueProvider<DllImportGeneratorOptions> stubOptions = context.AnalyzerConfigOptionsProvider
.Select((options, ct) => new DllImportGeneratorOptions(options.GlobalOptions));
.Select(static (options, ct) => new DllImportGeneratorOptions(options.GlobalOptions));
IncrementalValueProvider<StubEnvironment> 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("// <auto-generated/>");
......@@ -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<Diagnostic>) GenerateSource(
private static (MemberDeclarationSyntax, ImmutableArray<Diagnostic>) 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,
......
......@@ -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<int>()}}}";
......@@ -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<bool>(), 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<int>();
Compilation comp1 = await TestUtils.CreateCompilation(new string[] { CodeSnippets.BasicParametersAndModifiers<int>(), CodeSnippets.BasicParametersAndModifiers<bool>() });
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<ulong>(), 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<bool>();
......@@ -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<bool>(System.Runtime.InteropServices.UnmanagedType.Bool))!),
SyntaxFactory.ParseCompilationUnit(
CodeSnippets.MarshalAsParametersAndModifiers<bool>(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));
});
}
}
......
......@@ -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
......
......@@ -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
{
......
......@@ -2,7 +2,7 @@
<PropertyGroup>
<AnalyzerRoslynVersion>3.11</AnalyzerRoslynVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_3_11)</RoslynApiVersion>
</PropertyGroup>
<Import Project="System.Text.Json.SourceGeneration.targets" />
......@@ -11,4 +11,4 @@
<Compile Include="JsonSourceGenerator.Roslyn3.11.cs" />
</ItemGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -3,7 +3,7 @@
<PropertyGroup>
<IsNETCoreAppAnalyzer>true</IsNETCoreAppAnalyzer>
<AnalyzerRoslynVersion>4.0</AnalyzerRoslynVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_4_0)</RoslynApiVersion>
<DefineConstants>$(DefineConstants);ROSLYN4_0_OR_GREATER</DefineConstants>
</PropertyGroup>
......
......@@ -1340,12 +1340,12 @@ public void StructWithPropertyInit_OverrideInitedProperty()
var obj = JsonSerializer.Deserialize<StructWithPropertyInit>(json);
Assert.Equal(43, obj.A);
Assert.Equal(0, obj.B);
json = @"{""A"":0,""B"":44}";
obj = JsonSerializer.Deserialize<StructWithPropertyInit>(json);
Assert.Equal(0, obj.A);
Assert.Equal(44, obj.B);
json = @"{""B"":45}";
obj = JsonSerializer.Deserialize<StructWithPropertyInit>(json);
Assert.Equal(42, obj.A); // JSON doesn't set A property so it's expected to be 42
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_3_11)</RoslynApiVersion>
<IsHighAotMemoryUsageTest>true</IsHighAotMemoryUsageTest>
</PropertyGroup>
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_4_0)</RoslynApiVersion>
<DefineConstants>$(DefineConstants);ROSLYN4_0_OR_GREATER</DefineConstants>
<IsHighAotMemoryUsageTest>true</IsHighAotMemoryUsageTest>
</PropertyGroup>
......
......@@ -123,7 +123,7 @@
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<!-- Disable some C# warnings for the tests. -->
<NoWarn>78,162,164,168,169,219,251,252,414,429,618,642,649,652,659,675,1691,1717,1718,3001,3002,3003,3005,3008</NoWarn>
<NoWarn>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</NoWarn>
<RunAnalyzers>false</RunAnalyzers>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SkipSigning Condition="'$(CrossGen)' == 'true'">true</SkipSigning>
......@@ -196,4 +196,5 @@
</PropertyGroup>
<Import Project="$(RepositoryEngineeringDir)testing\tests.props" Condition="'$(IsTestsCommonProject)' != 'true'" />
<Import Project="$(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\test_dependencies.*.props" Condition="'$(IsTestsCommonProject)' != 'true'" />
</Project>
......@@ -278,7 +278,9 @@
<PropertyGroup>
<ProjectAssetsFile>$(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\project.assets.json</ProjectAssetsFile>
</PropertyGroup>
<Import Project="$(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\test_dependencies.*.targets" />
<PropertyGroup>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册