Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LambdaCompiler prefer interpretation to compilation on iOS #54970

Merged

Conversation

MaximLipnin
Copy link
Contributor

@MaximLipnin MaximLipnin commented Jun 30, 2021

This is an attempt to address #47112 based on Egor's suggestion.
The changes:

  • set IsInterpreting MSBuild property to 'true' in case of iOS;
  • made System.Linq.Expressions.ExpressionCreator class internal static in order not to introduce new public type; otherwise it throws Type 'System.Linq.Expressions.ExpressionCreator<TDelegate>' does not exist in the reference but it does exist in the implementation.
  • updated the iOS simulator functional test for AOT to verify the fix
  • added PlatformDetection.IsLinqExpressionsBuiltWithIsInterpretingOnly which checks whether the System.Linq.Expressions is built with IsInterpreting property set to true. To do so, it uses reflection to verify the Expression.Accept method doesn't exist.
  • disabled some failing library tests using ActiveIssue + PlatformDetection.
  • updated the invariant functional test for the iOS simulator (b/c of Allow restricting cultures creation with any arbitrary names in Globalization Invariant Mode #54247)

@ghost
Copy link

ghost commented Jun 30, 2021

Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.

Issue Details

This is an attempt to address #47112 based on Egor's suggestion.
The changes:

  • set IsInterpreting MSBuild property to 'true' in case of iOS;
  • made System.Linq.Expressions.ExpressionCreator class internal static in order not to introduce new public type; otherwise it throws Type 'System.Linq.Expressions.ExpressionCreator<TDelegate>' does not exist in the reference but it does exist in the implementation.
  • updated the iOS simulator functional test for AOT to verify the fix.
Author: MaximLipnin
Assignees: -
Labels:

area-System.Linq.Expressions

Milestone: -

Co-authored-by: Stephen Toub <[email protected]>
@MaximLipnin
Copy link
Contributor Author

Actually, System.Linq.Expressions.Tests failed on the iOS simulator with the following errors:

1. System.Linq.Expressions.Tests.CompilerTests test suite
System.TypeLoadException : Could not resolve type with token 01000085 from typeref (expected class 'System.Runtime.CompilerServices.Closure' in assembly 'System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

2. System.Linq.Expressions.Tests.ExceptionHandlingExpressions.TryFinallyWithinFilterCompiledProhibited
Assert.Throws() Failure\nExpected: typeof(System.InvalidOperationException)\nActual:   (No exception was thrown)

3. 
System.Linq.Expressions.Tests.UnaryQuoteTests.Quote_Block_Closure(useInterpreter: False)
System.Linq.Expressions.Tests.UnaryQuoteTests.Quote_Lambda_Closure2(useInterpreter: False)
System.Linq.Expressions.Tests.UnaryQuoteTests.Quote_Lambda_Closure1(useInterpreter: False)
System.Linq.Expressions.Tests.UnaryQuoteTests.Quote_CatchBlock_Variable_Closure1(useInterpreter: False)
System.Linq.Expressions.Tests.UnaryQuoteTests.Quote_CatchBlock_NoVariable_Closure2(useInterpreter: False)
System.Linq.Expressions.Tests.UnaryQuoteTests.Quote_CatchBlock_Variable_Closure2(useInterpreter: False)
System.Linq.Expressions.Tests.UnaryQuoteTests.Quote_CatchBlock_NoVariable_Closure1(useInterpreter: False)
System.Linq.Expressions.Tests.UnaryQuoteTests.Quote_Block_LocalAndClosure(useInterpreter: False)

Xunit.Sdk.EqualException: Assert.Equal() Failure\nExpected: MemberAccess\nActual:   Convert 

4. 
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeFunc(typeArgs: [typeof(string), typeof(System.Double*), typeof(int)])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(System.Int32*)])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(int), typeof(System.String*), typeof(double)])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(int), typeof(System.Int32&amp;), typeof(string)])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(string), typeof(System.Double*), typeof(int)])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(System.String*)])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(System.Collections.Generic.List&lt;int&gt;), typeof(System.Collections.Generic.List&lt;int&gt;), typeof(System.Collections.Generic.List&lt;int&gt;), typeof(System.Collections.Generic.List&lt;int&gt;), typeof(System.Collections.Generic.List&lt;int&gt;), ...])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(System.String*), typeof(System.String*), typeof(System.String*), typeof(System.String*), typeof(System.String*), ...])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(System.Span&lt;char&gt;)])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), ...])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(System.Int32&amp;)])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(System.Int32*), typeof(System.Int32*), typeof(System.Int32*), typeof(System.Int32*), typeof(System.Int32*), ...])
System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeAction(typeArgs: [typeof(System.Double&amp;), typeof(System.Double&amp;), typeof(System.Double&amp;), typeof(System.Double&amp;), typeof(System.Double&amp;), ...])

System.PlatformNotSupportedException : Operation is not supported on this platform.
   at System.Linq.Expressions.Compiler.DelegateHelpers.MakeNewCustomDelegate(Type[] types)
   at System.Linq.Expressions.Compiler.DelegateHelpers.MakeNewDelegate(Type[] types)
   at System.Linq.Expressions.Compiler.DelegateHelpers.MakeDelegateType(Type[] types)
   at System.Linq.Expressions.Expression.GetDelegateType(Type[] typeArgs)
   at System.Linq.Expressions.Tests.GetDelegateTypeTests.CantBeFunc(Type[] typeArgs)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

5. System.Linq.Expressions.Tests.NewWithByRefParameterTests.CreateByRefAliasingCompiled
Assert.Equal() Failure\nExpected: 16\nActual:   12

6. System.Dynamic.Tests.InvokeMemberBindingTests.InvokeVirtualMethod(value: 0)
Assert.Equal() Failure\n          ↓ (pos 0)\nExpected: 0\nActual:   -1307871456\n          ↑ (pos 0)
at System.Linq.Expressions.Interpreter.ActionCallInstruction`2[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(InterpretedFrame frame)
   at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[] arguments)
   at System.Linq.Expressions.Interpreter.CallInstruction.InterpretLambdaInvoke(LightLambda targetLambda, Object[] args)
   at System.Linq.Expressions.Interpreter.MethodInfoCallInstruction.Run(InterpretedFrame frame)
   at System.Linq.Expressions.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[] arguments)
   at System.Dynamic.Tests.InvokeMemberBindingTests.InvokeVirtualMethod(Object value)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

7. System.Dynamic.Tests.InvokeMemberBindingTests.InvokeFuncMember
System.ArgumentException : Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object' (Parameter 'arg2')

    at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
   at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi, String methodParamName, String argumentParamName)
   at System.Linq.Expressions.Expression.Invoke(Expression expression, Expression arg0, Expression arg1, Expression arg2)
   at System.Linq.Expressions.Expression.Invoke(Expression expression, IEnumerable`1 arguments)
   at System.Linq.Expressions.DynamicExpression.Reduce()
   at System.Linq.Expressions.Expression.ReduceAndCheck()
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileNoLabelPush(Expression expr)
   at System.Linq.Expressions.Interpreter.LightCompiler.Compile(Expression expr)
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileGotoExpression(Expression expr)
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileNoLabelPush(Expression expr)
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileAsVoid(Expression expr)
   at System.Linq.Expressions.Interpreter.LightCompiler.Compile(Expression expr, Boolean asVoid)
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileConditionalExpression(Expression expr, Boolean asVoid)
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileNoLabelPush(Expression expr)
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileAsVoid(Expression expr)
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileBlockStart(BlockExpression node)
   at System.Linq.Expressions.Interpreter.LightCompiler.CompileBlockExpression(Expression expr, Boolean asVoid)
   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[[<>A{00000004}`3[[System.Runtime.CompilerServices.CallSite, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Linq.Expressions.Tests, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].Compile()
   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[<>A{00000004}`3](CallSite`1 site, Object[] args)
   at System.Runtime.CompilerServices.CallSiteOps.Bind[<>A{00000004}`3](CallSiteBinder binder, CallSite`1 site, Object[] args)
   at System.Linq.Expressions.Interpreter.FuncCallInstruction`4[[System.Runtime.CompilerServices.CallSiteBinder, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Runtime.CompilerServices.CallSite`1[[<>A{00000004}`3[[System.Runtime.CompilerServices.CallSite, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Linq.Expressions.Tests, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]], System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Object[], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[<>A{00000004}`3[[System.Runtime.CompilerServices.CallSite, System.Linq.Expressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Linq.Expressions.Tests, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].Run(InterpretedFrame frame)
   at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[] arguments)
   at System.Dynamic.Tests.InvokeMemberBindingTests.InvokeFuncMember()
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture

@steveisok
Copy link
Member

steveisok commented Jul 1, 2021

Actually, System.Linq.Expressions.Tests failed on the iOS simulator with the following errors:

Can you file separate issues for each and tag them with ActiveIssue so that they are skipped? We may need someone from the libraries team to help us sort things out.

@MaximLipnin MaximLipnin marked this pull request as ready for review July 6, 2021 19:48
Copy link
Member

@steveisok steveisok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - I think it makes sense to follow up w/ wasm changes.

@steveisok steveisok merged commit 3319fa8 into dotnet:main Jul 9, 2021
@MaximLipnin MaximLipnin deleted the prefer_interp_for_lambda_compiler_on_ios branch July 9, 2021 13:01
@ghost ghost locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants