From 3cebafab4653068e35e2b82528ee625de049f22e Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 23 Dec 2019 16:03:00 -0800 Subject: [PATCH] Avoid infinite generics recursion in SynchronizationContextScheduler The infinitive generics recursion interacts poorly with AOT. The AOT compilers have hard figuring out where the stop generating the code for generics with infinite recursion. They either fail or produce large images by giving up once the generics get too complex. This change reverts a small part of #500 that introduced infinite generic recursion and adds comment. Fixes https://github.com/dotnet/corert/issues/7920 --- .../Concurrency/SynchronizationContextScheduler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/SynchronizationContextScheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/SynchronizationContextScheduler.cs index bce28477be..3c00774b1a 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/SynchronizationContextScheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/SynchronizationContextScheduler.cs @@ -93,7 +93,8 @@ public override IDisposable Schedule(TState state, TimeSpan dueTime, Fun return Schedule(state, action); } - return DefaultScheduler.Instance.Schedule((scheduler: this, action, state), dt, (_, tuple) => tuple.scheduler.Schedule(tuple.state, tuple.action)); + // Note that avoiding closure allocation here would introduce infinite generic recursion over the TState argument + return DefaultScheduler.Instance.Schedule(state, dt, (_, state1) => Schedule(state1, action)); } } }