Is there a way to hook into the IL post-processing (Mono Cecil) system to make some changes to the code before Burst? I have an idea for how to support a limited form of IEnumerator-based coroutines (eg yield return) in Jobs, but it requires that I modify the generated class to be a struct, check its size, and generate some unsafe casts to/from the expected type.
It might not work, but at least it’s worth a try. But the first step is to get at that IL in a supported way.
It works in .NET (kinda… for a limited definition of “works”). If I can figure out how to add a post-processing step, we can have native coroutines like this:
using System;
using System.Collections.Generic;
namespace burningmime.unity.enumerator
{
public class Program
{
public static void Main(string[] args)
{
NativeEnumerator<int> e = NativeEnumerator.Wrap(new MyEnumerable());
while(e.MoveNext())
Console.WriteLine(e.Current);
e.Dispose();
}
}
public struct MyEnumerable : INativeEnumerable
{
public IEnumerator<int> GetEnumerator()
{
yield return // ....
}
}
}
(proof of concept, doesn’t actually work like that: https://gitlab.com/burningmime/native-enumerable )