Skip to content

iOS: Attempting to JIT compile method '(wrapper dynamic-method) string object:lambda_method1 (System.Runtime.CompilerServices.Closure)' while running in aot-only mode. #47112

Closed

Description

@rolfbjarne

Description

The following code throws an exception at runtime when running on an iOS device:

var foos = new string [] { "hi", "bye" };
string f = foos.AsQueryable ().First ();

Exception:

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper dynamic-method) string object:lambda_method1 (System.Runtime.CompilerServices.Closure)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
    at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed)
    at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
    at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
    at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType, Object target)
    at System.Linq.Expressions.Compiler.LambdaCompiler.CreateDelegate()
    at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda)
    at System.Linq.Expressions.Expression`1[[System.Func`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Compile()
    at System.Linq.EnumerableExecutor`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Execute()
    at System.Linq.EnumerableQuery`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].System.Linq.IQueryProvider.Execute[String](Expression expression)
    at System.Linq.Queryable.First[String](IQueryable`1 source)
    at MySingleView.AppDelegate.FinishedLaunching(UIApplication app, NSDictionary options) in /Users/rolf/work/maccore/onedotnet/xamarin-macios/tests/dotnet/MySingleView/AppDelegate.cs:line 27

Repro:

git clone https://github.com/rolfbjarne/xamarin-macios
cd xamarin-macios
git checkout dotnet-attempting-to-jit-compile-method-lamba_method1
./configure --enable-dotnet
make reset
make all -j8
make install -j8
make mysingleview -C tests/dotnet

Complete output

Configuration

.NET 6.0.100-alpha.1.21060.3

Binlog:
MySingleView.binlog.zip

Regression?

No (new feature)

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jan 18, 2021
  2. EgorBo commented on Jan 18, 2021

    @EgorBo
    Member

    I suspect LambdaCompiler should always prefer interpretation instead of compilation on iOS.

    https://github.com/dotnet/runtime/blob/master/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj#L6-L9

  3. added and removed
    untriagedNew issue has not been triaged by the area owner
    on Jan 20, 2021
  4. added this to the 6.0.0 milestone on Jan 20, 2021
  5. steveisok commented on Jun 28, 2021

    @steveisok
    Member

    @MaximLipnin See if you can reproduce and give Egor's suggestion a try after.

  6. MaximLipnin commented on Jun 29, 2021

    @MaximLipnin
    Contributor

    I faced a lot of library test failures with similar error in in #50510. I have no any ios device at hand so I'll try re-enabling System.Linq.Expresions test suite in the PR and see any related CI failures.

  7. steveisok commented on Jun 29, 2021

    @steveisok
    Member

    @MaximLipnin try testing against the simulator with aot enabled. You should be able to take Rolf's example and alter the functional test to repro.

  8. MaximLipnin commented on Jun 30, 2021

    @MaximLipnin
    Contributor

    It's reproducible against the simulator when executing

    1. ./build.sh -os iOSSimulator -arch x64 -c Release -s mono+libs
    2. ./dotnet.sh build /t:Test /p:TargetOS=iOSSimulator /p:TargetArchitecture=x64 /p:Configuration=Release /p:RunAOTCompilation=true  /p:EnableAggressiveTrimming=true src/tests/FunctionalTests/iOS/Simulator/AOT/iOS.Simulator.Aot.Test.csproj
    

    @EgorBo What would be the right way to apply your suggestion? When trying to set <IsInterpreting>true</IsInterpreting>
    I get the following error:

    /Users/maxim/.nuget/packages/microsoft.dotnet.apicompat/6.0.0-beta.21321.1/build/Microsoft.DotNet.ApiCompat.targets(145,5): error : TypesMustExist : Type 'System.Linq.Expressions.ExpressionCreator<TDelegate>' does not exist in the reference but it does exist in the implementation. [/Users/maxim/dev/runtime/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj]
    /Users/maxim/.nuget/packages/microsoft.dotnet.apicompat/6.0.0-beta.21321.1/build/Microsoft.DotNet.ApiCompat.targets(159,5): error : MatchingRefApiCompat failed - The reference assembly doesn't match all the APIs in the implementation for '/Users/maxim/dev/runtime/artifacts/bin/System.Linq.Expressions/net6.0-Release/System.Linq.Expressions.dll'. To address either fix errors in the reference assembly (referenced as implementation in compat errors for this reverse compat check), add the issues to the baseline file '/Users/maxim/dev/runtime/src/libraries/System.Linq.Expressions/src/MatchingRefApiCompatBaseline.txt' or disable this check by setting RunMatchingRefApiCompat=false in this project. [/Users/maxim/dev/runtime/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj]
    

    The System.Linq.Expressions.ExpressionCreator type is not in the reference assembly.

  9. steveisok commented on Jun 30, 2021

    @steveisok
    Member

    @ViktorHofer Not quite sure who to ask, but would you happen to know the answer to Maxim's question?

  10. EgorBo commented on Jun 30, 2021

    @EgorBo
    Member

    @MaximLipnin I guess nobody tested "true" for that condition and it doesn't expose the same public APIs when it's set.
    if the only error AppCompat found is

    error : TypesMustExist : Type 'System.Linq.Expressions.ExpressionCreator<TDelegate>' does not exist in the reference but it does exist in the implementation. [/Users/maxim/dev/runtime/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj]
    

    that should not be difficult to fix

  11. ViktorHofer commented on Jun 30, 2021

    @ViktorHofer
    Member

    I guess nobody tested "true" for that condition and it doesn't expose the same public APIs when it's set.
    if the only error AppCompat found is

    Right, we had that option enabled on some configurations (I believe uap) which don't exist anymore. Nobody noticed that the API surface diverged when using the interpreter mode.

  12. ghost locked as resolved and limited conversation to collaborators on Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions