corert icon indicating copy to clipboard operation
corert copied to clipboard

CoreRT Stack overflow when build with EntityFrameworkCore

Open hez2010 opened this issue 5 years ago • 12 comments

CoreRT Stack overflow when build with EntityFrameworkCore

Repro:

Create project:

dotnet new web
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.DotNet.ILCompiler  --Version=1.0.0-*

And then add an empty DbContext:

using Microsoft.EntityFrameworkCore;
public class TestDbContext : DbContext { }

Build (with ilcarg: --verbose --singlethreaded):

dotnet publish -c Debug -r win-x64

Result:

  ......
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Remove<__Canon>(__Canon)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Update<__Canon>(__Canon)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Attach<__Canon>(__Canon)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.AddAsync<__Canon>(__Canon,CancellationToken)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Add<__Canon>(__Canon)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.SetEntityStateAsync(InternalEntityEntry,EntityState,CancellationToken)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.SetEntityState(InternalEntityEntry,EntityState)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.EntryWithoutDetectChanges(object)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Entry(object)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.EntryWithoutDetectChanges<__Canon>(__Canon)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Entry<__Canon>(__Canon)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.DisposeAsync()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.DisposeSync()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Dispose()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.GetResettableServices()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IResettableService.ResetStateAsync(CancellationToken)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IResettableService.ResetState()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextPoolable.Resurrect(DbContextPoolConfigurationSnapshot)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextPoolable.SnapshotConfiguration()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextPoolable.SetPool(IDbContextPool)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(bool,CancellationToken)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(CancellationToken)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges(EntityEntry)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.SaveChanges(bool)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.SaveChanges()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.OnModelCreating(ModelBuilder)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(DbContextOptionsBuilder)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.CheckDisposed()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Finder(Type)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Query<__Canon>()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Set<__Canon>()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbSetCache.GetOrAddSet(IDbSetSource,Type)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_InfrastructureLogger()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_UpdateLogger()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_EntityGraphAttacher()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_ChangeDetector()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_StateManager()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_QueryProvider()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_EntityFinderFactory()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_SetSource()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.get_ContextId()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.get_Model()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.get_ChangeTracker()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext.get_Database()...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions)...
  Compiling [Microsoft.EntityFrameworkCore]Microsoft.EntityFrameworkCore.DbContext..ctor()...
  Compiling object.GetHashCode()...
  Compiling object.ReferenceEquals(object,object)...
  Compiling object.Equals(object,object)...
  Compiling object.Equals(object)...
  Compiling object.ToString()...
  Compiling object.Finalize()...
  Compiling object..ctor()...
  Compiling object.GetRawDataSize()...
  Compiling object.MemberwiseClone()...
  Compiling object.get_EETypePtr()...
  Compiling object.GetType()...
  Compiling [S.P.CoreLib]System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs..ctor(Exception)...
  Compiling [S.P.CoreLib]System.Exception.get_HResult()...
  Compiling string.GetPinnableReference()...
  Compiling [S.P.CoreLib]System.Exception.GetType()...
  Compiling [S.P.CoreLib]System.Exception.AppendStackIP(native int,bool)...
  Compiling native int.op_Inequality(native int,native int)...
  Compiling [S.P.CoreLib]System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*,native int)...
  Compiling [S.P.CoreLib]Internal.Diagnostics.StackTraceHelper+SpecialIP..cctor()...
  Compiling [S.P.CoreLib]System.Environment.FailFast(string)...
  Compiling [S.P.CoreLib]System.DataMisalignedException..ctor()...
  Compiling [S.P.CoreLib]System.SystemException..ctor()...
  Compiling [S.P.CoreLib]System.SystemException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.DataMisalignedException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.RuntimeExceptionHelpers.FailFast(string)...
  Compiling [S.P.CoreLib]System.NullReferenceException..ctor()...
  Compiling [S.P.CoreLib]System.NullReferenceException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.OverflowException..ctor()...
  Compiling [S.P.CoreLib]System.OverflowException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.InvalidCastException..ctor()...
  Compiling [S.P.CoreLib]System.InvalidCastException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.IndexOutOfRangeException..ctor()...
  Compiling [S.P.CoreLib]System.IndexOutOfRangeException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.DivideByZeroException..ctor()...
  Compiling [S.P.CoreLib]System.DivideByZeroException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.ArrayTypeMismatchException..ctor()...
  Compiling [S.P.CoreLib]System.ArrayTypeMismatchException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.ArithmeticException..ctor()...
  Compiling [S.P.CoreLib]System.ArithmeticException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.OutOfMemoryException..ctor()...
  Compiling [S.P.CoreLib]System.OutOfMemoryException..ctor(SerializationInfo,StreamingContext)...
  Compiling [S.P.CoreLib]System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnThreadStaticBase(TypeManagerSlot*,int32,StaticClassConstructionContext*)...
  Compiling [S.P.CoreLib]Internal.Runtime.ThreadStatics.GetThreadStaticBaseForType(TypeManagerSlot*,int32)...
  Compiling [S.P.CoreLib]System.RuntimeExceptionHelpers..cctor()...
  Compiling [S.P.CoreLib]System.RuntimeExceptionHelpers.FailFast(string,Exception,RhFailFastReason,native int,native int)...
  Compiling string.Format(string,object,object,object)...
  Compiling [S.P.CoreLib]System.RuntimeExceptionHelpers.GetStringForFailFastReason(RhFailFastReason)...
  Compiling [S.P.CoreLib]System.PreallocatedOutOfMemoryException.get_Instance()...
  Compiling [S.P.CoreLib]System.RuntimeExceptionHelpers.get_SafeToPerformRichExceptionSupport()...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetV(object,native int,ArgSetupState&,bool)...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetVI<int64>(object,native int,ArgSetupState&,bool)...
  Compiling [S.P.CoreLib]System.Runtime.InteropServices.NativeCallableAttribute..ctor()...
  Compiling [S.P.CoreLib]System.Runtime.CalliIntrinsics.CallVoid(native int)...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetVII<native int,native int>(object,native int,ArgSetupState&,bool)...
  Compiling [S.P.CoreLib]System.Threading.Thread.InitializeComForFinalizerThread()...
  Compiling [S.P.CoreLib]System.Runtime.CastableObjectSupport.GetCastableObjectDispatchCellThunk(EEType*,native int)...
  Compiling [S.P.CoreLib]System.Runtime.CachedInterfaceDispatch.RhpCidResolve_Worker(object,native int)...
  Compiling native int.op_Equality(native int,native int)...
  Compiling [S.P.CoreLib]System.Runtime.CachedInterfaceDispatch.RhResolveDispatchWorker(object,void*,DispatchCellInfo&)...
  Compiling [S.P.CoreLib]System.Runtime.DispatchResolve.FindInterfaceMethodImplementationTarget(EEType*,EEType*,uint16)...
  Compiling [S.P.CoreLib]System.Runtime.InternalCalls.RhpSignalFinalizationComplete()...
  Compiling [S.P.CoreLib]System.Runtime.__Finalizer.DrainQueue()...
  Compiling [S.P.CoreLib]System.Runtime.__Finalizer.MakeFinalizerInitCallbacks()...
  Compiling [S.P.CoreLib]System.Runtime.InternalCalls.RhpWaitForFinalizerRequest()...
  Compiling [S.P.CoreLib]System.Runtime.EH+ExInfo.Init(object,bool)...
  Compiling [S.P.CoreLib]System.Runtime.EH.GetClasslibException(ExceptionIDs,native int)...
  Compiling [S.P.CoreLib]System.Runtime.EH.DispatchEx(StackFrameIterator&,ExInfo&,uint32)...
  Compiling [S.P.CoreLib]System.Runtime.EH+ExInfo.Init(object,ExInfo&)...
  Compiling [S.P.CoreLib]System.Runtime.EH+ExInfo.get_ThrownException()...
  Compiling [S.P.CoreLib]System.Runtime.InternalCalls.RhpCollect(int32,InternalGCCollectionMode)...
  Compiling [S.P.CoreLib]System.Runtime.InternalCalls.RhpGetGcTotalMemory()...
  Compiling [S.P.CoreLib]System.Runtime.InternalCalls.RhpStartNoGCRegion(int64,bool,int64,bool)...
  Compiling [S.P.CoreLib]System.Runtime.InternalCalls.RhpEndNoGCRegion()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.GetAssociatedModuleAddress()...
  Compiling [S.P.CoreLib]System.Runtime.CastableObjectSupport.GetCastableTargetIfPossible(ICastableObject,EEType*,bool,Exception&)...
  Compiling [S.P.CoreLib]System.Runtime.EH.FallbackFailFast(RhFailFastReason,object)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerServices.Unsafe.As<native int,__Canon>(native int&)...
  Compiling native int.op_Addition(native int,int32)...
  Compiling [S.P.CoreLib]Internal.Runtime.TransitionBlock.GetThisOffset()...
  Compiling [S.P.CoreLib]System.Runtime.CastableObjectSupport..cctor()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsFinalizable()...
  Compiling [S.P.CoreLib]System.Runtime.RuntimeExports.UnboxAnyTypeCompare(EEType*,EEType*)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_HasGCPointers()...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerServices.Unsafe.Add<uint8>(uint8&,int32)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_NullableValueOffset()...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerServices.Unsafe.As<uint8,bool>(uint8&)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_ValueTypeFieldPadding()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_BaseSize()...
  Compiling [S.P.CoreLib]System.Runtime.RuntimeExports+Wrapper..ctor()...
  Compiling object.GetRawData()...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerServices.Unsafe.As<__Canon>(object)...
  Compiling [S.P.CoreLib]System.EETypePtr..ctor(native int)...
  Compiling native int.op_Explicit(void*)...
  Compiling [S.P.CoreLib]System.Runtime.EH.FailFastViaClasslib(RhFailFastReason,object,native int)...
  Compiling [S.P.CoreLib]System.Runtime.RuntimeExports.RhpGetCurrentThreadStackTrace(native int*,uint32)...
  Compiling [S.P.CoreLib]System.Runtime.StackFrameIterator.Next()...
  Compiling native int..ctor(void*)...
  Compiling [S.P.CoreLib]System.Runtime.StackFrameIterator.get_ControlPC()...
  Compiling [S.P.CoreLib]System.Runtime.StackFrameIterator.Init(PAL_LIMITED_CONTEXT*,bool)...
  Compiling native uint..ctor(uint64)...
  Compiling native uint.op_Explicit(native uint)...
  Compiling native uint.op_Explicit(void*)...
  Compiling [S.P.CoreLib]System.Runtime.ThunksHeap.CreateThunksHeap(native int)...
  Compiling [S.P.CoreLib]System.Runtime.ThunksHeap.AllocateThunk()...
  Compiling [S.P.CoreLib]System.Runtime.ThunksHeap.FreeThunk(native int)...
  Compiling [S.P.CoreLib]System.Runtime.ThunksHeap.SetThunkData(native int,native int,native int)...
  Compiling [S.P.CoreLib]System.Runtime.ThunksHeap.TryGetThunkData(native int,native int&,native int&)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_NonClonedNonArrayBaseType()...
  Compiling [S.P.CoreLib]Internal.Runtime.WellKnownEETypes.IsSystemArray(EEType*)...
  Compiling [S.P.CoreLib]Internal.Runtime.WellKnownEETypes.IsSystemObject(EEType*)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_HasGenericVariance()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_CanonicalEEType()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsCloned()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.SimpleCasting()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_RawBaseType()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.BothSimpleCasting(EEType*,EEType*)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_ArrayRank()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsSzArray()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_ParameterizedTypeShape()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_NullableType()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsNullable()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsGenericTypeDefinition()...
  Compiling [S.P.CoreLib]System.Runtime.TypeCast.IsInstanceOfInterfaceViaCastableObjectWithException(object,EEType*,Exception&)...
  Compiling [S.P.CoreLib]System.Runtime.TypeCast+CastCache.AreTypesAssignableInternal_SourceNotTarget_BoxedSource(EEType*,EEType*,EETypePairList*)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsValueType()...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerServices.Unsafe.Add<native int>(native int&,int32)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerServices.Unsafe.As<uint8,native int>(uint8&)...
  Compiling [S.P.CoreLib]System.Runtime.TypeCast.IsInstanceOfInterfaceViaCastableObject(object,EEType*)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsICastable()...
  Compiling [S.P.CoreLib]System.Runtime.TypeCast+CastCache.AreTypesAssignableInternal(EEType*,EEType*,AssignmentVariation,EETypePairList*)...
  Compiling [S.P.CoreLib]System.Array.get_Length()...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerServices.Unsafe.Add<__Canon>(__Canon&,int32)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerServices.Unsafe.As<uint8,__Canon>(uint8&)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.GetClasslibException(ExceptionIDs)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_RelatedParameterType()...
  Compiling object.get_EEType()...
  Compiling native int.op_Explicit(native int)...
  Compiling [S.P.CoreLib]System.Runtime.TypeCast.AreTypesEquivalentInternal(EEType*,EEType*)...
  Compiling [S.P.CoreLib]System.EETypePtr.ToPointer()...
  Compiling [S.P.CoreLib]System.Runtime.TypeCast.CheckCastNonArrayParameterizedType(void*,object)...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsParameterizedType()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsInterface()...
  Compiling [S.P.CoreLib]Internal.Runtime.EEType.get_IsArray()...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.StartupCodeHelpers.InitializeEagerClassConstructorsForModule(TypeManagerHandle)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.StartupCodeHelpers.AddModule(TypeManagerHandle)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.StartupCodeHelpers.InitializeGlobalTablesForModule(TypeManagerHandle,int32)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowIndexOutOfRangeException()...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.StartupCodeHelpers.CreateTypeManagers(native int,native int*,int32,native int*,int32)...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetOI<float64,int32>(object,native int,ArgSetupState&,bool)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.MathHelpers.ThrowUIntOvf()...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetOI<float64,uint32>(object,native int,ArgSetupState&,bool)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.MathHelpers.ThrowLngOvf()...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetOI<float64,int64>(object,native int,ArgSetupState&,bool)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.MathHelpers.ThrowULngOvf()...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetOI<float64,uint64>(object,native int,ArgSetupState&,bool)...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetOI<float32,int32>(object,native int,ArgSetupState&,bool)...
  Compiling [S.P.CoreLib]Internal.Runtime.CompilerHelpers.MathHelpers.ThrowIntOvf()...
  Compiling [S.P.CompilerGenerated]Internal.CompilerGenerated.<Module>.InvokeRetOI<float32,int64>(object,native int,ArgSetupState&,bool)...
  
  Process is terminating due to StackOverflowException.

hez2010 avatar Mar 23 '20 13:03 hez2010

EntityFrameworkCore has infinite generic expansion here in ExecuteImplementation and ExecuteImplementationAsync methods. These two methods call themselves with different generic arguments. It makes them unfriendly to AOT compilation, and incompatible with full AOT compilation.

https://github.com/dotnet/efcore/blob/master/src/EFCore/Storage/ExecutionStrategy.cs#L183

jkotas avatar Mar 23 '20 15:03 jkotas

@jkotas AFAIK EF Core did work with UWP though?

Suchiman avatar Mar 23 '20 15:03 Suchiman

.NET Native for UWP used universal shared generics to handle these cases. The code worked, but run number of times slower. Universal shared generics are not really full AOT compilation.

jkotas avatar Mar 23 '20 16:03 jkotas

Note that the infinite generic expansion does not work too well with CoreCLR partial AOT either: crossgen will try to compile several expansions (that is usually a lot more than what is actually required) and eventually gives up.

jkotas avatar Mar 23 '20 16:03 jkotas

Ah, interesting trick, is there an easy of finding the source of these generic expansion issues? I've tried it with DependencyViewer last time around but got lost.

Suchiman avatar Mar 23 '20 16:03 Suchiman

I diagnose these by looking at the stacktrace of the stackoverflow, and then correlate it with sources. I agree that it would be nice to have better diagnostics for this in the compiler - https://github.com/dotnet/corert/issues/363

jkotas avatar Mar 23 '20 16:03 jkotas

Marking this as up-for-grabs. This should be fixed by submitting PR to EFCore that removes the recursive call in ExecuteImplementation/ExecuteImplementationAsync.

jkotas avatar Mar 23 '20 16:03 jkotas

@jkotas Per discussion a few weeks back with Hunter, any AOT solution needs to handle real .NET code including EF Core, not just a limited subset of simpler .NET code.

ajcvickers avatar Mar 24 '20 14:03 ajcvickers

@ajcvickers We have an ongoing discussion on this topic and the answer is more nuanced than this.

jkotas avatar Mar 24 '20 15:03 jkotas

With this kind of generic thing or generic reflection thing. Auto detect at compile time what generics run into this infinite expansion PLUS for dynamically created generics using runtime reflection just don't AOT them directly. You could just dynamically generate the memory at runtime similar to the .NET JIT for whats needed in the generic. Stuff will no longer inline maybe but it might solve the issue.

Would this kind of thing solve the issue?

zezba9000 avatar Apr 26 '20 23:04 zezba9000

dynamically generate the memory at runtime

How is it different from just having JIT?

jkotas avatar Apr 27 '20 05:04 jkotas

Its not really but unless I'm missing something, .NET having generics done the way it did (by putting them in the IL instead of letting langs compile them out to standard objects like Java) either means you have dynamic code generation for them or you add a Syntax Analyzer for CoreRT and disable / give compiler errors for problematic generics and give runtime errors for generic object creation using reflection.

Or I just saw that I missed the post about "universal shared generics" which I'm guessing is having the generic objects compile out using dynamic types for generic parameters of some kind?

Maybe its just me but designing APIs around reflection to generate generic objects isn't something other langs / runtimes can even do and I don't see people complaining about it. Having the minority of people update their code based to run on what could be considered a .NET runtime subset is a good enough solution for 99% of code out there?

Someone had linked this on Twitter so just got me thinking is all.

zezba9000 avatar Apr 27 '20 05:04 zezba9000