-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Introduce a new internal EventSourceGenerator and use it for all ES implementations #121180
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
Conversation
|
hm.. probably should move the SLNX update to a separate (last) commit (or maybe even PR?) |
…+ no explicit ctors 2) Introduce a new global SourceGenerators - EventSourceGenerator (and move the existing impl from SPC.Generators to this new project) 3) Update slnx files (via the UpdateSolutionFiles task) 4) Migrate all classes with [EventSource] to use the SG. Except for the ones with EtwSelfDescribingEventFormat
We will likely want more than just this, e.g. it'll need to be |
Do we need to modify the slnx files? Could we instead globally include via .props? |
it's not needed to build the projects, but needed for people opening slnx files for the SG project to show up there in slnx. All other source generator projects are already added there (added automatically by the UpdateSolutionFile task, which is manually invoked (it's slow)) |
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a source generator for EventSource classes to automatically generate constructors and metadata, eliminating the need for manual boilerplate code. The generator creates parameterless constructors that call the base EventSource constructor with the correct parameter order (name, guid).
Key changes:
- Introduces
EventSourceGeneratorsource generator that triggers on classes with[EventSource]attribute - Removes
[EventSourceAutoGenerate]attribute and makes affected EventSource classespartial - Changes EventSource base constructor parameter order from
(Guid, string)to(string, Guid)for consistency - Removes manual constructors from EventSource classes across the codebase
Reviewed Changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| EventSourceGenerator.cs | New source generator that creates constructors for EventSource classes |
| EventSourceGenerator.Parser.cs | Parser logic to extract EventSource metadata and validate constructors |
| EventSourceGenerator.Emitter.cs | Code generation logic for constructors and provider metadata |
| EventSource.cs | Changes constructor parameter order and visibility for source generator |
| TraceLoggingEventSource.cs | Updates constructor call to match new parameter order |
| Multiple EventSource classes | Removes manual constructors and adds partial keyword |
| NetCoreAppLibrary.props | Registers EventSourceGenerator |
| generators.targets | Enables generator for source projects |
| Directory.Build.props | Suppresses ESGEN001 warnings globally |
Comments suppressed due to low confidence (1)
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs:24
- The parser only checks for
NamespaceDeclarationSyntaxbut doesn't check forFileScopedNamespaceDeclarationSyntax. This will cause the generator to skip classes in file-scoped namespaces. UseBaseNamespaceDeclarationSyntaxas the base type to handle both traditional and file-scoped namespace declarations.
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused?
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs
Outdated
Show resolved
Hide resolved
…acing/RuntimeEventSource.cs
src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Show resolved
Hide resolved
|
@copilot address the recent feedback |
|
oh, that doesn't work that way? |
You can ask it to create a PR against your branch, but it will never do a direct push into your branch currently. |
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
This is the result of `dotnet build /t:UpdateSolutionFile slngen.proj` command (except for SPC.slnx which is not covered by the script so I added it there by hands). It's not build related, just for the people who open slnx for development, so the newly added SG (#121180) can show up in the solution tree. <img width="1092" height="529" alt="{3B42DE0C-82BD-4E62-8AEC-11221AE39139}" src="https://github.com/user-attachments/assets/a13b4d19-b12b-48ec-8a0b-7b7743b4ac12" />
Closes #28290
[EventSourceAutoGenerate], we rely on just [EventSource] + no explicit ctorsEventSourceSettings.EtwSelfDescribingEventFormat-- there are 3 ES impl defining this settings 🤔