Repository: JuliaLang/julia
File: Compiler/src/verifytrim.jl (Julia)

Code before:
            end
        end
    end
    return (errors, parents)
end

# It is unclear if this file belongs in Compiler itself, or should instead be a codegen
# driver / verifier implemented by juliac-buildscript.jl for the purpose of extensibility.
# For now, it is part of Base.Compiler, but executed with invokelatest so that packages
# could provide hooks to change, customize, or tweak its behavior and heuristics.
function verify_typeinf_trim(io::IO, codeinfos::Vector{Any}, onlywarn::Bool)
    errors, parents = get_verify_typeinf_trim(codeinfos)

    # count up how many messages we printed, of each severity
    counts = [0, 0] # errors, warnings
    io = IOContext{IO}(io)
    # print all errors afterwards, when the parents map is fully constructed
    for desc in errors
        warn, desc = desc
        severity = warn ? 2 : 1
        no = (counts[severity] += 1)
        if warn
            printstyled(io, "Verifier warning #", no, ": "; color=Base.warn_color(), bold=true)
        else
            printstyled(io, "Verifier error #", no, ": "; color=Base.error_color(), bold=true)
        end
        # TODO: should we coalesce any of these stacktraces to minimize spew?
        verify_print_error(io, desc, parents, warn)
    end

    ## TODO: compute and display the minimum and/or full call graph instead of merely the first parent stacktrace?
    #for i = 1:length(codeinfos)
    #    item = codeinfos[i]
    #    if item isa CodeInstance
    #        println(item, "::", item.rettype)
    #    end
    #end

    let severity = 0
        if counts[1] > 0 || counts[2] > 0
            print(io, "Trim verify finished with ")
            if counts[1] > 0
                printstyled(io, counts[1], counts[1] == 1 ? " error" : " errors"; color=Base.error_color(), bold=true)
            else
                print(io, counts[1], counts[1] == 1 ? " error" : " errors")
            end
            print(io, ", ")
            if counts[2] > 0
                printstyled(io, counts[2], counts[2] == 1 ? " warning" : " warnings"; color=Base.warn_color(), bold=true)
            else
                print(io, counts[2], counts[2] == 1 ? " warning" : " warnings")

Review comment (suggestion):
```suggestion
        printstyled(io, "Problem #", no, ": "; color=Base.warn_color(), bold=true)
```

The index is shared but these are counted separately, so changing between "error" / "warning" seems a bit confusing to me

Code after:
    #for i = 1:length(codeinfos)
    #    item = codeinfos[i]
    #    if item isa CodeInstance
    #        println(item, "::", item.rettype)
    #    end
    #end

    let severity = 0
        if counts[1] > 0 || counts[2] > 0
            print(io, "Trim verify finished with ")
            if counts[1] > 0
                printstyled(io, counts[1], counts[1] == 1 ? " error" : " errors"; color=Base.error_color(), bold=true)
            else
                print(io, counts[1], counts[1] == 1 ? " error" : " errors")
            end
            print(io, ", ")
            if counts[2] > 0
                printstyled(io, counts[2], counts[2] == 1 ? " warning" : " warnings"; color=Base.warn_color(), bold=true)
            else
                print(io, counts[2], counts[2] == 1 ? " warning" : " warnings")
            end
            print(io, ".\n")
            severity = 2
        end
        if counts[1] > 0
            severity = 1
        end
        # messages classified as errors are fatal, warnings are not
        0 < severity <= 1 && !onlywarn && throw(Core.TrimFailure())
    end
    nothing
end