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.