Hello,
i am trying to write something like Petite Zygote by manipulating Core.Compiler.IRCode to get sense, how it works. I am considering that as a part of survey, if I should show it to students, where the compiler infrastructure is heading. But not sure I will succeed. I also do not know, if it is better to ask here on discourse.
Anyway, here is my question.
Let’s say I have a function
function foo(x,y)
z = x * y
z + sin(x)
end
and its IRCode
2 1 ─ %1 = (_2 * _3)::Float64 │
3 │ %2 = Main.sin(_2)::Float64 │
│ %3 = (%1 + %2)::Float64 │
└── return %3 │
I transform it to
2 1 ─ %1 = rrule(Main.:*, _2, _3)::Any │
│ %2 = getindex(%1, 1)::Any │
│ getindex(%1, 2)::Any │
3 │ %4 = rrule(Main.sin, _2)::Any │
│ %5 = getindex(%4, 1)::Any │
│ getindex(%4, 2)::Any │
│ %7 = rrule(Main.:+, %2, %5)::Any │
│ %8 = getindex(%7, 1)::Any │
│ getindex(%7, 2)::Any │
└── return %8 │
Where I set all types to Any. Is there some function, which will perform type inference given I know types of arguments? If not, how I can perform type inference manually? The trouble is that I know the function to be called by Core.GlobalRef and not by their type used by Base.code_ircode which I wanted to use to give me the return type.
Thanks for answers in advance.
I posted this originally on slack. I am moving the discussion to here, such that it is archived. I will post below the important answers and clearly denote the authors, since obviously I cannot post it on their behalf.