Is it possible to do array lookup at compile time, that is, fully evaluated in macros? When generating functions, known variables can be interpolated all the way to the compiler:
x = 0
f = eval(:(y -> $x*y))
> @code_llvm f(1)
> ; @ REPL[4]:1 within `#3`
> define i64 @"julia_#3_151"(i64 signext %0) #0 {
> top:
> **ret** i64 0
> }
Also known tuples:
x = (0,1,2)
f = eval(:(y -> $x[1]*y))
@code_llvm f(1)
> ; @ REPL[7]:1 within `#5`
> define i64 @"julia_#5_168"(i64 signext %0) #0 {
> top:
> **ret** i64 0
> }
But not known arrays:
x = [0,1,2]
f = eval(:(y -> $x[1]*y))
@code_llvm f(1)
> ; @ REPL[10]:1 within `#7`
> define i64 @"julia_#7_170"(i64 signext %0) #0 {
> top:
> ; ┌ @ array.jl:861 within `getindex`
> %1 = **load** i64, i64* getelementptr ({ i8*, i64, i16, i16, i32 }, { i8*, i64, i16, i16, i32 }* inttoptr (i64 4561887056 to { i8*, i64, i16, i16, i32 }*), i64 0, i32 1), align 8
...