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

Support implicit blittability for structs declared in and not exposed outside of the current compilation. #1126

Conversation

jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented May 14, 2021

Also significantly increase our test coverage for generic blittable types as they're another area nearby and something I hadn't added a ton of tests for originally.

Fixes #1125

public static bool HasOnlyBlittableFields(this ITypeSymbol type) => HasOnlyBlittableFields(type, new HashSet<ITypeSymbol>(SymbolEqualityComparer.Default));
#pragma warning restore RS1024 // Compare symbols correctly

private static bool HasOnlyBlittableFields(this ITypeSymbol type, HashSet<ITypeSymbol> seenTypes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do me a favor here and pass a recursion counter - when it reaches 0 we throw. Alternatively this could be converted to use a Stack<T> and turned into an iterative solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same protection for IsConsideredBlittable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed offline, I think we should leave Stack-overflow protection due to too many nested structs to the Roslyn compiler infrastructure.

…e sure we're handling our recursion check correctly.
@jkoritzinsky jkoritzinsky force-pushed the internal-implicit-blittable branch from 070f1e7 to 505a2a2 Compare May 14, 2021 23:18
@jkoritzinsky jkoritzinsky merged commit 51d9ad8 into dotnet:feature/DllImportGenerator May 18, 2021
@jkoritzinsky jkoritzinsky deleted the internal-implicit-blittable branch May 18, 2021 21:00
jkoritzinsky added a commit to jkoritzinsky/runtime that referenced this pull request Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-DllImportGenerator Source Generated stubs for P/Invokes in C#
Projects
None yet
3 participants