-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[WIP] [ILVerify] Recognize type equivalence of two types with System.Runtime.InteropServices.TypeIdentifierAttribute
#64413
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
Closed
TIHan
wants to merge
3
commits into
dotnet:main
from
TIHan:il-verify-type-identifier-attribute-equiv
Closed
Changes from all commits
Commits
Show all changes
3 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.
This code only runs in debug builds (see 5 lines above) so that we can assert correct use. Equality comparison is done using referential equality for perf reasons. This fix won't work in release builds.
The fix would have to go somewhere around here:
runtime/src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.cs
Lines 147 to 151 in 014b084
I think a correct fix won't be trivial. The type system is meant to be general purpose and CastingHelper must not cast anything to
EcmaType. It will require some thinking on the shape of the extentibility API. Do we need to fix this 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.
On a second thought, placing the code in
IsEquivalentTowon't fix the problem of method resolution. This is a much bigger type system problem that I don't know how to solve without causing a major regression in type system performance. I suggest finding an easier problem to work on. This issue should be moved to Future.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.
(Files under src/coreclr/Common/TypeSystem are shared with tools like crossgen2 that are very sensitive to type system performance. It may be acceptable for ILVerify to get slower, but crossgen2 and the other tools need to be fast.)
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.
Thank you for the feedback.
Yea, I missed that. Though, when a test gets added it would hopefully catch it.
I found that out too. At the moment, it seems the most correct way to do this is the additional equivalency check in
==and!=.Could you expand on this? I'm not sure what this is in relation to this change.
The majority of types do not have a
TypeIdentifierAttribute, so constantly checking to see if the attribute exists might be too much considering this is being used by crossgen2. Instead, we could get this information a single time when the type gets imported and then look for that information if a type equivalency check fails.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.
That comment was connected to the existing
bool IsEquivalentTomethod - it doesn't apply because we don't need to do this just in casting - we need to do this any time we compare two types.Types not being equal is a very common scenario in the type system. We often need to check whether two types are equal. Currently this is just a trivial reference equality check. Requiring a fallback that will start inspecting fields on the types to check whether they happen to be type equivalent will regress performance (extra CPU cycles, wasted cache lines, etc.).
AFAIK type equivalence is part of built-in COM interop that is Windows specific and we're trying to phase out. Even the issue that this pull request is trying to fix was hit on .NET Framework, not Core. I don't know whether it's a good enough reason to regress performance and add maintenance cost. That's why I'm suggesting going the "won't fix" route.
Cc @davidwrighton for second opinion
Uh oh!
There was an error while loading. Please reload this page.
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.
cc @JulieLeeMSFT - see above comment from @MichalStrehovsky
Based on that, I think we can hold off on this change for a bit until we decide what we want to do. It isn't a critical fix.