KT
Size: a a a
KT
KT
foo(a, :: Nothing) = foo(a)
VG
KT
Base.string(x :: Nothing) = ""KT
AK
VG
VG
V
VG
@code_typedэто не выглядит как нестабильный тип:
%4 = invoke Main.Val(%3::Symbol)::Val{_A} where _AVG
function f(x::String)
f2(Val(Symbol(x)))
end
f2(::Val) = 0
f2(::Val{:somesymbol}) = 1
f2(::Val{:othersymbol}) = 2
@code_typed f("somesymbol")
VG
CodeInfo(
1 ─ %1 = $(Expr(:foreigncall, :(:jl_string_ptr), Ptr{UInt8}, svec(Any), 0, :(:ccall), :(x)))::Ptr{UInt8}
│ %2 = Core.sizeof(x)::Int64
│ %3 = $(Expr(:foreigncall, :(:jl_symbol_n), Ref{Symbol}, svec(Ptr{UInt8}, Int64), 0, :(:ccall), :(%1), :(%2), :(%2), :(%1)))::Symbol
│ %4 = invoke Main.Val(%3::Symbol)::Val{_A} where _A
│ %5 = (isa)(%4, Val{:othersymbol})::Bool
└── goto #3 if not %5
2 ─ goto #6
3 ─ %8 = (isa)(%4, Val{:somesymbol})::Bool
└── goto #5 if not %8
4 ─ goto #6
5 ─ %11 = Main.f2(%4)::Int64
└── goto #6
6 ┄ %13 = φ (#2 => 2, #4 => 1, #5 => %11)::Int64
└── return %13
) => Int64
V
VG
@code_warntype в обоих случаях выделяет краснымV
V
VG
VG
VG
V