dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.06k stars 4.69k forks source link

Source generators should be able to handle C# 13 extensions #102817

Open eiriktsarpalis opened 4 months ago

eiriktsarpalis commented 4 months ago

Source generators that accept arbitrary .NET types as inputs such as STJ, ConfigurationBinder and the logger generator should be updated so that they are able to handle type graphs containing extensions gracefully. Code produced by such generators is usually indexed by System.Type, so they often do not distinguish between different aliases of the same type. Even though some generators (such as CB) don't do this, we still need to make sure that extensions are being handled gracefully and that compatibility with the baseline reflection-based implementation is being preserved.

We need to make sure that the introduction of either implicit or explicit extensions in the type graph does not result in nondeterminstic contracts being generated (i.e. because of extension properties being defined).

cc @ericstj @tarekgh @stephentoub

eiriktsarpalis commented 4 months ago

@333fred could you point to any additions to the Roslyn symbols API that are used to represent extensions?

stephentoub commented 4 months ago

cc: @jcouv

jcouv commented 4 months ago

The Roslyn symbol APIs for extensions have not yet been discussed in details, but likely there will be something indicating whether a type is an extension (TypeKind.Extension and IsExtension), something indicating whether the extension is implicit or explicit (IsExplicitExtension) and something indicating the underlying type. Tagging the tracking issue for extensions

eiriktsarpalis commented 4 months ago

@jcouv how would implicit extensions work in this case? Whether a type has an implicit extension would be dependent on scope.

jcouv commented 4 months ago

I didn't understand the question. The APIs I described above tell you whether a type is an extension, whether it is explicit or implicit and what its underlying type is. None of the above APIs tell you whether an implicit extension is applicable to a given type in a given scope.

dotnet-policy-service[bot] commented 4 months ago

Tagging subscribers to this area: @dotnet/area-system-runtime See info in area-owners.md if you want to be subscribed.