@@ -750,6 +750,39 @@ function is_kw_sorter_name(name::Symbol)
750750 return ! startswith (sn, ' #' ) && endswith (sn, " ##kw" )
751751end
752752
753+ # For improved user experience, filter out frames for include() implementation
754+ # - see #33065. See also #35371 for extended discussion of internal frames.
755+ function _simplify_include_frames (trace)
756+ kept_frames = trues (length (trace))
757+ i = length (trace)
758+ first_ignored = nothing
759+ while i >= 1
760+ frame,_ = trace[i]
761+ mod = parentmodule (frame)
762+ if isnothing (first_ignored)
763+ if mod in (Base,Core) && frame. func === :_include
764+ # Hide include() machinery by default
765+ first_ignored = i
766+ end
767+ else
768+ # Hack: allow `mod==nothing` as a workaround for inlined functions.
769+ # TODO : Fix this by improving debug info.
770+ if mod in (Base,Core,nothing ) && 1 + first_ignored- i <= 5
771+ if frame. func == :eval
772+ @debug " Ignoring frames" removed= trace[i: first_ignored]
773+ kept_frames[i: first_ignored] .= false
774+ first_ignored = nothing
775+ end
776+ else
777+ # Bail out
778+ first_ignored = nothing
779+ end
780+ end
781+ i -= 1
782+ end
783+ trace[kept_frames]
784+ end
785+
753786function process_backtrace (t:: Vector , limit:: Int = typemax (Int); skipC = true )
754787 n = 0
755788 last_frame = StackTraces. UNKNOWN
@@ -790,7 +823,7 @@ function process_backtrace(t::Vector, limit::Int=typemax(Int); skipC = true)
790823 if n > 0
791824 push! (ret, (last_frame, n))
792825 end
793- return ret
826+ return _simplify_include_frames ( ret)
794827end
795828
796829function show_exception_stack (io:: IO , stack:: Vector )
0 commit comments