dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.

Home Page:http://dot.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enumerable.OrderBy does not work in reflection-free mode.

Thealexbarney opened this issue · comments

Given this example code, the numbers should be printed in ascending order.

using System;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] unsorted = { 5, 257, 66, 6 };

            foreach (int val in unsorted.OrderBy(x => x))
            {
                Console.WriteLine(val);
            }
        }
    }
}

A default CoreRT build will print the sorted numbers.

5
6
66
257

However, the following is printed in reflection-free mode.

5
257
66
6

I would have to debug this, but it's possibly related to the the fact that we disable the default comparers logic in reflection free mode right now.

<!-- Comparers don't currently work with reflection disabled. https://github.com/dotnet/corert/pull/7208 -->
<IlcArg Condition="$(IlcDisableReflection) == 'true'" Include="--removefeature:Comparers" />

Not quite sure why the fallback wouldn't work though.

Also the reasons why we had to disable them in the first place probably don't exist anymore, but enabling them will be a size regression. Comparer<Foo>.Default is basically reflection right now.