diff --git a/src/JET.jl b/src/JET.jl index 936488433..e88d84972 100644 --- a/src/JET.jl +++ b/src/JET.jl @@ -215,7 +215,7 @@ struct JETConfigError <: Exception JETConfigError(msg::AbstractString, key::Symbol, val) = (@nospecialize msg val; new(msg, key, val)) end -Base.showerror(io::IO, err::JETConfigError) = print(io, "JETConfigError: ", err.msg) +Base.showerror(io::IO, err::JETConfigError) = print(depth_lim_cxt(io), "JETConfigError: ", err.msg) # utils # ----- @@ -615,7 +615,7 @@ function analyze_and_report_call!(analyzer::AbstractAnalyzer, @nospecialize(tt:: validate_configs(analyzer, jetconfigs) analyzer, result = analyze_gf_by_type!(analyzer, tt) analyzername = nameof(typeof(analyzer)) - sig = LazyPrinter(io::IO->Base.show_tuple_as_call(io, Symbol(""), tt)) + sig = LazyPrinter(io::IO->Base_show_tuple_as_call(io, Symbol(""), tt)) source = lazy"$analyzername: $sig" return JETCallResult(result, analyzer, source; jetconfigs...) end @@ -624,7 +624,7 @@ function analyze_and_report_call!(analyzer::AbstractAnalyzer, mi::MethodInstance validate_configs(analyzer, jetconfigs) analyzer, result = analyze_method_instance!(analyzer, mi) analyzername = nameof(typeof(analyzer)) - sig = LazyPrinter(io::IO->Base.show_tuple_as_call(io, Symbol(""), mi.specTypes)) + sig = LazyPrinter(io::IO->Base_show_tuple_as_call(io, Symbol(""), mi.specTypes)) source = lazy"$analyzername: $sig" return JETCallResult(result, analyzer, source; jetconfigs...) end @@ -642,7 +642,7 @@ function find_single_match(@nospecialize(tt), analyzer::AbstractAnalyzer) end @noinline function single_match_error(@nospecialize tt) - sig = LazyPrinter(io::IO->Base.show_tuple_as_call(io, Symbol(""), tt)) + sig = LazyPrinter(io::IO->Base_show_tuple_as_call(io, Symbol(""), tt)) error(lazy"Could not find single target method for `$sig`") end @@ -715,7 +715,7 @@ end function apply_file_config(jetconfigs, filename::AbstractString) isfile(filename) || throw(ArgumentError("$filename doesn't exist")) - jetconfigs = set_if_missing(jetconfigs, :toplevel_logger, IOContext(stdout, JET_LOGGER_LEVEL => DEFAULT_LOGGER_LEVEL)) + jetconfigs = set_if_missing(jetconfigs, :toplevel_logger, IOContext(stdout, JET_LOGGER_LEVEL => DEFAULT_LOGGER_LEVEL, :limit => true)) configfile = find_config_file(dirname(abspath(filename))) if !isnothing(configfile) config = parse_config_file(configfile) diff --git a/src/abstractinterpret/abstractanalyzer.jl b/src/abstractinterpret/abstractanalyzer.jl index ec031e0be..6584ab514 100644 --- a/src/abstractinterpret/abstractanalyzer.jl +++ b/src/abstractinterpret/abstractanalyzer.jl @@ -281,7 +281,7 @@ end @assert JETInferenceParams(InferenceParams(); max_methods=1).max_methods == 1 @assert !JETOptimizationParams(OptimizationParams(); inlining=false).inlining -Base.show(io::IO, state::AnalyzerState) = print(io, typeof(state), "(...)") +Base.show(io::IO, state::AnalyzerState) = print(depth_lim_cxt(io), typeof(state), "(...)") @noinline function AnalyzerState(analyzer::AbstractAnalyzer) AnalyzerType = nameof(typeof(analyzer)) diff --git a/src/analyzers/jetanalyzer.jl b/src/analyzers/jetanalyzer.jl index cbf22a7f0..1b8af8888 100644 --- a/src/analyzers/jetanalyzer.jl +++ b/src/analyzers/jetanalyzer.jl @@ -594,7 +594,7 @@ function print_report_message(io::IO, report::MethodErrorReport) end function print_callsig(io, @nospecialize(t)) print(io, '`') - Base.show_tuple_as_call(io, Symbol(""), t) + Base_show_tuple_as_call(io, Symbol(""), t) print(io, '`') end diff --git a/src/ui/print.jl b/src/ui/print.jl index e661e6eb9..2192479d0 100644 --- a/src/ui/print.jl +++ b/src/ui/print.jl @@ -1,3 +1,13 @@ +function Base_type_depth_limit(io::IO) + sz = get(io, :displaysize, (typemax(Int), typemax(Int)))::Tuple{Int, Int} + return Base.type_depth_limit(String(take!(io)), max(sz[2], 120); maxdepth=1) +end +function Base_show_tuple_as_call(io::IO, name, tt; kwargs...) + io = IOContext(io, :limit => true) + Base.show_tuple_as_call(io, name, tt; kwargs...) +end +depth_lim_cxt(io) = IOContext(io, :limit => true) + # entry # ===== @@ -83,7 +93,7 @@ end function with_bufferring(f, args...) buf = IOBuffer() - io = IOContext(buf, args...) + io = IOContext(buf, args..., :limit => true) f(io) return String(take!(buf)) end @@ -107,12 +117,14 @@ function print_reports(io::IO, arg = :color => get(io, :color, false) with_bufferring(arg) do io + io = depth_lim_cxt(io) s = string(pluralize(n, "toplevel error"), " found") printlnstyled(io, LEFT_ROOF, s, RIGHT_ROOF; color = HEADER_COLOR) color = ERROR_COLOR rail = with_bufferring(arg) do io + io = depth_lim_cxt(io) printstyled(io, "│ "; color) end @@ -183,6 +195,7 @@ function print_stack(io, report, config, wrote_linfos, depth = 1) linfo_hash = hash(frame) should_print = linfo_hash ∉ wrote_linfos push!(wrote_linfos, linfo_hash) + io = depth_lim_cxt(io) # print current frame and go into deeper if should_print @@ -200,10 +213,14 @@ end function print_frame_sig(io, frame) mi = frame.linfo m = mi.def + io = depth_lim_cxt(io) if m isa Module Base.show_mi(io, mi, #=from_stackframe=#true) else - Base.StackTraces.show_spec_sig(IOContext(io, :backtrace=>true), m, mi.specTypes) + buf = IOBuffer() + Base.StackTraces.show_spec_sig(buf, m, mi.specTypes) + io = IOContext(io, :backtrace=>true, :limit=>true) + write(io, Base_type_depth_limit(buf)); end end @@ -230,6 +247,7 @@ function print_error_frame(io, report, config, depth) frame = report.vst[depth] color = report_color(report) + io = depth_lim_cxt(io) print_rails(io, depth-1) printstyled(io, "┌ "; color) print_frame_sig(io, frame) @@ -264,6 +282,7 @@ function print_signature(io, sig::Signature, config; kwargs...) end end function _print_signature(io, @nospecialize(x), config; kwargs...) + io = IOContext(io, :limit=>true) if isa(x, Type) if x == pairs(NamedTuple) if isdefined(Base, Symbol("@Kwargs")) @@ -272,7 +291,7 @@ function _print_signature(io, @nospecialize(x), config; kwargs...) printstyled(io, "::Base.Pairs{…}"; color = TYPE_ANNOTATION_COLOR, kwargs...) end elseif x !== Union{} - io = IOContext(io, :backtrace=>true) + io = IOContext(io, :backtrace=>true, :limit => true) printstyled(io, "::", x; color = TYPE_ANNOTATION_COLOR, kwargs...) end elseif isa(x, Repr) @@ -313,13 +332,14 @@ struct IgnoreMarker end # adapted from https://github.com/JuliaLang/julia/blob/0f11a7bb07d2d0d8413da05dadd47441705bf0dd/base/show.jl#L989-L1011 function show_mi(io::IO, l::MethodInstance) def = l.def + io = depth_lim_cxt(io) if isa(def, Method) if isdefined(def, :generator) && l === def.generator # print(io, "MethodInstance generator for ") show(io, def) else # print(io, "MethodInstance for ") - Base.show_tuple_as_call(io, def.name, l.specTypes; qualified=true) + Base_show_tuple_as_call(io, def.name, l.specTypes; qualified=true) end else # print(io, "Toplevel MethodInstance thunk") diff --git a/test/setup.jl b/test/setup.jl index ebfa67bf7..681fbade7 100644 --- a/test/setup.jl +++ b/test/setup.jl @@ -8,7 +8,7 @@ include("interactive_utils.jl") function get_reports_with_test(res::JET.AnyJETResult) reports = get_reports(res) buf = IOBuffer() - print_reports(IOContext(buf, :color=>true), reports; res.jetconfigs...) + print_reports(IOContext(buf, :color=>true, :limit=>true), reports; res.jetconfigs...) @test !isempty(String(take!(buf))) return reports end @@ -21,7 +21,7 @@ const ERROR_REPORTS_FROM_SUM_OVER_STRING = let get_reports_with_test(result) end -get_msg(report::JET.InferenceErrorReport) = sprint(JET.print_report, report) +get_msg(report::JET.InferenceErrorReport) = sprint(JET.print_report, report, context=(:limit >= true,)) function test_sum_over_string(ers) @test !isempty(ers)