Show function effects via specialised about call

This commit is contained in:
TEC 2024-04-29 20:28:08 +08:00
parent 1b563854d9
commit 04869e3b4c
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 4 additions and 4 deletions

View File

@ -56,11 +56,11 @@ function about(io::IO, fn::Function, @nospecialize(sig::Type{<:Tuple}))
for method in ms
println(io, " ", sprint(show, method, context=IOContext(io)))
end
print_effects(io, fn, sig)
println(io)
about(io, Base.infer_effects(fn, sig))
end
function print_effects(io::IO, fn::Function, @nospecialize(sig::Type{<:Tuple}))
effects = Base.infer_effects(fn, sig)
function about(io::IO, effects::Core.Compiler.Effects)
ATRUE, AFALSE = Core.Compiler.ALWAYS_TRUE, Core.Compiler.ALWAYS_FALSE
CNORETURN, CINACCESSIBLEMEM, EFINACCESSIBLEMEM, INACESSIBLEMEMARG, NOUBINBOUNDS =
Core.Compiler.CONSISTENT_IF_NOTRETURNED, Core.Compiler.CONSISTENT_IF_INACCESSIBLEMEMONLY,
@ -79,7 +79,7 @@ function print_effects(io::IO, fn::Function, @nospecialize(sig::Type{<:Tuple}))
NOUBINBOUNDS => styled"guaranteed ({italic:so long as {code,julia_macro:@inbounds} is not used or propagated}) to"),
t, styled"???")
hedge(b::Bool) = hedge(ifelse(b, ATRUE, AFALSE))
println(io)
println(io, styled"{bold:Method effects:}")
for (effect, description) in
[(:consistent, "return or terminate consistently"),
(:effect_free, "be free from externally semantically visible side effects"),