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

Mark ISourceGenerator as obsolete for implementation #75223

Merged
merged 6 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions docs/features/incremental-generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Summary

Incremental generators are a new API that exists alongside
[source generators](source-generators.md) to allow users to specify generation
Incremental generators are a new API that replaces
[v1 source generators](source-generators.md) to allow users to specify generation
strategies that can be applied in a high performance way by the hosting layer.

### High Level Design Goals
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Interface, AllowMultiple = false)]
internal sealed class ImplementationObsoleteAttribute(string url) : Attribute
{
public string Url { get; } = url;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
Debug.Assert(_sourceExtension != DummySourceExtension);

GeneratorInitializationContext generatorInitContext = new GeneratorInitializationContext(CancellationToken.None);
#pragma warning disable CS0618 // Type or member is obsolete
SourceGenerator.Initialize(generatorInitContext);
#pragma warning restore CS0618 // Type or member is obsolete

if (generatorInitContext.Callbacks.PostInitCallback is object)
{
Expand All @@ -62,7 +64,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
context.RegisterSourceOutput(contextBuilderSource, (productionContext, contextBuilder) =>
{
var generatorExecutionContext = contextBuilder.ToExecutionContext(_sourceExtension, productionContext.CancellationToken);
#pragma warning disable CS0618 // Type or member is obsolete
SourceGenerator.Execute(generatorExecutionContext);
#pragma warning restore CS0618 // Type or member is obsolete

// copy the contents of the old context to the new
generatorExecutionContext.CopyToProductionContext(productionContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.PooledObjects;
Expand All @@ -19,13 +20,15 @@ namespace Microsoft.CodeAnalysis
/// is no guarantee that the same instance will be used on a
/// subsequent generation pass.
/// </remarks>
[ImplementationObsolete(url: "https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md")]
public interface ISourceGenerator
{
/// <summary>
/// Called before generation occurs. A generator can use the <paramref name="context"/>
/// to register callbacks required to perform generation.
/// </summary>
/// <param name="context">The <see cref="GeneratorInitializationContext"/> to register callbacks on</param>
[Obsolete("ISourceGenerator is deprecated and should not be implemented. Please implement IIncrementalGenerator instead. See https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md.")]
void Initialize(GeneratorInitializationContext context);

/// <summary>
Expand All @@ -42,6 +45,7 @@ public interface ISourceGenerator
/// discover information about the users compilation and make decisions on what source to
/// provide.
/// </remarks>
[Obsolete("ISourceGenerator is deprecated and should not be implemented. Please implement IIncrementalGenerator instead. See https://github.com/dotnet/roslyn/blob/main/docs/features/incremental-generators.md.")]
void Execute(GeneratorExecutionContext context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,13 @@ End Class

Public _receiver As Receiver = New Receiver()

#Disable Warning BC40000
Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize
context.RegisterForSyntaxNotifications(Function() _receiver)
End Sub

Public Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute
#Enable Warning BC40000
context.AddSource("source.vb", "
Public Class D
End Class
Expand Down Expand Up @@ -801,13 +803,15 @@ End Class
_initialized = True
End Sub

#Disable Warning BC40000
Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize
_sourceInitialized = True
End Sub

Public Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute
_sourceExecuted = True
End Sub
#Enable Warning BC40000

End Class

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ public partial class GeneratedClass : IInterface { }
Private Class GeneratorThatImplementsInterfaceMethod
Implements ISourceGenerator

#Disable Warning BC40000
Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize
End Sub

Public Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute
#Enable Warning BC40000
Dim [interface] = context.Compilation.GetTypeByMetadataName("IInterface")
Dim memberName = [interface].MemberNames.Single()

Expand Down