Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 18 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
544fa8a
Update out-of-band generators to explicitly reference pinned versions…
jkoritzinsky Jan 15, 2022
1e4f98f
Update Roslyn and update the DllImportGenerator incremental generatio…
jkoritzinsky Jan 19, 2022
1f5ea02
Bump Roslyn to get the bugfix and finish updating the incremental gen…
jkoritzinsky Jan 21, 2022
cbe6dc2
Merge branch 'main' into update-roslyn
jkoritzinsky Jan 21, 2022
4e491b2
Merge branch 'main' of github.com:dotnet/runtime into update-roslyn
jkoritzinsky Feb 4, 2022
8cdb7d0
Escape per CS8981 throughout the repo.
jkoritzinsky Feb 4, 2022
c40fcb2
Fix build
jkoritzinsky Feb 7, 2022
0b06bd9
Import test_dependencies' nuget-generated props/targets since we don'…
jkoritzinsky Feb 9, 2022
bfc324a
Merge branch 'main' of github.com:dotnet/runtime into update-roslyn
jkoritzinsky Feb 9, 2022
cd57d2b
Unify roslyn version.
jkoritzinsky Feb 9, 2022
4a7b84d
Remove some extraneous escapes in comments
jkoritzinsky Feb 9, 2022
ea30f83
Fix build failures other than the binary/text issue.
jkoritzinsky Feb 10, 2022
979ca2f
Merge branch 'main' of github.com:dotnet/runtime into update-roslyn
jkoritzinsky Feb 18, 2022
1bb9514
Update compiler toolset to get dotnet/roslyn#59578
jkoritzinsky Feb 18, 2022
bfb3115
Update Roslyn version again to get latest fix.
jkoritzinsky Feb 23, 2022
100f65c
Merge branch 'main' into update-roslyn
jkoritzinsky Feb 24, 2022
b44c0ec
PR feedback and update Roslyn again now that Chris has actually put i…
jkoritzinsky Feb 28, 2022
cc60244
Disable capitalization warning in the src/tests tree
jkoritzinsky Mar 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eerhardt does this need to be a change that makes our OOB source generators cross-compile? What's going to happen when someone now installs the JSON or logging source generator package on a 6.0 GA SDK/Visual Studio 2022?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically updated our in-box analyzers that we have already shipped to be pinned to the RTM versions of the Roslyn API surface they built against when they shipped. The JSON and Logging generators are pinned to 3.11 and 4.0. They don't build against these new versions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we guarantee that all net7.0 consumers will have this version of roslyn? I know we have some surprising combinations that are sometimes supported due to the roslyn shipping in VS at a different cadence.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the time this commit ships, we will have at least this version of Roslyn in the product. By the time .NET 7 ships, all places where .NET 7 is supported will also have a version of Roslyn that is at least this version (likely the release version of 4.2.0)

<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 -->
Expand Down
1 change: 1 addition & 0 deletions eng/formatting/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
1 change: 0 additions & 1 deletion src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
2 changes: 1 addition & 1 deletion src/libraries/Common/src/Interop/Unix/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() :
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RoslynApiVersion>$(MicrosoftCodeAnalysisCSharpWorkspacesVersion_3_11)</RoslynApiVersion>
<RoslynApiVersion>$(MicrosoftCodeAnalysisVersion_3_11)</RoslynApiVersion>
<IsHighAotMemoryUsageTest>true</IsHighAotMemoryUsageTest>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,7 +103,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)
Expand All @@ -143,34 +126,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)
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
.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/>");
Expand All @@ -182,12 +155,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);
Expand Down Expand Up @@ -472,7 +445,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)
Expand Down Expand Up @@ -529,7 +502,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,
Expand Down
Loading