Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Implement castclass/isinst opcodes #4510

Closed
morganbr opened this issue Sep 15, 2017 · 6 comments
Closed

Implement castclass/isinst opcodes #4510

morganbr opened this issue Sep 15, 2017 · 6 comments

Comments

@morganbr
Copy link
Contributor

morganbr commented Sep 15, 2017

The castclass and isinst opcodes should be implemented as calls into RhTypeCast functions. The method that handles these opcodes is

private void ImportCasting(ILOpcode opcode, int token)

The complete mapping based on opcode and type is in

public static string GetCastingHelperNameForType(TypeDesc type, bool throwing)

@morganbr
Copy link
Contributor Author

This is probably pretty doable now.

@Blealtan
Copy link
Contributor

Tried to implement this but got this when I try to generate calls to the related runtime functions:

Expected method 'RhTypeCast_IsInstanceOfClass' not found on type '[S.P.CoreLib]System.Runtime.TypeCast'

Debugging into the helper classes, I've confirmed the class itself is found but not the method, while ILSpy told me the method is there in S.P.CoreLib.dll with expected RuntimeExport attribute. May anyone have idea on this?

@jkotas
Copy link
Member

jkotas commented Jan 31, 2018

The result of GetCastingHelperNameForType is "extern C" symbol. I think the problem is that you are using it as a managed method name.

@morganbr
Copy link
Contributor Author

morganbr commented Feb 1, 2018

@Blealtan, thanks for picking this up!

It looks like this is a slightly special case. The casting helpers are implemented in managed code, but they're both exported and imported with a different name. For example, System.Runtime.TypeCast.IsInstanceOfClass is exported as RhTypeCast_IsInstanceOfClass. We have a CallRuntime utility, but because it uses the managed names of the methods, not the values in their RuntimeImport or RuntimeExport attributes, the names in JitHelper end up with the wrong value. You might be able to either modify the strings from JitHelper to remove the RhTypeCast_ prefix, change CallRuntime to use the names from the attributes or replicate the logic from JitHelper with the managed names.

@Blealtan
Copy link
Contributor

Blealtan commented Feb 1, 2018

@morganbr is right. I was using the RuntimeExport name and once switch to the managed name, it works. I've also add simple tests on this; PR will be there in minutes.

By the way, JitHelper is invalid for use in the wasm importer seemingly due to assembly structure problems; I'm replicating the GetCastingHelperNameForType in the importer currently, like all other runtime interface references do.

@Blealtan
Copy link
Contributor

Blealtan commented Feb 1, 2018

However after added checks on interface casting, the implementation broke on execution. Still digging into it.

Blealtan pushed a commit to Blealtan/corert that referenced this issue Feb 1, 2018
Implement castclass and isinst opcodes in ILToWebAssemblyImporter by
doing related function calls to methods in System.Runtime.TypeCast.

Fix dotnet#4510
Blealtan added a commit to Blealtan/corert that referenced this issue Feb 1, 2018
Implement castclass and isinst opcodes in ILToWebAssemblyImporter by
doing related function calls to methods in System.Runtime.TypeCast.

Fix dotnet#4510
Blealtan added a commit to Blealtan/corert that referenced this issue Feb 1, 2018
Implement castclass and isinst opcodes in ILToWebAssemblyImporter by
doing related function calls to methods in System.Runtime.TypeCast.

Fix dotnet#4510
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants