magic
magic copied to clipboard
can't even farm out simple generic array ops
We should have a good intrinsic story for array operations, but it sounds like that might take a little while. An obvious stopgap until we can get that is to farm out the most basic array operations to a c# class that can at least preserve type information so we don't have to spastically box stuff:
using System;
namespace ArcadiaHacks
{
public static class ArrayHelper
{
public static T aget<T> (T[] arr, int i)
{
return arr[i];
}
public static T aset<T> (T[] arr, int i, T val)
{
arr[i] = val;
return val;
}
}
}
Even this innocuous class doesn't work well with magic, however:
(def float-ar (float-array 10))
(ArrayHelper/aget float-ar 0)
;; crashes unity!
(ArrayHelper/aget (type-args |System.Single|) float-ar 0)
;; returns 0.0: the correct behavior
(m/faster
(let [^|System.Single[]| float-ar float-ar]
(ArrayHelper/aget (type-args |System.Single|) float-ar 0)))
;; throws error
(m/faster
(let [^|System.Single[]| float-ar float-ar]
(ArrayHelper/aget float-ar 0)))
;; throws error
(m/faster
(let [^|System.Single[]| float-ar float-ar]
(ArrayHelper/aget float-ar (int 0))))
;; throws error
(m/faster
(let [^|System.Single[]| float-ar float-ar]
(ArrayHelper/aget (type-args |System.Single|) float-ar (int 0))))
;; throws error
Even if we find some other approach to arrays, these methods should work. If they don't, other stuff won't either.