[ILVerify] Handling of assignment of interface to object - with CastingHelper#3666
[ILVerify] Handling of assignment of interface to object - with CastingHelper#3666jkotas merged 11 commits intodotnet:masterfrom Dynatrace:VerifyInterfaces
Conversation
merge from dotnet/corert master
Merge dotnet/corert master
You need to run with a consistent set of assemblies:
Mixing and matching of reference assemblies and implementation does not work. The problem that you have described occurs when you mix System.Runtime reference assembly with System.Private.CoreLib implementation assembly. |
| curType = curType.BaseType; | ||
| if (curType.IsInterface) | ||
| { | ||
| curType = curType.Context.GetWellKnownType(WellKnownType.Object); |
There was a problem hiding this comment.
The other implementation of casting logic implement this case as one-off check before this loop, for example: https://github.com/dotnet/corert/blob/master/src/Runtime.Base/src/System/Runtime/TypeCast.cs#L633
It is a bit more efficient because of you need this check only first time through the loop. It would be nice to do it same way here.
| return true; | ||
|
|
||
| return IsAssignable(src.Type, dst.Type); | ||
| return CastingHelper.CanCastTo(src.Type, dst.Type); |
There was a problem hiding this comment.
Change IsAssignable(TypeDesc src, TypeDesc dst) to call CastingHelper.CanCastTo as well while you are on it? At this line https://github.com/dotnet/corert/pull/3666/files#diff-ab14902486f8fc54c4fd3c1845fa8babR187
Agree. The CoreRT is building with old project.json-based .NET CLI that does not integrate well with current Visual Studio. For example, you might have noticed that the VS project that we use for debugging the CoreRT compiler is actually full .NET Framework project, not .NET Core project. I have been working on upgrading the build system to recent .NET CLI that is a big step towards fixing this sort of problems. It will take me 1-2 weeks to get it done. The full .NET Framework helper projects should be gone once I am done. BTW: If you run into this with adding ILVerify tests, feel free to create a vanilla .NET Core projects using |
Yup, this works. Open the src\ILCompiler.TypeSystem\TypeSystem.sln solution and set the |
…Assignable(TypeDesc src, TypeDesc dst)
Now I understand. I will add this to the readme. I just naively passed every reference (direct or indirect) to ILVerify, maybe I won't be the only one doing this. @jkotas your second comment answers a ton of questions I had. Thanks for that! @MichalStrehovsky Great! Some tests fail when I start them that way (they are fine from the command line) I will dig deeper if I need to debug, but thanks for the info! |
| return thisType.CanCastTo(otherType.Instantiation[0]); | ||
| } | ||
|
|
||
| if(curType.IsInterface) |
We had some branching issues on our fork, so I opened a new PR.
Original PR: #3649
One problem I have is this:
On CoreCLR we have lots of type forwardings. E.g. Application code references System.Runtime.dll, which defines System.Object. The application code always references System.Object from System.Runtime, but System.Runtime.dll forwards it to Sysmte.PricateCorLib.dll. When I do
curType.Context.GetWellKnownType(WellKnownType.Object)it creates a [System.PriveCorLib]System.Object, but theotherTypeis [System.Runtime]System.Object (since it comes from the code referencing System.Runtime.dll). How should I handle this?Additionally I also have a question:
Is it possible to start the unit tests (in this case these: https://github.com/dotnet/corert/blob/master/src/ILCompiler.TypeSystem/tests/CastingTests.cs ) directly in Visual Studio? The VS Test runner does not discover these tests, the error I get is this:
As a workaround I do it from the command line like this:
CoreRun.exe xunit.console.netcore.exe TypeSystem.Tests.dll -xml testResults.xml -notrait Benchmark=true -notrait category=nonnetcoreapp1.1tests -notrait category=OuterLoop -notrait category=failing -notrait category=nonwindowstestsI found this in a log from runtest.cmd, but it would be much better to do it in VS, so I can also debug the tests.
Thanks.