Open pedro-gilmora opened 1 month ago
Issue #57239 involves a proposal for an overlapping set of problems.
The main problem with the current proposal is it does not include any concrete motivating examples (detailed descriptions of source generator solutions which cannot currently be implemented, but could be implemented if the proposed API was available). Once these examples are provided, the next step is evaluating related proposals (e.g. #57239) to determine which proposals provide a solution to which specific problems.
I see, you're asking for real world examples for it.
The one that made me do this proposal was a Dependency Injection resolver at compile time. I thought it to make able others SGen and analyzer writers to use this one as basis for their own code analysis and generations.
Since it's not possible to share data among generators, I took the following approach
Make others generators aware of the existence of mine. And then, they should implement based on their own attributes inheriting mine. So I can detect those ones and be aware whenever I find them.
Eg:
public sealed class JsonConfigurationAttribute(
string fileName = "appsettings",
bool optional = true,
bool reloadOnChange = true) : SingletonAttribute(factory: nameof(ConfigurationResolver.GetConfiguration));
public sealed class JsonSettingAttribute(string key) : SingletonAttribute(factory: nameof(ConfigurationResolver.GetSetting));
But that won't avoid collisions and possible ambiguities or implementations when doing such parallel process by possible multiple authors trying to integrate their packages by generating their code variant.
So, this is the main part. Ensuring other generator to no waste their time resolving what's already taken for some primary work.
Same for runtime existing variant it might lead to resolving exceptions
Abstracting this issue sounds like this:
What if I want to others use my conventions to generate code and provide more functionalities to an existing one? What would be the best approach to conciliate in compile time, such that others want to provide to an initial generated implementation by generating or not their own partialization of it?
My first idea sharing data through a delegate didn't work at release because of the difference of execution contexts. So, I can't bring that to here I guess
Motivation
I'm exploring a scenario where the initialization context of a source generator (SGen) can subscribe to a delegate from an SGen engine host, provided by a method within the
SourceProducerContext
. This would enable core source generator authors to:However, this approach comes with performance concerns, such as potential deadlocks, especially when relying on extension SGen authors’ implementations. To mitigate these issues, one solution could involve propagating the cancel token and execute 3rd party SGens with some predefined timeout.
Key-points
Proposed API
To address the outlined scenario, the following API can be introduced:
Usage Sample
Core Source Generator Author Example
Third-Party Source Generator Author Example
Risks
@sharwell ... At your considerations