Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ src/Features/**/PublicAPI.Unshipped.txt @dotnet/roslyn-api-owners
src/EditorFeatures/**/PublicAPI.Unshipped.txt @dotnet/roslyn-api-owners

src/Tools/ExternalAccess/OmniSharp*/ @333fred @joerobich
src/Tools/ExternalAccess/RazorCompiler*/ @dotnet/roslyn-compiler
10 changes: 10 additions & 0 deletions Compilers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.CSha
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestDiscoveryWorker", "src\Tools\TestDiscoveryWorker\TestDiscoveryWorker.csproj", "{FB617466-C4A1-4289-A512-A06182FC779F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ExternalAccess", "ExternalAccess", "{67B6F694-CA27-4CDE-B1E5-E2B4105A2420}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler", "src\Tools\ExternalAccess\RazorCompiler\Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.csproj", "{8450EF6B-28BB-4F4D-B005-CD734B476800}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -423,6 +427,10 @@ Global
{FB617466-C4A1-4289-A512-A06182FC779F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB617466-C4A1-4289-A512-A06182FC779F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB617466-C4A1-4289-A512-A06182FC779F}.Release|Any CPU.Build.0 = Release|Any CPU
{8450EF6B-28BB-4F4D-B005-CD734B476800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8450EF6B-28BB-4F4D-B005-CD734B476800}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8450EF6B-28BB-4F4D-B005-CD734B476800}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8450EF6B-28BB-4F4D-B005-CD734B476800}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -499,6 +507,8 @@ Global
{48C93F90-8776-4847-96D8-127B896D6C80} = {C65C6143-BED3-46E6-869E-9F0BE6E84C37}
{F3D9264A-7CAE-4265-AF48-0C863301F51E} = {32A48625-F0AD-419D-828B-A50BDABA38EA}
{FB617466-C4A1-4289-A512-A06182FC779F} = {FD0FAF5F-1DED-485C-99FA-84B97F3A8EEC}
{67B6F694-CA27-4CDE-B1E5-E2B4105A2420} = {FD0FAF5F-1DED-485C-99FA-84B97F3A8EEC}
{8450EF6B-28BB-4F4D-B005-CD734B476800} = {67B6F694-CA27-4CDE-B1E5-E2B4105A2420}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6F599E08-A9EA-4FAA-897F-5D824B0210E6}
Expand Down
2 changes: 2 additions & 0 deletions Compilers.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"src\\Test\\PdbUtilities\\Roslyn.Test.PdbUtilities.csproj",
"src\\Compilers\\Test\\Core\\Microsoft.CodeAnalysis.Test.Utilities.csproj",
"src\\Tools\\AnalyzerRunner\\AnalyzerRunner.csproj",
"src\\Tools\\ExternalAccess\\RazorCompiler\\Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.csproj",
"src\\Tools\\ExternalAccess\\RazorCompilerTest\\Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.UnitTests.csproj",
"src\\Tools\\Source\\CompilerGeneratorTools\\Source\\BoundTreeGenerator\\CompilersBoundTreeGenerator.csproj",
"src\\Tools\\Source\\CompilerGeneratorTools\\Source\\CSharpErrorFactsGenerator\\CSharpErrorFactsGenerator.csproj",
"src\\Tools\\Source\\CompilerGeneratorTools\\Source\\CSharpSyntaxGenerator\\CSharpSyntaxGenerator.csproj",
Expand Down
14 changes: 14 additions & 0 deletions Roslyn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Microsoft.CodeAnalysis.Visu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestDiscoveryWorker", "src\Tools\TestDiscoveryWorker\TestDiscoveryWorker.csproj", "{8BC50AFF-1EBF-4E9A-AEBB-04F387AA800F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler", "src\Tools\ExternalAccess\RazorCompiler\Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.csproj", "{E5E0BF73-95F7-4BC3-8443-2336C4FF4297}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.UnitTests", "src\Tools\ExternalAccess\RazorCompilerTest\Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.UnitTests.csproj", "{828FD0DB-9927-42AC-B6C2-D1514965D6C3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1283,6 +1287,14 @@ Global
{8BC50AFF-1EBF-4E9A-AEBB-04F387AA800F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BC50AFF-1EBF-4E9A-AEBB-04F387AA800F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BC50AFF-1EBF-4E9A-AEBB-04F387AA800F}.Release|Any CPU.Build.0 = Release|Any CPU
{E5E0BF73-95F7-4BC3-8443-2336C4FF4297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5E0BF73-95F7-4BC3-8443-2336C4FF4297}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5E0BF73-95F7-4BC3-8443-2336C4FF4297}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5E0BF73-95F7-4BC3-8443-2336C4FF4297}.Release|Any CPU.Build.0 = Release|Any CPU
{828FD0DB-9927-42AC-B6C2-D1514965D6C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{828FD0DB-9927-42AC-B6C2-D1514965D6C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{828FD0DB-9927-42AC-B6C2-D1514965D6C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{828FD0DB-9927-42AC-B6C2-D1514965D6C3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1522,6 +1534,8 @@ Global
{4C1B26EE-465B-4B30-9E50-0285EF7AB035} = {3E5FE3DB-45F7-4D83-9097-8F05D3B3AEC6}
{F836BDB1-4EC7-4F4C-B2E9-BCD721C9E650} = {3E5FE3DB-45F7-4D83-9097-8F05D3B3AEC6}
{8BC50AFF-1EBF-4E9A-AEBB-04F387AA800F} = {FD0FAF5F-1DED-485C-99FA-84B97F3A8EEC}
{E5E0BF73-95F7-4BC3-8443-2336C4FF4297} = {8977A560-45C2-4EC2-A849-97335B382C74}
{828FD0DB-9927-42AC-B6C2-D1514965D6C3} = {8977A560-45C2-4EC2-A849-97335B382C74}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {604E6B91-7BC0-4126-AE07-D4D2FEFC3D29}
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/Core/Portable/Microsoft.CodeAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.ExpressionCompiler.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator.ExpressionCompiler.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.Utilities" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" />
<InternalsVisibleTo Include="InteractiveHost.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Scripting.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Scripting.Desktop.UnitTests" />
Expand Down
11 changes: 7 additions & 4 deletions src/Compilers/Core/Portable/SourceGeneration/GeneratorDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace Microsoft.CodeAnalysis
/// </remarks>
public abstract class GeneratorDriver
{
internal const IncrementalGeneratorOutputKind HostKind = (IncrementalGeneratorOutputKind)0b100000; // several steps higher than IncrementalGeneratorOutputKind.Implementation

internal readonly GeneratorDriverState _state;

internal GeneratorDriver(GeneratorDriverState state)
Expand Down Expand Up @@ -163,7 +165,8 @@ public GeneratorDriverRunResult GetRunResult()
generatedSources: getGeneratorSources(generatorState),
elapsedTime: generatorState.ElapsedTime,
namedSteps: generatorState.ExecutedSteps,
outputSteps: generatorState.OutputSteps));
outputSteps: generatorState.OutputSteps,
hostOutputs: generatorState.HostOutputs));
return new GeneratorDriverRunResult(results, _state.RunTime);

static ImmutableArray<GeneratedSourceResult> getGeneratorSources(GeneratorState generatorState)
Expand Down Expand Up @@ -292,11 +295,11 @@ internal GeneratorDriverState RunGeneratorsCore(Compilation compilation, Diagnos
try
{
// We do not support incremental step tracking for v1 generators, as the pipeline is implicitly defined.
var context = UpdateOutputs(generatorState.OutputNodes, IncrementalGeneratorOutputKind.Source | IncrementalGeneratorOutputKind.Implementation, new GeneratorRunStateTable.Builder(state.TrackIncrementalSteps), cancellationToken, driverStateBuilder);
(var sources, var generatorDiagnostics, var generatorRunStateTable) = context.ToImmutableAndFree();
var context = UpdateOutputs(generatorState.OutputNodes, IncrementalGeneratorOutputKind.Source | IncrementalGeneratorOutputKind.Implementation | HostKind, new GeneratorRunStateTable.Builder(state.TrackIncrementalSteps), cancellationToken, driverStateBuilder);
(var sources, var generatorDiagnostics, var generatorRunStateTable, var hostOutputs) = context.ToImmutableAndFree();
generatorDiagnostics = FilterDiagnostics(compilation, generatorDiagnostics, driverDiagnostics: diagnosticsBag, cancellationToken);

stateBuilder[i] = generatorState.WithResults(ParseAdditionalSources(state.Generators[i], sources, cancellationToken), generatorDiagnostics, generatorRunStateTable.ExecutedSteps, generatorRunStateTable.OutputSteps, generatorTimer.Elapsed);
stateBuilder[i] = generatorState.WithResults(ParseAdditionalSources(state.Generators[i], sources, cancellationToken), generatorDiagnostics, generatorRunStateTable.ExecutedSteps, generatorRunStateTable.OutputSteps, hostOutputs, generatorTimer.Elapsed);
}
catch (UserFunctionException ufe)
{
Expand Down
31 changes: 29 additions & 2 deletions src/Compilers/Core/Portable/SourceGeneration/GeneratorState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics;

namespace Microsoft.CodeAnalysis
{
/// <summary>
Expand All @@ -20,18 +21,38 @@ internal readonly struct GeneratorState
ImmutableArray<Diagnostic>.Empty,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>>.Empty,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>>.Empty,
ImmutableArray<(string, string)>.Empty,
exception: null,
elapsedTime: TimeSpan.Zero);

/// <summary>
/// Creates a new generator state that contains information, constant trees and an execution pipeline
/// </summary>
public GeneratorState(ImmutableArray<GeneratedSyntaxTree> postInitTrees, ImmutableArray<SyntaxInputNode> inputNodes, ImmutableArray<IIncrementalGeneratorOutputNode> outputNodes)
: this(postInitTrees, inputNodes, outputNodes, ImmutableArray<GeneratedSyntaxTree>.Empty, ImmutableArray<Diagnostic>.Empty, ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>>.Empty, ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>>.Empty, exception: null, elapsedTime: TimeSpan.Zero)
: this(postInitTrees,
inputNodes,
outputNodes,
ImmutableArray<GeneratedSyntaxTree>.Empty,
ImmutableArray<Diagnostic>.Empty,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>>.Empty,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>>.Empty,
ImmutableArray<(string, string)>.Empty,
exception: null,
elapsedTime: TimeSpan.Zero)
{
}

private GeneratorState(ImmutableArray<GeneratedSyntaxTree> postInitTrees, ImmutableArray<SyntaxInputNode> inputNodes, ImmutableArray<IIncrementalGeneratorOutputNode> outputNodes, ImmutableArray<GeneratedSyntaxTree> generatedTrees, ImmutableArray<Diagnostic> diagnostics, ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> executedSteps, ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> outputSteps, Exception? exception, TimeSpan elapsedTime)
private GeneratorState(
ImmutableArray<GeneratedSyntaxTree> postInitTrees,
ImmutableArray<SyntaxInputNode> inputNodes,
ImmutableArray<IIncrementalGeneratorOutputNode> outputNodes,
ImmutableArray<GeneratedSyntaxTree> generatedTrees,
ImmutableArray<Diagnostic> diagnostics,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> executedSteps,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> outputSteps,
ImmutableArray<(string Key, string Value)> hostOutputs,
Exception? exception,
TimeSpan elapsedTime)
{
this.Initialized = true;
this.PostInitTrees = postInitTrees;
Expand All @@ -41,6 +62,7 @@ private GeneratorState(ImmutableArray<GeneratedSyntaxTree> postInitTrees, Immuta
this.Diagnostics = diagnostics;
this.ExecutedSteps = executedSteps;
this.OutputSteps = outputSteps;
this.HostOutputs = hostOutputs;
this.Exception = exception;
this.ElapsedTime = elapsedTime;
}
Expand All @@ -49,6 +71,7 @@ public GeneratorState WithResults(ImmutableArray<GeneratedSyntaxTree> generatedT
ImmutableArray<Diagnostic> diagnostics,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> executedSteps,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> outputSteps,
ImmutableArray<(string Key, string Value)> hostOutputs,
TimeSpan elapsedTime)
{
return new GeneratorState(this.PostInitTrees,
Expand All @@ -58,6 +81,7 @@ public GeneratorState WithResults(ImmutableArray<GeneratedSyntaxTree> generatedT
diagnostics,
executedSteps,
outputSteps,
hostOutputs,
exception: null,
elapsedTime);
}
Expand All @@ -71,6 +95,7 @@ public GeneratorState WithError(Exception exception, Diagnostic error, TimeSpan
ImmutableArray.Create(error),
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>>.Empty,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>>.Empty,
ImmutableArray<(string, string)>.Empty,
exception,
elapsedTime);
}
Expand All @@ -94,5 +119,7 @@ public GeneratorState WithError(Exception exception, Diagnostic error, TimeSpan
internal ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> ExecutedSteps { get; }

internal ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> OutputSteps { get; }

internal ImmutableArray<(string Key, string Value)> HostOutputs { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -166,16 +167,19 @@ internal readonly struct IncrementalExecutionContext

internal readonly GeneratorRunStateTable.Builder GeneratorRunStateBuilder;

internal readonly ArrayBuilder<(string Key, string Value)> HostOutputBuilder;

public IncrementalExecutionContext(DriverStateTable.Builder? tableBuilder, GeneratorRunStateTable.Builder generatorRunStateBuilder, AdditionalSourcesCollection sources)
{
TableBuilder = tableBuilder;
GeneratorRunStateBuilder = generatorRunStateBuilder;
Sources = sources;
HostOutputBuilder = ArrayBuilder<(string, string)>.GetInstance();
Diagnostics = DiagnosticBag.GetInstance();
}

internal (ImmutableArray<GeneratedSourceText> sources, ImmutableArray<Diagnostic> diagnostics, GeneratorRunStateTable executedSteps) ToImmutableAndFree()
=> (Sources.ToImmutableAndFree(), Diagnostics.ToReadOnlyAndFree(), GeneratorRunStateBuilder.ToImmutableAndFree());
internal (ImmutableArray<GeneratedSourceText> sources, ImmutableArray<Diagnostic> diagnostics, GeneratorRunStateTable executedSteps, ImmutableArray<(string Key, string Value)> hostOutputs) ToImmutableAndFree()
=> (Sources.ToImmutableAndFree(), Diagnostics.ToReadOnlyAndFree(), GeneratorRunStateBuilder.ToImmutableAndFree(), HostOutputBuilder.ToImmutableAndFree());

internal void Free()
{
Expand Down
13 changes: 12 additions & 1 deletion src/Compilers/Core/Portable/SourceGeneration/RunResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ public ImmutableArray<SyntaxTree> GeneratedTrees
/// </summary>
public readonly struct GeneratorRunResult
{
internal GeneratorRunResult(ISourceGenerator generator, ImmutableArray<GeneratedSourceResult> generatedSources, ImmutableArray<Diagnostic> diagnostics, ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> namedSteps, ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> outputSteps, Exception? exception, TimeSpan elapsedTime)
internal GeneratorRunResult(
ISourceGenerator generator,
ImmutableArray<GeneratedSourceResult> generatedSources,
ImmutableArray<Diagnostic> diagnostics,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> namedSteps,
ImmutableDictionary<string, ImmutableArray<IncrementalGeneratorRunStep>> outputSteps,
ImmutableArray<(string Key, string Value)> hostOutputs,
Exception? exception,
TimeSpan elapsedTime)
{
Debug.Assert(exception is null || (generatedSources.IsEmpty && diagnostics.Length == 1));

Expand All @@ -86,6 +94,7 @@ internal GeneratorRunResult(ISourceGenerator generator, ImmutableArray<Generated
this.Diagnostics = diagnostics;
this.TrackedSteps = namedSteps;
this.TrackedOutputSteps = outputSteps;
this.HostOutputs = hostOutputs;
this.Exception = exception;
this.ElapsedTime = elapsedTime;
}
Expand All @@ -109,6 +118,8 @@ internal GeneratorRunResult(ISourceGenerator generator, ImmutableArray<Generated
/// </remarks>
public ImmutableArray<Diagnostic> Diagnostics { get; }

internal ImmutableArray<(string Key, string Value)> HostOutputs { get; }

/// <summary>
/// An <see cref="System.Exception"/> instance that was thrown by the generator, or <c>null</c> if the generator completed without error.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.FSharp.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Rebuild.UnitTests" />
<InternalsVisibleTo Include="Roslyn.Test.PdbUtilities" />
<InternalsVisibleTo Include="Roslyn.VisualStudio.Next.UnitTests" />
Expand Down
Loading