monkey0506 / native-generic-delegates

Generic C# delegates for P/Invoke.
Other
8 stars 0 forks source link

Generic type argument detection is insufficient #14

Closed monkey0506 closed 9 months ago

monkey0506 commented 1 year ago

Describe the issue

The incremental-generator branch takes a naïve approach to discovering complete generic type arguments, which entirely (and deliberately) excludes using any generic type (e.g., Foo<T>) or unsubstituted generic type parameter (e.g., T inside some generic class or method) as a type argument for any of the INativeAction/INativeFunc interfaces and methods. This majorly cripples the utility of this library, and diminishes the project goal of enabling .NET generics to be utilized in scenarios that .NET doesn't natively support.

This library provides delegate types that must not be generic so that function pointers may be produced, but this requirement does not translate to the delegate arguments. By providing arguments that do not depend on type substitution, the library requirements can be fulfilled while greatly expanding the scope of what argument types are permitted and supported.

Proposed solution

A version of the GenericSymbolTree can be utilized here. Specifically, GetCompletedSymbolsForBranch can be called with only those symbols that are relevant to the library, though it is necessary to add every generic symbol's branches as this cannot be predicted (note: "adding" the branch to the tree in this context merely caches the symbol; type substitution is completed via GetCompletedSymbolsForBranch).

Additional considerations

The means used in the proposed solution may potentially have unknown consequences regarding performance. Real-world testing scenarios will be needed to ensure that this is not over-encumbering the source generation.

monkey0506 commented 9 months ago

Fixed by a6d0462 (interceptors branch).

monkey0506 commented 9 months ago

See also GenericSymbolReferenceTree.