Skip to content
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

Fix source generator issues #1732

Merged
merged 9 commits into from
Sep 5, 2024
Merged

Fix source generator issues #1732

merged 9 commits into from
Sep 5, 2024

Conversation

manodasanW
Copy link
Member

@manodasanW manodasanW commented Sep 4, 2024

This addresses a couple issues that came up with respect to our source generator:

  • There are scenarios where we generate code making use of unsafe. This can lead to compiler errors that might not be immediately obvious if unsafe isn't enabled and wasn't enabled by a CsWinRT package reference. So now we detect if unsafe isn't enabled and instead produce a diagnostic with a code fix to allow unsafe blocks. This is similar to what the other .NET sources generators do that also generate code using unsafe. Fixes SourceGenerator generates code using unsafe even if EnableUnsafeBlocks aren't enabled #1721
  • We were generating code for generic interface instantiations in scenarios we can say for sure aren't WinRT scenarios. Specifically, for .NET custom WinRT type mapping classes, we treated function calls to them as if they were WinRT classes and generated code to make them AOT safe when needed. But given they are not actually WinRT classes like string.Join, we do not need to generate during those scenarios. Addressed by differentiating the check to be for whether it is a WinRT class rather than just a WinRT type.
  • Instantiations of generic types defined in the same assembly were not getting code generated for on the vtable lookup table. This was due to the check we put where we said if the type is defined in the current assembly, we will probably be generating an attribute on it so we don't need to put it on the lookup table. But that isn't true if it is a generic class implementing generic interfaces. Addressing by making that check more accurate. Fixes AOT generator ignores generic classes inheriting from generic types #1724

@manodasanW
Copy link
Member Author

Validated with a couple repro scenarios that they behave as expected with the fix.

@manodasanW manodasanW merged commit c109e10 into master Sep 5, 2024
10 checks passed
@manodasanW manodasanW deleted the manodasanw/generatorfixes branch September 5, 2024 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant