Identifying type stability
In the preceding pos function, the type instability was found by reading and understanding the code. In many cases where the code is longer or more complicated, it may not be easy or even possible to understand the type behavior of a function merely by inspection. It would be useful to have some tools at our disposal.
Fortunately, Julia provides the @code_warntype macro, which enables us to view the types inferred by the compiler, thereby identifying any type instability in our code. The output of @code_warntype is the lowered, type-inferred abstract syntax tree (AST) structure. In other words, the compiler parses and processes the source code into a standardized form and then runs the type inference on the result ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access