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

Make host outputs public #74750

Merged
merged 16 commits into from
Aug 27, 2024
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;
chsienki marked this conversation as resolved.
Show resolved Hide resolved
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
Expand Down Expand Up @@ -3051,12 +3052,17 @@
});
}

#pragma warning disable RSEXPERIMENTAL004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

[Theory]
[CombinatorialData]
[InlineData(IncrementalGeneratorOutputKind.Source | IncrementalGeneratorOutputKind.Implementation)]
[InlineData(IncrementalGeneratorOutputKind.Source | IncrementalGeneratorOutputKind.PostInit)]
[InlineData(IncrementalGeneratorOutputKind.Implementation | IncrementalGeneratorOutputKind.PostInit)]
[InlineData(IncrementalGeneratorOutputKind.Source | IncrementalGeneratorOutputKind.Host)]
[InlineData(IncrementalGeneratorOutputKind.Implementation | IncrementalGeneratorOutputKind.Host)]
[InlineData(IncrementalGeneratorOutputKind.Source | IncrementalGeneratorOutputKind.Implementation | IncrementalGeneratorOutputKind.PostInit)]
[InlineData(IncrementalGeneratorOutputKind.Source | IncrementalGeneratorOutputKind.Implementation | IncrementalGeneratorOutputKind.PostInit | IncrementalGeneratorOutputKind.Host)]
public void Generator_Output_Kinds_Can_Be_Disabled(IncrementalGeneratorOutputKind disabledOutput)
{
var source = @"
Expand All @@ -3072,6 +3078,7 @@
ctx.RegisterPostInitializationOutput((context) => context.AddSource("PostInit", ""));
ctx.RegisterSourceOutput(ctx.CompilationProvider, (context, ct) => context.AddSource("Source", ""));
ctx.RegisterImplementationSourceOutput(ctx.CompilationProvider, (context, ct) => context.AddSource("Implementation", ""));
ctx.RegisterHostOutput(ctx.CompilationOptionsProvider, (context, ct) => context.AddOutput("Host", ""));
});

GeneratorDriver driver = CSharpGeneratorDriver.Create(new[] { generator.AsSourceGenerator() }, driverOptions: new GeneratorDriverOptions(disabledOutput), parseOptions: parseOptions);
Expand All @@ -3085,22 +3092,38 @@
// NOTE: adding new output types will cause this test to fail. Update above as needed.
foreach (IncrementalGeneratorOutputKind kind in Enum.GetValues(typeof(IncrementalGeneratorOutputKind)))
{
if (kind == IncrementalGeneratorOutputKind.None || kind == IncrementalGeneratorOutputKind.Host)
if (kind == IncrementalGeneratorOutputKind.None)
continue;

if (disabledOutput.HasFlag((IncrementalGeneratorOutputKind)kind))
{
Assert.DoesNotContain(result.Results[0].GeneratedSources, isTextForKind);
if (kind == IncrementalGeneratorOutputKind.Host)
{
Assert.DoesNotContain(result.Results[0].HostOutputs, o => o.Key == "Host");
}
else
{
Assert.DoesNotContain(result.Results[0].GeneratedSources, isTextForKind);
}
}
else
{
Assert.Contains(result.Results[0].GeneratedSources, isTextForKind);
if (kind == IncrementalGeneratorOutputKind.Host)
{
Assert.Contains(result.Results[0].HostOutputs, o => o.Key == "Host");
}
else
{
Assert.Contains(result.Results[0].GeneratedSources, isTextForKind);
}
}

bool isTextForKind(GeneratedSourceResult s) => s.HintName == Enum.GetName(typeof(IncrementalGeneratorOutputKind), kind) + ".cs";
}
}

#pragma warning restore RSEXPERIMENTAL004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

[Fact]
public void IncrementalGeneratorInputSourcesHaveNames()
{
Expand Down Expand Up @@ -4589,7 +4612,7 @@
var exception = Assert.IsType<InvalidOperationException>(result.Exception);
Assert.Equal("failed", exception.Message);
}

Check failure on line 4615 in src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs#L4615

src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs(4615,1): error IDE2000: (NETCORE_ENGINEERING_TELEMETRY=Build) Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

Check failure on line 4615 in src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs

View check run for this annotation

Azure Pipelines / roslyn-CI

src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs#L4615

src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs(4615,1): error IDE2000: (NETCORE_ENGINEERING_TELEMETRY=Build) Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

#pragma warning restore RSEXPERIMENTAL004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}
Expand Down
1 change: 0 additions & 1 deletion src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Microsoft.CodeAnalysis.ITypeParameterSymbol.AllowsRefLikeType.get -> bool
Microsoft.CodeAnalysis.RuntimeCapability.ByRefLikeGenerics = 8 -> Microsoft.CodeAnalysis.RuntimeCapability
static Microsoft.CodeAnalysis.GeneratorExtensions.AsIncrementalGenerator(this Microsoft.CodeAnalysis.ISourceGenerator! sourceGenerator) -> Microsoft.CodeAnalysis.IIncrementalGenerator!
static Microsoft.CodeAnalysis.GeneratorExtensions.GetGeneratorType(this Microsoft.CodeAnalysis.IIncrementalGenerator! generator) -> System.Type!
[RSEXPERIMENTAL004]Microsoft.CodeAnalysis.GeneratorRunResult.HostOutputs.get -> System.Collections.Immutable.ImmutableDictionary<string!, object!>!
[RSEXPERIMENTAL004]Microsoft.CodeAnalysis.HostOutputProductionContext
[RSEXPERIMENTAL004]Microsoft.CodeAnalysis.HostOutputProductionContext.AddOutput(string! name, object! value) -> void
[RSEXPERIMENTAL004]Microsoft.CodeAnalysis.HostOutputProductionContext.CancellationToken.get -> System.Threading.CancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10666,10 +10666,12 @@ End Class")
Dim hostOutputRan As Boolean = False
Dim sourceOutputRan As Boolean = False
Dim generator = New PipelineCallbackGenerator(Sub(ctx)
#Disable Warning RSEXPERIMENTAL004
ctx.RegisterHostOutput(ctx.CompilationProvider, Sub(hostCtx, value)
hostOutputRan = True
hostCtx.AddOutput("output", "value")
End Sub)
#Enable Warning RSEXPERIMENTAL004
ctx.RegisterSourceOutput(ctx.CompilationProvider, Sub(spc, po)
sourceOutputRan = True
spc.AddSource("output.vb", "'value")
Expand Down
Loading