NMFCode / NMF

This repository contains the entire code for the .NET Modeling Framework
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

il2cpp compability for unity3d engine #43

Closed friuns2 closed 5 years ago

friuns2 commented 6 years ago

any hope for AOT compability mode? There are restrictions System.Reflection.Emit is missing

georghinkel commented 6 years ago

What do you mean by AOT compatibility mode? I can't think of a place where NMF uses System.Reflection.Emit. NMF does runtime code generation, but usually only through compiling lambda expressions. I have no idea whether that is compatible with AOT.

friuns2 commented 6 years ago

Really? gonna check error output then here is some more info basicly its just disables System.Reflection.Emit https://docs.unity3d.com/Manual/ScriptingRestrictions.html

friuns2 commented 6 years ago

NotSupportedException: D:\Program Files\Unity2018.2.0f2\Editor\Data\il2cpp\libil2cpp\icalls\mscorlib\System.Reflection.Emit\AssemblyBuilder.cpp(20) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported. at System.Reflection.Emit.AssemblyBuilder..ctor (System.Reflection.AssemblyName n, System.String directory, System.Reflection.Emit.AssemblyBuilderAccess access, System.Boolean corlib_internal) [0x00000] in <00000000000000000000000000000000>:0 at System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access, System.String dir, System.Security.Policy.Evidence evidence, System.Security.PermissionSet requiredPermissions, System.Security.PermissionSet optionalPermissions, System.Security.PermissionSet refusedPermissions, System.Boolean isSynchronized) [0x00000] in <00000000000000000000000000000000>:0 at System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) [0x00000] in <00000000000000000000000000000000>:0 at System.Reflection.Emit.DynamicMethod+AnonHostModuleHolder..cctor () [0x00000] in <00000000000000000000000000000000>:0 at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes, System.Type owner, System.Reflection.Module m, System.Boolean skipVisibility, System.Boolean anonHosted) [0x00000] in <00000000000000000000000000000000>:0 at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Boolean restrictedSkipVisibility) [0x00000] in <00000000000000000000000000000000>:0 at System.Linq.Expressions.Compiler.LambdaCompiler..ctor (System.Linq.Expressions.Compiler.AnalyzedTree tree, System.Linq.Expressions.LambdaExpression lambda) [0x00000] in <00000000000000000000000000000000>:0 at System.Linq.Expressions.Compiler.LambdaCompiler.Compile (System.Linq.Expressions.LambdaExpression lambda) [0x00000] in <00000000000000000000000000000000>:0 at System.Linq.Expressions.Expression1[TDelegate].Compile (System.Boolean preferInterpretation) [0x00000] in <00000000000000000000000000000000>:0 at NMF.Expressions.ObservingFunc2[T1,TResult]..ctor (System.Linq.Expressions.Expression1[TDelegate] expression) [0x00000] in <00000000000000000000000000000000>:0 at NMF.Expressions.ObservingFunc2[T1,TResult].FromExpression (System.Linq.Expressions.Expression1[TDelegate] expression) [0x00000] in <00000000000000000000000000000000>:0 at NMF.Expressions.Linq.ObservableExtensions.OrderBy[TItem,TKey] (NMF.Expressions.INotifyEnumerable1[T] source, System.Linq.Expressions.Expression1[TDelegate] keySelector, System.Collections.Generic.IComparer1[T] comparer) [0x00000] in <00000000000000000000000000000000>:0 at NMF.Expressions.Linq.ObservableExtensions.OrderByDescending[TItem,TKey] (NMF.Expressions.INotifyEnumerable1[T] source, System.Linq.Expressions.Expression1[TDelegate] keySelector) [0x00000] in <00000000000000000000000000000000>:0 at Test2.Start () [0x00000] in <00000000000000000000000000000000>:0

friuns2 commented 6 years ago

seems System.Linq.Expressions.Compiler.LambdaCompiler. uses System.Reflection.Emit :(

there is some hack but probably generates more overhead or not work https://github.com/deniszykov/csharp-eval-unity3d

georghinkel commented 6 years ago

That library says it is an expression parser. I guess parsing is not the problem, but runtime code generation is if you want to statically translate IL code to C++. It is simply impossible.

NMF uses the lambda expression compiler in a couple of places when pure reflection does not suffice. In most cases, it actually does (at least for the instruction-level incrementalization that is most commonly used). However, some stuff such as constructor calls need expression compilers simply because the .NET Standard reflection API does not support creating a delegate for a constructor. Thus, if you avoid any constructor calls, including any compiler-generated constructor call, in your query, then I guess you can get away without the expression compiler.