-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix obtaining type handles of IDynamicInterfaceCastableImplementation #109875
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our of curiosity, is this something we could fix? What would those annotations look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NotActuallyAMemberButConsiderThisConstructed)].We have one more place where this would be useful and that's
GetUninitializedObject, but there we could approximate this by simply saying "keep all constructors". That one doesn't work here because interfaces don't have constructors.I don't know if we want a whole new thing just to annotate this API. Also it would be a breaking change to add now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a proposal for
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Constructed)]be viable? Eg. we useGetUninitializedObjectin a few places in the Store, and having to manually mark all public + private constructors everywhere is quite annoying, plus it likely keeps a bit more than it should. If we addedConstructedand updatedPublicConstructorsandPrivateConstructorsto both also implyConstructed, that would seem like it would not be a breaking change? And then we could update annotations to just requireConstructed, where possible. Thoughts? I'd be happy to open a proposal if you think it seems reasonable 🙂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing breaking changes in DAM annotations is still uncharted territory. This API is currently not annotated at all. I don't know if we could add annotation on it and whether all important users would be able to annotate.
Re-annotating GetUninitializedObject sounds more promising but I don't know if we really get much savings from it. How does it look like size-wise if you just violate the annotation and pass System.Type without annotations here? Do the constructors do meaningful amounts of work that would produce real savings? This API is also a bit niche, typically only used in serializers that need to use source gen anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to violate the annotation if there is a follow up constructor call? I assume that the follow up constructor call should keep the type constructable.
(GetUninitializedObject without a follow up constructor call is a questionable pattern that we should not be encouraging.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not straightforward currently:
GetUninitializedObjectis annotated as needing all constructors, but in fact we'd just need a single constructor being reflection-callable for this to work). This assumes that the code reflection-calling the constructor is not producing trimming warnings.