Open morganbr opened 6 years ago
Blazor doesn't use them, Blazor built https://github.com/dotnet/jsinterop before mono built theirs.
Simply went through the jsinterop
implementation. It seems just implement another IJSRuntime
like in Mono.WebAssembly.Interop
would be good?
Simply went through the
jsinterop
implementation. It seems just implement anotherIJSRuntime
like inMono.WebAssembly.Interop
would be good?
Yep, that sounds like a good plan!
@Blealtan Did you get anywhere with this, I was going to have a look at it?
Had nothing better to do this afternoon, so had a go at this at https://github.com/yowl/corert/tree/jsinterop. However the Ilc step fails when attempting get the sequence points for various(all?) methods in System.Text.Json, e.g. https://github.com/dotnet/runtime/blob/5c12e28775077cf8b585f48bc83137e931283634/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ConverterList.cs#L18
Exception is {"Read out of bounds."} BadImageFormatException at https://github.com/dotnet/corert/blob/093c4e3684f7500b6e2d683541074027e8150fb4/src/Common/src/TypeSystem/Ecma/SymbolReader/PortablePdbSymbolReader.cs#L98
What is the stacktrace of the exception?
We're getting it with RyuJIT too. I haven't looked why yet. It's not a problem there because we do a try catch to work around Roslyn bugs: https://github.com/dotnet/corert/blob/e81eb736e4467c20aaece04a9db23c10e8567b67/src/ILCompiler.RyuJit/src/JitInterface/CorInfoImpl.RyuJit.cs#L795
Wasm should do the same.
Stack trace:
System.Reflection.Metadata.dll!System.Reflection.Throw.OutOfBounds() Line 168 C#
System.Reflection.Metadata.dll!System.Reflection.Metadata.Ecma335.MethodDebugInformationTableReader.GetSequencePoints(System.Reflection.Metadata.MethodDebugInformationHandle handle) Line 107 C#
System.Reflection.Metadata.dll!System.Reflection.Metadata.MethodDebugInformation.GetSequencePoints() Line 66 C#
> ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.PortablePdbSymbolReader.GetSequencePointsForMethod(int methodToken) Line 98 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.StartImportingInstruction() Line 578 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.ImportBasicBlock(Internal.IL.ILImporter.BasicBlock basicBlock) Line 328 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.ImportBasicBlocks() Line 304 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.Import() Line 172 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.CompileMethod(ILCompiler.WebAssemblyCodegenCompilation compilation, ILCompiler.DependencyAnalysis.WebAssemblyMethodCodeNode methodCodeNodeNeedingCode) Line 85 C#
ILCompiler.WebAssembly.dll!ILCompiler.WebAssemblyCodegenCompilation.ComputeDependencyNodeDependencies(System.Collections.Generic.List<ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory>> obj) Line 74 C#
ILCompiler.DependencyAnalysisFramework.dll!ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer<ILCompiler.DependencyAnalysisFramework.NoLogStrategy<ILCompiler.DependencyAnalysis.NodeFactory>, ILCompiler.DependencyAnalysis.NodeFactory>.ComputeDependencies(System.Collections.Generic.List<ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory>> deferredStaticDependencies) Line 139 C#
ILCompiler.DependencyAnalysisFramework.dll!ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer<ILCompiler.DependencyAnalysisFramework.NoLogStrategy<ILCompiler.DependencyAnalysis.NodeFactory>, ILCompiler.DependencyAnalysis.NodeFactory>.ComputeMarkedNodes() Line 262 C#
ILCompiler.WebAssembly.dll!ILCompiler.WebAssemblyCodegenCompilation.CompileInternal(string outputFile, ILCompiler.ObjectDumper dumper) Line 50 C#
ILCompiler.Compiler.dll!ILCompiler.Compilation.ILCompiler.ICompilation.Compile(string outputFile, ILCompiler.ObjectDumper dumper) Line 405 C#
ilc.dll!ILCompiler.Program.Run(string[] args) Line 612 C#
ilc.dll!ILCompiler.Program.Main(string[] args) Line 766 C#
Prints
Read out of bounds. ([System.Text.Json]System.Text.Json.Serialization.ConverterList..ctor(JsonSerializerOptions))
Have taken @MichalStrehovsky advice and try/catched it. Next problem is a FileNotFoundException at
> ILCompiler.Compiler.dll!ILCompiler.CompilerTypeSystemContext.GetModuleForSimpleName(string simpleName, bool throwIfNotFound) Line 128 C#
ILCompiler.Compiler.dll!ILCompiler.CompilerTypeSystemContext.ResolveAssembly(System.Reflection.AssemblyName name, bool throwIfNotFound) Line 106 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.ResolveAssemblyReference(System.Reflection.Metadata.AssemblyReferenceHandle handle) Line 488 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(System.Reflection.Metadata.EntityHandle handle) Line 123 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.LockFreeReaderHashtable<System.Reflection.Metadata.EntityHandle, Internal.TypeSystem.Ecma.EcmaModule.IEntityHandleObject>.CreateValueAndEnsureValueIsInTable(System.Reflection.Metadata.EntityHandle key) Line 417 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.LockFreeReaderHashtable<System.Reflection.Metadata.EntityHandle, Internal.TypeSystem.Ecma.EcmaModule.IEntityHandleObject>.GetOrCreateValue(System.Reflection.Metadata.EntityHandle key) Line 438 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.GetObject(System.Reflection.Metadata.EntityHandle handle) Line 336 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.ResolveTypeReference(System.Reflection.Metadata.TypeReferenceHandle handle) Line 444 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(System.Reflection.Metadata.EntityHandle handle) Line 115 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.LockFreeReaderHashtable<System.Reflection.Metadata.EntityHandle, Internal.TypeSystem.Ecma.EcmaModule.IEntityHandleObject>.CreateValueAndEnsureValueIsInTable(System.Reflection.Metadata.EntityHandle key) Line 417 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.LockFreeReaderHashtable<System.Reflection.Metadata.EntityHandle, Internal.TypeSystem.Ecma.EcmaModule.IEntityHandleObject>.GetOrCreateValue(System.Reflection.Metadata.EntityHandle key) Line 438 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.GetObject(System.Reflection.Metadata.EntityHandle handle) Line 336 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.ResolveMemberReference(System.Reflection.Metadata.MemberReferenceHandle handle) Line 384 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(System.Reflection.Metadata.EntityHandle handle) Line 119 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.LockFreeReaderHashtable<System.Reflection.Metadata.EntityHandle, Internal.TypeSystem.Ecma.EcmaModule.IEntityHandleObject>.CreateValueAndEnsureValueIsInTable(System.Reflection.Metadata.EntityHandle key) Line 417 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.LockFreeReaderHashtable<System.Reflection.Metadata.EntityHandle, Internal.TypeSystem.Ecma.EcmaModule.IEntityHandleObject>.GetOrCreateValue(System.Reflection.Metadata.EntityHandle key) Line 438 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.GetObject(System.Reflection.Metadata.EntityHandle handle) Line 336 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.GetMethod(System.Reflection.Metadata.EntityHandle handle) Line 320 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.ResolveMethodSpecification(System.Reflection.Metadata.MethodSpecificationHandle handle) Line 351 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.EcmaObjectLookupHashtable.CreateValueFromKey(System.Reflection.Metadata.EntityHandle handle) Line 131 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.LockFreeReaderHashtable<System.Reflection.Metadata.EntityHandle, Internal.TypeSystem.Ecma.EcmaModule.IEntityHandleObject>.CreateValueAndEnsureValueIsInTable(System.Reflection.Metadata.EntityHandle key) Line 417 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.LockFreeReaderHashtable<System.Reflection.Metadata.EntityHandle, Internal.TypeSystem.Ecma.EcmaModule.IEntityHandleObject>.GetOrCreateValue(System.Reflection.Metadata.EntityHandle key) Line 438 C#
ILCompiler.TypeSystem.dll!Internal.TypeSystem.Ecma.EcmaModule.GetObject(System.Reflection.Metadata.EntityHandle handle) Line 336 C#
ILCompiler.TypeSystem.dll!Internal.IL.EcmaMethodIL.GetObject(int token) Line 143 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.ImportCall(Internal.IL.ILOpcode opcode, int token) Line 1584 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.ImportBasicBlock(Internal.IL.ILImporter.BasicBlock basicBlock) Line 420 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.ImportBasicBlocks() Line 304 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.Import() Line 172 C#
ILCompiler.WebAssembly.dll!Internal.IL.ILImporter.CompileMethod(ILCompiler.WebAssemblyCodegenCompilation compilation, ILCompiler.DependencyAnalysis.WebAssemblyMethodCodeNode methodCodeNodeNeedingCode) Line 85 C#
ILCompiler.WebAssembly.dll!ILCompiler.WebAssemblyCodegenCompilation.ComputeDependencyNodeDependencies(System.Collections.Generic.List<ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory>> obj) Line 74 C#
ILCompiler.DependencyAnalysisFramework.dll!ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer<ILCompiler.DependencyAnalysisFramework.NoLogStrategy<ILCompiler.DependencyAnalysis.NodeFactory>, ILCompiler.DependencyAnalysis.NodeFactory>.ComputeDependencies(System.Collections.Generic.List<ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory>> deferredStaticDependencies) Line 139 C#
ILCompiler.DependencyAnalysisFramework.dll!ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer<ILCompiler.DependencyAnalysisFramework.NoLogStrategy<ILCompiler.DependencyAnalysis.NodeFactory>, ILCompiler.DependencyAnalysis.NodeFactory>.ComputeMarkedNodes() Line 262 C#
ILCompiler.WebAssembly.dll!ILCompiler.WebAssemblyCodegenCompilation.CompileInternal(string outputFile, ILCompiler.ObjectDumper dumper) Line 50 C#
ILCompiler.Compiler.dll!ILCompiler.Compilation.ILCompiler.ICompilation.Compile(string outputFile, ILCompiler.ObjectDumper dumper) Line 405 C#
ilc.dll!ILCompiler.Program.Run(string[] args) Line 612 C#
ilc.dll!ILCompiler.Program.Main(string[] args) Line 766 C#
For the simpleName
System.Runtime.CompilerServices.Unsafe
. Assembly name is {System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a}
. When I compile it the reference is E:\GitHub\corert\packages\System.Runtime.CompilerServices.Unsafe\4.5.1\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll
Which is .ver 4:0:4:0
so that looks like it could just be a compilation reference problem as 4.0.5.0 is in the 4.6.0 package. However even if I change the csc /reference then the problem persists.
Sticking my hand in the sand and carrying on leaves a problem at runtime
_S_P_CoreLib_System_Diagnostics_Debug__Fail_0@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[796]:0x4089f0
_S_P_CoreLib_System_Diagnostics_Debug__Assert_1@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[693]:0x3fd5a8
_S_P_CoreLib_System_Diagnostics_Debug__Assert@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[405]:0x3e5379
_S_P_TypeLoader_Internal_TypeSystem_TypeDesc__SetRuntimeTypeHandleUnsafe@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[13484]:0xa51fdf
_S_P_TypeLoader_Internal_TypeSystem_CanonType__Initialize@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[18601]:0xcff548
_S_P_TypeLoader_Internal_TypeSystem_CanonType___ctor@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[18107]:0xcc86bf
_S_P_TypeLoader_Internal_TypeSystem_TypeSystemContext__get_CanonType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[13482]:0xa51e7e
_S_P_TypeLoader_Internal_TypeSystem_TypeSystemContext__ResolveRuntimeTypeHandle@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[13088]:0xa1cd3f
_S_P_TypeLoader_Internal_Runtime_TypeLoader_TypeBuilder__TryBuildArrayType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[12954]:0xa12eca
_S_P_TypeLoader_Internal_Runtime_TypeLoader_TypeLoaderEnvironment__TryGetArrayTypeForElementType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[9424]:0x822c0b
_S_P_Reflection_Execution_Internal_Reflection_Execution_ExecutionEnvironmentImplementation__TryGetArrayTypeForElementType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[9425]:0x822d54
_S_P_Reflection_Core_System_Reflection_Runtime_TypeInfos_RuntimeArrayTypeInfo__GetRuntimeTypeHandleIfAny@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[6341]:0x68a3b3
_S_P_Reflection_Core_System_Reflection_Runtime_TypeInfos_RuntimeArrayTypeInfo__GetArrayTypeInfo@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[5778]:0x6504c1
_S_P_Reflection_Core_System_Reflection_Runtime_General_TypeUnifier__GetArrayType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[4395]:0x597ca6
_S_P_Reflection_Core_System_Reflection_Runtime_TypeInfos_RuntimeTypeInfo__MakeArrayType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[4394]:0x597c36
_S_P_CoreLib_System_Array__GetArrayTypeFromElementType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[2597]:0x4dd96a
_S_P_CoreLib_System_Array__CreateSzArray@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[2140]:0x4a80f3
_S_P_CoreLib_System_Array__CreateInstance@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[1207]:0x4363d3
_S_P_Reflection_Core_System_Reflection_Runtime_General_Helpers__InstantiateAsArray@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[17484]:0xc77125
_S_P_Reflection_Core_System_Reflection_Runtime_TypeInfos_RuntimeTypeInfo__GetCustomAttributes_0@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[17487]:0xc77625
_System_Text_Json_System_Text_Json_JsonSerializerOptions__GetAttributeThatCanHaveMultiple_0@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[13999]:0xa97921
_System_Text_Json_System_Text_Json_JsonSerializerOptions__GetConverter@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[12764]:0x9ee733
_System_Text_Json_System_Text_Json_JsonSerializerOptions__HasConverter@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[9557]:0x83cf24
_System_Text_Json_System_Text_Json_JsonClassInfo__GetClassType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[8570]:0x7b1df3
_System_Text_Json_System_Text_Json_JsonClassInfo___ctor@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[6449]:0x693e17
_System_Text_Json_System_Text_Json_JsonSerializerOptions__GetOrAddClass@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[5728]:0x64c583
_System_Text_Json_System_Text_Json_WriteStackFrame__Initialize@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[6595]:0x6a4137
_System_Text_Json_System_Text_Json_JsonSerializer__WriteCore_0@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[5667]:0x641be7
_System_Text_Json_System_Text_Json_JsonSerializer__WriteCore@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[4462]:0x59d89c
_System_Text_Json_System_Text_Json_JsonSerializer__WriteCoreString@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[3517]:0x55a0e6
_System_Text_Json_System_Text_Json_JsonSerializer__ToStringInternal@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[2645]:0x4e0bdf
_System_Text_Json_System_Text_Json_JsonSerializer__Serialize___Array_Object__@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[2056]:0x4a3bb9
_Microsoft_JSInterop_Microsoft_JSInterop_JSInProcessRuntime__Invoke_Int32_@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[1278]:0x43b557
_HelloWasm_Program__TestJsInterop@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[988]:0x420d75
_HelloWasm_Program__Main@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[556]:0x3ee160
_HelloWasm__Module___MainMethodWrapper@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[467]:0x3e92d1
_StartupCodeMain@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[456]:0x3e8e67
Which could be a problem with the recent shared generic changes I made which I'm using for this test.
FileNotFoundException
fixed (just me being stupid with the rsp file. SetRuntimeTypeHandleUnsafe
problem still there, maybe I've missed a dependency when compiling.
Do you know which one of the asserts is hitting in SetRuntimeTypeHandleUnsafe?
Looks like the first one !RuntimeHandleExtensions.IsNull(runtimeTypeHandle)
, where runtimeTypeHandle seems to be RuntimeAugments.GetCanonType(CanonTypeKind.NormalCanon)
Ah, and thats an intrinsic which Wasm does not implement. I'll take a look at other implementations to see what I should do here.
Hmm, the first point in the eetype for System.__Cannon is null so that would seem to be worth investigating
@__EEType_System___Canon = global [6 x i32*] [i32* null,
I seem to have a few problems not directly related, but will continue here. When compiling the method {[S.P.CompilerGenerated]Boxed_Enumerator<System.__Canon>..ctor_Unbox(SortedSet``1<__Canon>)}
for the call to {[System.Collections]System.Collections.Generic.SortedSet``1+Enumerator<System.__Canon>..ctor(native int,SortedSet``1<__Canon>)} {$1}
I need to get the override of the constructor but because the unboxing method is not an EcmaMethod
I dont get to go through the DisambiguateName
at https://github.com/dotnet/corert/blob/e81eb736e4467c20aaece04a9db23c10e8567b67/src/ILCompiler.Compiler/src/Compiler/CoreRTNameMangler.cs#L481 and hence the LLVM call is to the other ctor and there is a parameter count mismatch.
My LLVM is
call void @"System_Collections_System_Collections_Generic_SortedSet_1_Enumerator<System___Canon>___ctor"(i8* %3, i8* %LoadField_m_pEEType, i1 %Loadarg2_)
whereas I want (mangled name has suffix _0
)
call void @"System_Collections_System_Collections_Generic_SortedSet_1_Enumerator<System___Canon>___ctor_0"(i8* %3, i8* %LoadField_m_pEEType, i1 %Loadarg2_)
I find it suspicious we need an unboxing stub for a constructor. One would typically need unboxing stubs for virtual methods (pretty much just ToString/GetHasCode/Equals, and interface methods implemented by the struct). To need one for a constructor is odd (it would imply code pattern that is not expressible in IL). Where is the need for the unboxing stub coming from?
Basically unoxing stubs are only need when we have an object reference and need to call value types instance method. Should only happen in context of virtual calls.
Was hoping something like that was the answer.
It comes from adding the WebAssemblyMethodBodyNode
due to
ILCompiler.WebAssembly.dll!ILCompiler.DependencyAnalysis.WebAssemblyMethodBodyNode.WebAssemblyMethodBodyNode(Internal.TypeSystem.MethodDesc method) Line 67 C#
> ILCompiler.WebAssembly.dll!ILCompiler.DependencyAnalysis.WebAssemblyCodegenNodeFactory.CreateUnboxingStubNode(Internal.TypeSystem.MethodDesc method) Line 67 C#
System.Collections.Concurrent.dll!System.Collections.Concurrent.ConcurrentDictionary<Internal.TypeSystem.MethodDesc, ILCompiler.DependencyAnalysis.IMethodNode>.GetOrAdd(Internal.TypeSystem.MethodDesc key, System.Func<Internal.TypeSystem.MethodDesc, ILCompiler.DependencyAnalysis.IMethodNode> valueFactory) Unknown
ILCompiler.Compiler.dll!ILCompiler.DependencyAnalysis.NodeFactory.NodeCache<Internal.TypeSystem.MethodDesc, ILCompiler.DependencyAnalysis.IMethodNode>.GetOrAdd(Internal.TypeSystem.MethodDesc key) Line 150 C#
ILCompiler.Compiler.dll!ILCompiler.DependencyAnalysis.NodeFactory.MethodEntrypoint(Internal.TypeSystem.MethodDesc method, bool unboxingStub) Line 748 C#
ILCompiler.Compiler.dll!ILCompiler.DependencyAnalysis.NodeFactory.ExactCallableAddress(Internal.TypeSystem.MethodDesc method, bool isUnboxingStub) Line 772 C#
ILCompiler.Compiler.dll!ILCompiler.DependencyAnalysis.CodeBasedDependencyAlgorithm.AddDependenciesDueToReflectability(ref ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory>.DependencyList dependencies, ILCompiler.DependencyAnalysis.NodeFactory factory, Internal.TypeSystem.MethodDesc method) Line 40 C#
ILCompiler.Compiler.dll!ILCompiler.MetadataManager.GetDependenciesDueToReflectability(ref ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory>.DependencyList dependencies, ILCompiler.DependencyAnalysis.NodeFactory factory, Internal.TypeSystem.MethodDesc method) Line 322 C#
ILCompiler.Compiler.dll!ILCompiler.DependencyAnalysis.CodeBasedDependencyAlgorithm.AddDependenciesDueToMethodCodePresence(ref ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory>.DependencyList dependencies, ILCompiler.DependencyAnalysis.NodeFactory factory, Internal.TypeSystem.MethodDesc method) Line 62 C#
ILCompiler.WebAssembly.dll!ILCompiler.DependencyAnalysis.WebAssemblyMethodBodyNode.GetStaticDependencies(ILCompiler.DependencyAnalysis.NodeFactory factory) Line 81 C#
ILCompiler.DependencyAnalysisFramework.dll!ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer<ILCompiler.DependencyAnalysisFramework.NoLogStrategy<ILCompiler.DependencyAnalysis.NodeFactory>, ILCompiler.DependencyAnalysis.NodeFactory>.GetStaticDependenciesImpl(ILCompiler.DependencyAnalysisFramework.DependencyNodeCore<ILCompiler.DependencyAnalysis.NodeFactory> node) Line 145 C#
ILCompiler.DependencyAnalysisFramework.dll!ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer<ILCompiler.DependencyAnalysisFramework.NoLogStrategy<ILCompiler.DependencyAnalysis.NodeFactory>, ILCompiler.DependencyAnalysis.NodeFactory>.ComputeMarkedNodes() Line 266 C#
ILCompiler.WebAssembly.dll!ILCompiler.WebAssemblyCodegenCompilation.CompileInternal(string outputFile, ILCompiler.ObjectDumper dumper) Line 50 C#
ILCompiler.Compiler.dll!ILCompiler.Compilation.ILCompiler.ICompilation.Compile(string outputFile, ILCompiler.ObjectDumper dumper) Line 405 C#
ilc.dll!ILCompiler.Program.Run(string[] args) Line 612 C#
ilc.dll!ILCompiler.Program.Main(string[] args) Line 766 C#
The method that is having its AddDependenciesDueToReflectability
is {[System.Collections]System.Collections.Generic.SortedSet``1+Enumerator<System.__Canon>..ctor(SortedSet``1<__Canon>)}
Where I'm hitting this line https://github.com/dotnet/corert/blob/e81eb736e4467c20aaece04a9db23c10e8567b67/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/CodeBasedDependencyAlgorithm.cs#L40
Will compare to cpp to see why it doesn't do this.
Oh, if reflection adds it it's different. Try looking into IPrefixMangledMethod interface. It might help here. Sorry, still typing from a phone between diaper changes....
Thanks, having a look at that. Could you expand a bit on this comment: https://github.com/dotnet/corert/blob/e81eb736e4467c20aaece04a9db23c10e8567b67/src/ILCompiler.Compiler/src/Compiler/CompilerTypeSystemContext.BoxedTypes.cs#L588-L593 , particularly the last sentence. I think a corresponding comment is at https://github.com/dotnet/corert/blob/e81eb736e4467c20aaece04a9db23c10e8567b67/src/ILCompiler.Compiler/src/Compiler/CompilerTypeSystemContext.BoxedTypes.cs#L488-L490
I read from that a call to a ValueTypeInstanceMethodWithHiddenParameter
should never actually exist in the output?
Yes, the relocation to the fake method is replaced in the node factory when the codegen asks for the method entrypoint symbol for the fake method:
Thanks, I'll look at that in more detail. Have by passed it for the moment by editing the llvm, but I think the Wasm backend might be missing something else as getting an exception at
nullFunc_ii@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.js:6415:42
b25@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[26935]:0xf0e895
_S_P_CoreLib_System_Runtime_CalliIntrinsics__Call_IntPtr_@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[767]:0x279a6b
_S_P_CoreLib_Internal_Runtime_EEType__GetArrayEEType@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[635]:0x26c11a
_S_P_CoreLib_System_Runtime_DispatchResolve__FindInterfaceMethodImplementationTarget@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[424]:0x2593ae
_System_Text_Json_System_Text_Json_JsonSerializer__HandleEnumerable@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[7673]:0x58f7f3
_System_Text_Json_System_Text_Json_JsonSerializer__Write@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[5870]:0x4af750
_System_Text_Json_System_Text_Json_JsonSerializer__WriteCore_0@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[5103]:0x465acc
_System_Text_Json_System_Text_Json_JsonSerializer__WriteCore@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[3939]:0x3cc289
_System_Text_Json_System_Text_Json_JsonSerializer__WriteCoreString@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[3179]:0x39f571
_System_Text_Json_System_Text_Json_JsonSerializer__ToStringInternal@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[2278]:0x3268e1
_System_Text_Json_System_Text_Json_JsonSerializer__Serialize_System___Canon_@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[1948]:0x3074e1
_Microsoft_JSInterop_Microsoft_JSInterop_JSInProcessRuntime__Invoke_System___Canon_@file:///E:/GitHub/corert/tests/src/Simple/HelloWasm/bin/Debug/wasm/native/HelloWasm.wasm:wasm-function[1205]:0x2aae91
GetArrayEEType
is looking up a function through RhpGetClasslibFunctionFromEEType
. Maybe Wasm doesn't emit these class lib functions at all.
GetArrayEEType is looking up a function through RhpGetClasslibFunctionFromEEType
There's a special case for Wasm here that passes null classlib functions. This is where the fix will be:
https://github.com/dotnet/corert/blob/master/src/Native/Bootstrap/main.cpp#L365
The CalliIntrinisic
is going to call https://github.com/dotnet/corert/blob/093c4e3684f7500b6e2d683541074027e8150fb4/src/System.Private.CoreLib/src/System/Array.CoreRT.cs#L76-L80 but its going for the RuntimeExport
function, not the managed method directly. It will end up in the managed method, but by going through a native to managed thunk. Is that right?
I should say that my problem is that CalliIntrinsic
is getting compiled to make the calli
as though it were a managed method and is adding a shadow stack arg (as wasm does), which is then screwing things up as the native->managed thunk for GetSystemArrayEEType
does not have that parameter
I would kind of expect RuntimeExport methods to have the managed calling convention. It's really just a way to expose a managed method under a stable symbolic name (it's important for one of CoreRT configurations that are not enabled right now).
Can you check and see if any of the RuntimeExport symbols are called from the C/C++ code?
We could either give RuntimeExport the managed calling convention (if the C code doesn't need to call into these), or just come up with some other mechanism for these situations (don't have specific ideas right now).
I would kind of expect RuntimeExport methods to have the managed calling convention.
Well it sort of does and doesn't.. LLVM:
define %"[S.P.CoreLib]Internal.Runtime.EEType"* @S_P_CoreLib_System_Array__GetSystemArrayEEType(i8*) {
That has the managed convention, but there is also
define %"[S.P.CoreLib]Internal.Runtime.EEType"* @GetSystemArrayEEType() {
This is the thunk which doesn't. Maybe I'm just not quite getting this. If I change the signature on the RuntimeExport thunks to be managed (have the shadow stack first param), then I need to do the import call side as well to match which then leads to a problem with https://github.com/dotnet/corert/blob/093c4e3684f7500b6e2d683541074027e8150fb4/src/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs#L34 . And that's in C++ land.
Or do I leave the import side alone and match a managed import call to the export without going through the thunk. /confused/
To support interacting with the DOM, CoreRT needs to allow calls to and from JavaScript. Mono has established an API for this that Blazor uses, so that's probably a good start. It might be possible to just copy most of their code from https://github.com/mono/mono/blob/master/sdks/wasm/binding_support.js and https://github.com/mono/mono/blob/master/sdks/wasm/bindings.cs and make small changes.