dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.39k stars 4.75k forks source link

Crash in GetHashCode with generic record #72181

Closed dr1rrb closed 2 years ago

dr1rrb commented 2 years ago

Description

In a library, I've a generic record that inherits from another generic record https://github.com/unoplatform/uno.extensions/blob/450d19f8fd9d4c53f327e5ecddbeeb50f86b020f/src/Uno.Extensions.Reactive/Operators/FeedToListFeedAdapter.cs#L14, but as soon as I try to use an instance of that record in a Dictionary my app is crashing.

Reproduction Steps

Unfortunately I was not able to create a repro for that issue. But here are the working (with an explicit GetHashCode) and failing version of my app on iOS. working-Commerce.iOS.app.zip crashing-Commerce.iOS.app.zip .

Expected behavior

No crash :)

Actual behavior

Using mono for Android and iOS the app is crashing while using the same library is working fine on UWP / WinUI. Didn't test WebAssembly.

On Android I get a SIGABRT

[libc] Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 5768 (mmerce.Commerce), pid 5768 (mmerce.Commerce)

On iOS I get that stack trace:


=================================================================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`1:GetHashCode <0x0004a>
      at Uno.Extensions.Reactive.ListStateImpl`1:GetHashCode <0x0004a>
      at System.Collections.Generic.ObjectEqualityComparer`1:GetHashCode <0x000aa>
      at Uno.Extensions.Reactive.Operators.ListFeedToFeedAdapter`1:GetHashCode <0x0012c>
      at System.Collections.Generic.Dictionary`2:FindEntry <0x001e6>
      at System.Collections.Generic.Dictionary`2:TryGetValue <0x0008a>
      at Uno.Extensions.Reactive.Core.StateStore:GetOrCreateState <0x0045a>
      at Uno.Extensions.Reactive.Core.SourceContext:GetOrCreateStateCore <0x00375>
      at Uno.Extensions.Reactive.Core.SourceContext:GetOrCreateListState <0x000fa>
      at Uno.Extensions.Reactive.Bindings.BindableListFeed`1:.ctor <0x00132>
      at BindableDealsViewModel:.ctor <0x006b2>
      at <Module>:runtime_invoke_void__this___object_object_object <0x001ff>
      at <unknown> <0xffffffff>
      at System.Reflection.RuntimeConstructorInfo:InternalInvoke <0x00100>
      at System.Reflection.RuntimeConstructorInfo:InternalInvoke <0x0029a>
      at System.Reflection.RuntimeConstructorInfo:DoInvoke <0x004ea>
      at System.Reflection.RuntimeConstructorInfo:Invoke <0x0009a>
      at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver:VisitConstructor <0x0038d>
      at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2:VisitCallSiteMain <0x00398>
      at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver:VisitDisposeCache <0x000dd>
      at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2:VisitCallSite <0x00564>
      at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver:Resolve <0x00237>
      at <>c__DisplayClass2_0:<RealizeService>b__0 <0x000d2>
      at Microsoft.Extensions.DependencyInjection.ServiceProvider:GetService <0x001eb>
      at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope:GetService <0x00122>
      at <CreateViewModel>d__8:MoveNext <0x00c4d>
      at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start <0x00202>
      at Uno.Extensions.Navigation.Navigators.ControlNavigator:CreateViewModel <0x0029a>
      at <InitializeCurrentView>d__9:MoveNext <0x006da>
      at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start <0x0021a>
      at Uno.Extensions.Navigation.Navigators.ControlNavigator`1:InitializeCurrentView <0x002bc>
      at <NavigateForwardAsync>d__10:MoveNext <0x016a2>
      at MoveNextRunner:InvokeMoveNext <0x000ab>
      at System.Threading.ExecutionContext:RunInternal <0x00585>
      at System.Threading.ExecutionContext:Run <0x00092>
      at MoveNextRunner:Run <0x001aa>
      at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
      at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
      at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
      at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
      at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
      at System.Threading.Tasks.Task`1:TrySetResult <0x0026a>
      at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x002da>
      at <Show>d__14:MoveNext <0x010ea>
      at MoveNextRunner:InvokeMoveNext <0x000ab>
      at System.Threading.ExecutionContext:RunInternal <0x00585>
      at System.Threading.ExecutionContext:Run <0x00092>
      at MoveNextRunner:Run <0x001aa>
      at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
      at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
      at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
      at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
      at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
      at System.Threading.Tasks.Task`1:TrySetResult <0x00262>
      at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x002e2>
      at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x0014a>
      at System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult <0x00082>
      at <EnsurePageLoaded>d__15:MoveNext <0x006ba>
      at MoveNextRunner:InvokeMoveNext <0x000ab>
      at System.Threading.ExecutionContext:RunInternal <0x00585>
      at System.Threading.ExecutionContext:Run <0x00092>
      at MoveNextRunner:Run <0x001aa>
      at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
      at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
      at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
      at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
      at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
      at System.Threading.Tasks.Task`1:TrySetResult <0x0022a>
      at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x002b2>
      at <EnsureLoaded>d__6:MoveNext <0x0088a>
      at MoveNextRunner:InvokeMoveNext <0x000ab>
      at System.Threading.ExecutionContext:RunInternal <0x00585>
      at System.Threading.ExecutionContext:Run <0x00092>
      at MoveNextRunner:Run <0x001aa>
      at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
      at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
      at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
      at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
      at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
      at System.Threading.Tasks.Task`1:TrySetResult <0x0022a>
      at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x002b2>
      at System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1:SetResult <0x000a2>
      at <ExecuteAsync>d__0`1:MoveNext <0x006f2>
      at MoveNextRunner:InvokeMoveNext <0x000ab>
      at System.Threading.ExecutionContext:RunInternal <0x00585>
      at System.Threading.ExecutionContext:Run <0x00092>
      at MoveNextRunner:Run <0x001aa>
      at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
      at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
      at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
      at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
      at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
      at System.Threading.Tasks.Task`1:TrySetResult <0x0022a>
      at System.Threading.Tasks.TaskCompletionSource`1:TrySetResult <0x00092>
      at System.Threading.Tasks.TaskCompletionSource`1:SetResult <0x0007a>
      at <<ExecuteAsync>b__0>d:MoveNext <0x0046a>
      at System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start <0x0020a>
      at <>c__DisplayClass0_0`1:<ExecuteAsync>b__0 <0x0014a>
      at <>c__DisplayClass6_0:<TryEnqueue>b__0 <0x0006f>
      at Uno.UI.Dispatching.CoreDispatcher:InvokeOperation <0x00460>
      at Uno.UI.Dispatching.CoreDispatcher:InvokeOperationSafe <0x0008a>
      at Uno.UI.Dispatching.CoreDispatcher:DispatchItems <0x0070a>
      at CoreFoundation.DispatchQueue:static_dispatcher_to_managed <0x0032f>
      at CoreFoundation.DispatchQueue:static_dispatcher_to_managed <0x0010a>
      at <unknown> <0xffffffff>
      at UIKit.UIApplication:UIApplicationMain <0x00254>
      at UIKit.UIApplication:Main <0x002da>
      at Commerce.iOS.Application:Main <0x00092>
      at <Module>:runtime_invoke_void_object <0x001a8>
=================================================================
The app has been terminated.
x

Regression?

No response

Known Workarounds

I've implemented my own GetHashCode https://github.com/unoplatform/uno.extensions/blob/450d19f8fd9d4c53f327e5ecddbeeb50f86b020f/src/Uno.Extensions.Reactive/Operators/FeedToListFeedAdapter.cs#L96

Configuration

Dev machine:

Mac:

Other information

No response

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

spouliot commented 2 years ago

@vargaz does that ring any bells to you It seems mono does not like the compiler generated GetHashCode ?!? thanks!

vargaz commented 2 years ago

Would need some kind of testcase to track this down.

marek-safar commented 2 years ago

C# records generate complex generic calls. @dr1rrb could you attach the compiled assembly or share what's record generated GetHashCode IL ?

dr1rrb commented 2 years ago

C# records generate complex generic calls. @dr1rrb could you attach the compiled assembly or share what's record generated GetHashCode IL ?

@marek-safar The source code is here https://github.com/unoplatform/uno.extensions/blob/450d19f8fd9d4c53f327e5ecddbeeb50f86b020f/src/Uno.Extensions.Reactive/Operators/FeedToListFeedAdapter.cs#L14 The issue occurs when I use one instance of this in a dictionary (and I remove the GetHashCode I've added to workaround the issue).

For the IL, it's a netstandard 2.0 library that is working on other platforms, that's why I sent your the whole app (with the magic of the linker ^^ - working and crashing), but here is what I get from ILSpy:

For the FeedToListFeedAdapter``1

.method public hidebysig virtual 
    instance int32 GetHashCode () cil managed 
{
    .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    // Method begins at RVA 0x7409
    // Header size: 1
    // Code size: 7 (0x7)
    .maxstack 8

    IL_0000: ldarg.0
    IL_0001: call instance int32 class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<class [System.Collections.Immutable]System.Collections.Immutable.IImmutableList`1<!T>, !T>::GetHashCode()
    IL_0006: ret
} // end of method FeedToListFeedAdapter`1::GetHashCode

For the FeedToListFeedAdapter``2

.method public hidebysig virtual 
    instance int32 GetHashCode () cil managed 
{
    .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
        01 00 00 00
    )
    // Method begins at RVA 0x76f0
    // Header size: 12
    // Code size: 109 (0x6d)
    .maxstack 3

    IL_0000: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<class [netstandard]System.Type>::get_Default()
    IL_0005: ldarg.0
    IL_0006: callvirt instance class [netstandard]System.Type class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::get_EqualityContract()
    IL_000b: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<class [netstandard]System.Type>::GetHashCode(!0)
    IL_0010: ldc.i4 -1521134295
    IL_0015: mul
    IL_0016: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<class Uno.Extensions.Reactive.IFeed`1<!TCollection>>::get_Default()
    IL_001b: ldarg.0
    IL_001c: ldfld class Uno.Extensions.Reactive.IFeed`1<!0> class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::'<Source>k__BackingField'
    IL_0021: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<class Uno.Extensions.Reactive.IFeed`1<!TCollection>>::GetHashCode(!0)
    IL_0026: add
    IL_0027: ldc.i4 -1521134295
    IL_002c: mul
    IL_002d: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<class [netstandard]System.Func`2<!TCollection, class [System.Collections.Immutable]System.Collections.Immutable.IImmutableList`1<!TItem>>>::get_Default()
    IL_0032: ldarg.0
    IL_0033: ldfld class [netstandard]System.Func`2<!0, class [System.Collections.Immutable]System.Collections.Immutable.IImmutableList`1<!1>> class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::'<ToImmutable>k__BackingField'
    IL_0038: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<class [netstandard]System.Func`2<!TCollection, class [System.Collections.Immutable]System.Collections.Immutable.IImmutableList`1<!TItem>>>::GetHashCode(!0)
    IL_003d: add
    IL_003e: ldc.i4 -1521134295
    IL_0043: mul
    IL_0044: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<valuetype Uno.Extensions.Reactive.Collections.ItemComparer`1<!TItem>>::get_Default()
    IL_0049: ldarg.0
    IL_004a: ldfld valuetype Uno.Extensions.Reactive.Collections.ItemComparer`1<!1> class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::'<ItemComparer>k__BackingField'
    IL_004f: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<valuetype Uno.Extensions.Reactive.Collections.ItemComparer`1<!TItem>>::GetHashCode(!0)
    IL_0054: add
    IL_0055: ldc.i4 -1521134295
    IL_005a: mul
    IL_005b: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<class Uno.Extensions.Collections.Tracking.CollectionAnalyzer`1<!TItem>>::get_Default()
    IL_0060: ldarg.0
    IL_0061: ldfld class Uno.Extensions.Collections.Tracking.CollectionAnalyzer`1<!1> class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::_analyzer
    IL_0066: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<class Uno.Extensions.Collections.Tracking.CollectionAnalyzer`1<!TItem>>::GetHashCode(!0)
    IL_006b: add
    IL_006c: ret
} // end of method FeedToListFeedAdapter`2::GetHashCode

You can find the assembly itself on nuget: https://www.nuget.org/packages/Uno.Extensions.Reactive/2.2.0-dev.8 (version dev.8 is the latest version with the bug, versions after include my workaround)

ivanpovazan commented 2 years ago

Hello @dr1rrb, I am trying to extract your use case into a reproducible (crashing) sample as @vargaz suggested.

Would it be possible for you to provide the instantiation of BindableListFeed which was causing the crash? Additionally, does this happen both in Debug and Release configurations?

dr1rrb commented 2 years ago

Yes the crash happen in both debug and release.

BTW, if it helps you, the source code of the app is here https://github.com/unoplatform/Uno.Samples/tree/master/reference/Uno.Extensions.Commerce (it's a sample app, you can pass the login page just by entering dummy content)

In the app source code, the crash is caused by this line: https://github.com/unoplatform/Uno.Samples/blob/d29881785845b484480fc0c125a210c1cc1d5c0b/reference/Uno.Extensions.Commerce/Commerce/ViewModels/DealsViewModel.cs#L23 in the DealsViewModel for which we generate a nested class BindableDealsViewModel which will instantiate the BindableListFeed directly in its constructor :

Favorites = new global::Uno.Extensions.Reactive.Bindings.BindableListFeed<Commerce.Business.Models.Product>(
    nameof(Favorites),
    vm.Favorites ?? throw new NullReferenceException("The list feed property 'Favorites' is null. Public feeds properties must be initialized in the constructor."),
    ctx);

FYI In the sample project, the generated source code can be found here: image

ivanpovazan commented 2 years ago

Commerce app crash repro

I have managed to reproduce the reported issue when using Xamarin iOS with legacy mono:

  1. Checkout the sample app
  2. Change version of referenced Uno.Extensions.* to 2.2.0-dev.8 in the *.props files
  3. Build and run the Commerce.iOS in VS for Mac 2022
  4. Perform some actions in the app: log in, add some items, etc

I get the following error on the simulator:

2022-07-28 19:46:08.933000+0200 Commerce.iOS[18142:400335] error: * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/ios/release/mono/mini/method-to-ir.c:7241, condition `is_ok (error)' not met, function:mono_method_to_ir, VAR 1 (TItem_REF) cannot be expanded in this context with 1 instantiations

With the same Managed stack trace:

=================================================================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`1:GetHashCode <0x0004a>
      at System.Collections.Generic.ObjectEqualityComparer`1:GetHashCode <0x000aa>
      at Uno.Extensions.Reactive.Operators.ListFeedToFeedAdapter`1:GetHashCode <0x0012c>
      at System.Collections.Generic.Dictionary`2:FindEntry <0x001e6>
      at System.Collections.Generic.Dictionary`2:TryGetValue <0x0008a>
      at Uno.Extensions.Reactive.Core.StateStore:GetOrCreateState <0x00392>
      at Uno.Extensions.Reactive.Core.SourceContext:GetOrCreateStateCore <0x00375>
      at Uno.Extensions.Reactive.Core.SourceContext:GetOrCreateListState <0x000fa>
      at Uno.Extensions.Reactive.Bindings.BindableListFeed`1:.ctor <0x00132>
      at BindableProductDetailsViewModel:.ctor <0x00752>

The error message

From the error message we can see that the issue occurs in the JIT compiler. To confirm the failure, we can also choose to target a device (if there is no actual testing device connected to the host we can choose iOS Build Only Device:Generic Device configuration in VS) instead of the simulator, which will make the compiler build the app in fullAOT mode. The AOT compilation should fail and the same error will be reported in the build phase.

@dr1rrb Could you please try this out and confirm?


Already fixed?

If this is the case, then this issue seems to be the same as https://github.com/dotnet/runtime/issues/57560, which was fixed for .NET6 but was not backported to mono repo. I have tried the similar-smaller repro sample (see below) on .NET7 and could not reproduce the failure I am getting on legacy mono. @vargaz @marek-safar should this issue be moved to the https://github.com/mono/mono ?

The smaller repro (on legacy mono)

  1. Create a brand new iOS app from the Single View App template in VisualStudio
  2. Replace the code from Main.cs with
using UIKit;
using System.Collections.Generic;
using System.Collections.Immutable;
using Uno.Extensions.Reactive;

namespace HelloWorld
{
    public class Application
    {
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            var dict = new Dictionary<object, int>();
            var listFeed = Feed
                .Async(async ct => new[] { new object() })
                .Select(list => list.ToImmutableList())
                .AsListFeed();
            var listFeedAsFeed = listFeed.AsFeed();
            var listFeedAsFeedAsListFeed = listFeedAsFeed.AsListFeed();
            var listFeedAsFeedAsListFeedAsFeed = listFeedAsFeedAsListFeed.AsFeed();

            var inserted = dict.TryGetValue(listFeedAsFeedAsListFeedAsFeed, out var existing)
                ? existing
                : (dict[listFeedAsFeedAsListFeedAsFeed] = 42);

            UIApplication.Main(args, null, typeof(AppDelegate));
        }
    }
}
  1. Add appropriate package references in the project file:
    <ItemGroup>
    <PackageReference Include="Uno.Extensions.Reactive" Version="2.2.0-dev.8" />
    <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0.0" />
    </ItemGroup>
dr1rrb commented 2 years ago

@dr1rrb Could you please try this out and confirm?

I do! When I try to build the "Commerce" sample app targeting a device (in release), the OAT fails:

1>  C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(235,3): error MT3001: Could not AOT the assembly '/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Uno.Extensions.Reactive.dll'
spouliot commented 2 years ago

@dr1rrb MT3001 is a catch-all error code of Xamarin.iOS when running the AOT compiler. Basically it means "we called the AOT compiler" but we can't find any output.

The most common case is that the AOT compiler crashed. Your build logs should have some trace of that crash. The Mac's Console.app should also have a crash report for the compiler.

ivanpovazan commented 2 years ago

The most common case is that the AOT compiler crashed. Your build logs should have some trace of that crash. The Mac's Console.app should also have a crash report for the compiler.

The build log in VisualStudio should have a line stating the cause of the failure. From what I described above that line should be something like:

2022-07-28 19:46:08.933000+0200 Commerce.iOS[18142:400335] error: * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/ios/release/mono/mini/method-to-ir.c:7241, condition `is_ok (error)' not met, function:mono_method_to_ir, VAR 1 (TItem_REF) cannot be expanded in this context with 1 instantiations

@dr1rrb it would be great if you could confirm this.

dr1rrb commented 2 years ago

@spouliot @ivanpovazan

Indeed, I didn't scroll the log enough:

1>  MTouch: 2022-08-02T10:45:57.3782861-04:00 - Logging messages
1>  /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch @/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/response-file.rsp "--setenv=MONO_GC_PARAMS=soft-heap-limit=512m,nursery-size=64m,evacuation-threshold=66,major=marksweep,concurrent-sweep" 
1>  Xamarin.iOS 15.10.0.5 (d17-2: 96b3edb6d) using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk
1>  AOT Compilation exited with code 134, command:
1>  MONO_PATH=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build /Library/Frameworks/Xamarin.iOS.framework/Versions/15.10.0.5/bin/arm64-darwin-mono-sgen --debug --llvm -O=gsharedvt -O=-float32 --aot=mtriple=arm64-ios,data-outfile=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/arm64/Uno.Extensions.Reactive.aotdata.arm64,static,asmonly,direct-icalls,full,readonly-value=ObjCRuntime.Runtime.Arch=i4/0,nodebug,dwarfdebug,msym-dir=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Msym,llvm-path=/Library/Frameworks/Xamarin.iOS.framework/Versions/15.10.0.5/LLVM/bin/,outfile=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/arm64/Uno.Extensions.Reactive.dll.s,llvm-outfile=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/arm64/Uno.Extensions.Reactive.dll-llvm.o /Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Uno.Extensions.Reactive.dll
1>  Mono Ahead of Time compiler - compiling assembly /Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Uno.Extensions.Reactive.dll
1>  AOTID 2604B0B2-C0F0-4563-CDC2-B9E379462159
1>  * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/ios/release/mono/mini/method-to-ir.c:7241, condition `is_ok (error)' not met, function:mono_method_to_ir, VAR 1 (TItem_REF) cannot be expanded in this context with 1 instantiations
1>  
1>C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(235,3): error MT3001: Could not AOT the assembly '/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Uno.Extensions.Reactive.dll'

So yes it's the same assertion that fails

dr1rrb commented 2 years ago

Hey @ivanpovazan I just tried to build the "Commerce Sample App" with the version "2.2.0-dev.70" (which contains my workaround for the GetHashCode) and I noticed that the build (release - device) also fails on the AOT step. But if I target an emulator (still in release, but without AOT), the build succeed ... and my original bug (crash at runtime) is fixed.

I'm wondering if it's not 2 different issues.

Any thoughts?

(Going to try with our "simple repro")

ivanpovazan commented 2 years ago

hey @dr1rrb, if it is failing with the same error message (mentioned above) in the fullAOT build - device build, then it is most likely the same issue. Regarding the simulator, it is a bit more difficult to trigger the actual call which causes the problem, so the AOT build should be your measuring (repro) point.

SamMonoRT commented 2 years ago

@ivanpovazan - other than backporting to mono\mono, does any more work remain for this for the dotnet/runtime repo for 7.0.0 ?

ivanpovazan commented 2 years ago

@SamMonoRT, I don't think so

SamMonoRT commented 2 years ago

No work remains for 7.0.0 @ivanpovazan will validate the fix on the mono\mono repo and close this issue.

dr1rrb commented 2 years ago

hey @dr1rrb, if it is failing with the same error message (mentioned above) in the fullAOT build - device build, then it is most likely the same issue. Regarding the simulator, it is a bit more difficult to trigger the actual call which causes the problem, so the AOT build should be your measuring (repro) point.

FYI, to workaround the build issue we do have on projects (including our sample "commerce app") I had to push my workaround further by converting my objects to class instead of record (and implement the GetHashCode and the Equals manually). So even if for me (which is not used to deal with that kind of issues) it's not "natural" that a runtime bug can be reproduced at build time with AOT, everything tends to show that you are right ... which is a good news 👍

Thanks for your support