Using @code_warntype to inspect my module functions


I am wondering what or how is the best way to use @code_warntype to inspect my code for type instabilities. To give you some context, I am working in a script file (.jl) and doing using MyCustomModule at the top to bring in some structs and methods I have written. Also, I am using VsCode with the Julia extension.

I want to step through the methods I have defined and try to find places where I might have created type instabilities. What I have tried thus far to do is have a line like this in my script (not all methods are exported) and run it interactively by highlighting it and pressing Shift+Enter. The output is sent to the REPL. .

@code_warntype MyCustomModule.SomeMethod

Regardless of which method I use the macro on though, I seem to only ever get back the following (below) and I assume I must be doing something wrong.


1 ─ %1 = Base.getfield(x, f)::Any
└──      return %1

I would appreciate any tips on how I could use this correctly.

You have to call the function. @code_warntype foo(1,2). Also you might want to try JET.@report_opt f(1,2).

Ah okay - Thank you, and also I did not know about JET.jl. I will definitely check that out.

So my problem now is that some of my functions are nested in other functions. I was hoping I could enter the top function via the debugger and then run @code_warntype NestedFunction(Inputs) from the debugger console while inside my top level function but that doesn’t seem to work.

Actually I take that back. At least for the function I am currently trying, @code_warntype seems to evaluate fine but it returns nothing. I wonder if that means my function is too complex.