Skip to content

Conversation

@stephentoub
Copy link
Contributor

Closes #1003

Comment on lines +465 to +466
ImmutableArray<string> TypeParameters, ImmutableArray<ParameterInfo> Parameters,
string? MethodDescription, string? ReturnDescription, ImmutableArray<DiagnosticInfo> Diagnostics)
Copy link
Contributor

Choose a reason for hiding this comment

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

Immutable array is likely to hurt equality here. I personally always reuse EquatableArray from @Sergio0694 for this. https://github.com/Sergio0694/ComputeSharp/blob/main/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray%7BT%7D.cs

Copy link

Choose a reason for hiding this comment

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

Yep. This model, as written, will very rarely be equatable.

private readonly record struct DiagnosticInfo(string Id, Location? Location, params object?[] MessageArgs);

/// <summary>Holds extracted XML documentation for a method.</summary>
private sealed record XmlDocumentation(string MethodDescription, string Returns, Dictionary<string, string> Parameters);
Copy link
Contributor

Choose a reason for hiding this comment

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

This Dictionary should still be a problem, isn't it?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. In one of my personal repos I've created a number of immutable collection types that implement structural equality including a dictionary type.

private readonly record struct MethodToGenerate(MethodDeclarationSyntax MethodDeclaration, IMethodSymbol MethodSymbol);
private readonly record struct TypeDeclarationInfo(string Name, string TypeKeyword);

private readonly record struct DiagnosticInfo(string Id, Location? Location, params object?[] MessageArgs);
Copy link
Contributor

Choose a reason for hiding this comment

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

This array here is likely to be a problem as well?

// Combine with compilation to get well-known type symbols.
var compilationAndMethods = context.CompilationProvider.Combine(allMethods);
// Report diagnostics.
context.RegisterSourceOutput(allMethods, static (spc, methods) =>
Copy link
Member

Choose a reason for hiding this comment

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

This separation of diagnostic reporting into a separate callback is an interesting approach. I think it might provide a viable workaround for dotnet/runtime#92509. Curious if you've applied this approach elsewhere before, or if there are any drawbacks to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't. copilot suggested it.

Copy link
Member

Choose a reason for hiding this comment

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

Tagging @chsienki @333fred in case they have any objections.

Choose a reason for hiding this comment

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

Note that diagnostic objects are not equatable, and the recommendation of the team (e.g. @CyrusNajmabadi) is to not include them in incremental steps, or they would break them. Meaning that you effectively lose incrementality at each re-run as long as there's any diagnostic being produced. From our previous talks there's 3 ways to fix this:

  • If possible, just move them al to analyzers
  • Emit them immediately from the transform step
  • Introduce some equatable model to carry diagnostic info (e.g. I do this here)

Copy link

Choose a reason for hiding this comment

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

If there are any diagnostics, I expect that equality will be completely broken here. Our recommendation is to have separate analyzers for diagnostics and not do any reporting in the generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revise XmlToDescriptionGenerator incrementality

5 participants