-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[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
[WIP] [ILVerify] Recognize type equivalence of two types with System.Runtime.InteropServices.TypeIdentifierAttribute
#64413
Conversation
…em.Runtime.InteropServices.TypeIdentifierAttribute
| // Its only valid to compare two TypeDescs in the same context | ||
| Debug.Assert(left is null || right is null || object.ReferenceEquals(left.Context, right.Context)); | ||
| return object.ReferenceEquals(left, right); | ||
| if (left is null) |
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
| private static bool IsEquivalentTo(this TypeDesc thisType, TypeDesc otherType) | |
| { | |
| // TODO: Once type equivalence is implemented, this implementation needs to be enhanced to honor it. | |
| return thisType == otherType; | |
| } |
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 IsEquivalentTo won'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.
This fix won't work in release builds.
Yea, I missed that. Though, when a test gets added it would hopefully catch it.
placing the code in IsEquivalentTo won't fix the problem of method resolution.
I found that out too. At the moment, it seems the most correct way to do this is the additional equivalency check in == and !=.
It will require some thinking on the shape of the extentibility API.
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.
Could you expand on this? I'm not sure what this is in relation to this change.
That comment was connected to the existing bool IsEquivalentTo method - 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.
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.
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
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
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.
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.
System.Runtime.InteropServices.TypeIdentifierAttributeSystem.Runtime.InteropServices.TypeIdentifierAttribute
|
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsResolves this: #62732 Description ILVerify would fail verification of an assembly when two types, one in the assembly and one in a different assembly, had equivalent Acceptance Criteria
|
|
Draft Pull Request was automatically closed for inactivity. Please let us know if you'd like to reopen it. |
Resolves this: #62732
Description
ILVerify would fail verification of an assembly when two types, one in the assembly and one in a different assembly, had equivalent
TypeIdentifierAttributedata.Acceptance Criteria