4 ms·
Try Julia nightly (1.7): julia> @code_warntype not_type_stable() MethodInstance for not_type_stable() from not_type_stable() in Main at REPL[2]:1 Arg
by celrod 5y ago
Try Julia nightly (1.7):
julia> @code_warntype not_type_stable()
MethodInstance for not_type_stable()
from not_type_stable() in Main at REPL[2]:1
Arguments
#self#::Core.Const(not_type_stable)
Locals
o::Any
Body::Int64
1 ─ (o = Main.returns_option())
│ %2 = Main.isnothing(o)::Bool
└── goto #3 if not %2
2 ─ return 0
3 ─ return 1
julia> versioninfo()
Julia Version 1.7.0-DEV.1169
Commit e5d7ef01b0* (2021-05-26 14:17 UTC)
Note `Body::Int64`.
With older Julia versions, it should still be type stable if you did `o === nothing` instead of `isnothing(o)`.
- hexane360 5y agoRight, I'm referring to the local o being Any, meaning that it must be behind a pointer lookup. I should have clarified because the more common usage is about the function's return value.