kekekeks / XamlX

General purpose pluggable XAML compiler with no runtime dependencies.
MIT License
319 stars 55 forks source link

Migrate to using Cecil types to resolve generics and types equality #114

Closed maxkatz6 closed 6 months ago

maxkatz6 commented 6 months ago

cc @kekekeks @MrJul

This is a heavy PR, but these changes do make sense, solving most of our generics related problems.

Essentially, this PR removes old code related to CecilHelpers.TransformGeneric and CecilHelpers.Equals. And adds copy-pasted internal implementations from the Cecil itself (that never have been made public). It now includes:

Where GenericTypeResolver always works in a context. In a context of "owner" generic type and "owner" generic method (one of them or both, or none if no generics). Which would require passing GenericTypeResolver down from the root types to nested methods. Instead of that, partially moves responsibility to create IXamlType from CecilTypeSystem to CecilTypeResolver, which internally abstracts on top of both CecilTypeSystem and GenericTypeResolver with GenericParameterResolver. Every IXamlType instance now goes through generics transformation, except cases where it's explicitly disable (IXamlType.GenericTypeDefinition).

This and also multiple type caching layers were reduced to one in CecilTypeResolver. Which is greatly simplified using TypeReferenceEqualityComparer.

Fixes https://github.com/AvaloniaUI/Avalonia/issues/10485 Fixes https://github.com/AvaloniaUI/Avalonia/issues/9090 Probably https://github.com/AvaloniaUI/Avalonia/issues/8684 (didn't test) Probably https://github.com/AvaloniaUI/Avalonia/issues/3395 (didn't test)

maxkatz6 commented 6 months ago

Ah nice. Tests are failing, but only on Linux.

kekekeks commented 6 months ago

Ah nice. Tests are failing, but only on Linux.

Mono