IronLanguages / dlr

Dynamic Language Runtime
Apache License 2.0
369 stars 84 forks source link

UWP trouble with interpreting dynamic expressions #3

Open neolithos opened 8 years ago

neolithos commented 8 years ago

Hello,

a really Q&D example for showing the issue.

First the simple callsitebinder:

private class BinaryCallSiteBinder : BinaryOperationBinder
{
    public BinaryCallSiteBinder()
        : base(ExpressionType.Add)
    {
    }

    public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
    {

        return new DynamicMetaObject(
            Expression.Convert(
            Expression.Add(
                Expression.Convert(target.Expression, typeof(int)),
                Expression.Convert(arg.Expression, typeof(int))
            ), typeof(object)),

            BindingRestrictions.GetTypeRestriction(target.Expression, typeof(int)).Merge(
                BindingRestrictions.GetTypeRestriction(arg.Expression, typeof(int))
            ));
    }
}

And the calling code:

var expr = DynamicExpression.Dynamic(new BinaryCallSiteBinder(), typeof(object), Expression.Constant(40, typeof(object)), Expression.Constant(2, typeof(object)));
var f = Expression.Lambda<Func<object>>(expr);
var f2 = f.Compile();
textbox1.Text = f2().ToString();

If I run the code under Windows 8.1 Phone or the desktop .net framework, it works fine.

But under Windows 10 UWP I get the following exception:

System.ArgumentException wurde nicht von Benutzercode behandelt.
  HResult=-2147024809
  Message=Expression of type 'System.Object' cannot be used for parameter of type 'System.Runtime.CompilerServices.CallSite' of method 'Boolean SetNotMatched(System.Runtime.CompilerServices.CallSite)'
  Source=System.Linq.Expressions
  StackTrace:
       at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
       at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0)
       at System.Runtime.CompilerServices.CallSite`1.CreateCustomNoMatchDelegate(MethodInfo invoke)
       at System.Runtime.CompilerServices.CallSite`1.MakeUpdateDelegate()
       at System.Runtime.CompilerServices.CallSite`1.GetUpdateDelegate(T& addr)
       at System.Runtime.CompilerServices.CallSite`1.GetUpdateDelegate()
       at System.Runtime.CompilerServices.CallSite`1.Create(CallSiteBinder binder)
       at System.Runtime.CompilerServices.CallSite.Create(Type delegateType, CallSiteBinder binder)
       at System.Linq.Expressions.DynamicExpression.Reduce()
       at System.Linq.Expressions.Interpreter.LightCompiler.CompileNoLabelPush(Expression expr)
       at System.Linq.Expressions.Interpreter.LightCompiler.Compile(Expression expr)
       at System.Linq.Expressions.Interpreter.LightCompiler.CompileTop(LambdaExpression node)
       at System.Linq.Expressions.Expression`1.Compile()
       at TestLua.MainPage.btnClick_Click(Object sender, RoutedEventArgs e)

What is wrong?

Same issue https://github.com/IronLanguages/main/issues/1231

neolithos commented 8 years ago

Is there a way to help to find the problem?

It would be nice if my library runs on UWP, to port my application to Windows 10 IoT.

neolithos commented 8 years ago

The Delegate that is generated for the expression is Func<object,object,object,object> but in a later stage Func<CallSite,object,object,object> is expected.

https://github.com/dotnet/corefx/blob/master/src/System.Dynamic.Runtime/src/System/Linq/Expressions/Compiler/TypeInfoExtensions.cs

But CallSiteOps.SetNotMatched expects a CallSite as first argument (see CallSite<>.MakeUpdateDelegate). Btw. marked as "Do not use"?

I do not understand, who is the right address. I am little confused about all the implementations.

Is this here know the right place? Because, now this problem is a real show stopper for updating to W10.

jdhardy commented 8 years ago

It depends on whether it's an issue in how IronPython uses the DLR, or if the DLR implementation changed. To be honest, I'm not entirely clear on the relationship between all of the various .NET runtimes any more. I do know that it works as a desktop app on Windows 10/.NET 4.6 (as that's where I do my development) but I don't know what variant of the runtime UWP apps use.

On Wed, Sep 30, 2015 at 2:39 AM, neolithos notifications@github.com wrote:

The Delegate that is generated for the expression is Func but in a later stage Func is expected.

https://github.com/dotnet/corefx/blob/master/src/System.Dynamic.Runtime/src/System/Linq/Expressions/Compiler/TypeInfoExtensions.cs

But CallSiteOps.SetNotMatched expects a CallSite as first argument (see CallSite<>.MakeUpdateDelegate). Btw. marked as "Do not use"?

I do not understand, who is the right address. I am little confused about all the implementations.

Is this here know the right place? Because, now this problem is a real show stopper for updating to W10.

— Reply to this email directly or view it on GitHub https://github.com/IronLanguages/dlr/issues/3#issuecomment-144339621.

neolithos commented 8 years ago

IronPython and NeoLua are using the same parts of the dynamic runtime (I do not know the current version as good as previous). I will repost this issue in the corefx project, because that is used by W10 UWP.

In .net core the dynamic stuff is interpreted and not compiled anymore. I have no idea how this perform.

slide commented 7 years ago

Was this ever resolved?

neolithos commented 7 years ago

This issue was a show stopper. So, we did go back to the old devices and libs.

I tried the code again. And it still fails. Under Win10 1607 even harder. After putting the code in a try catch block I get the same exception.

So, it seems not resolved.

woachk commented 6 years ago

Windows 10 UWP uses an Ahead-of-time compiler toolset without a JIT, so do not even try. (Reflection alone is already painful enough)

Debug builds uses a JIT though, but you’ll never get it working for release.

DjArt commented 5 years ago

Works! https://github.com/IronLanguages/dlr/pull/179

neolithos commented 5 years ago

Cool! Thx.