119119# In case the line numbers in the source code have changed since the code was compiled,
120120# allow packages to set a callback function that corrects them.
121121# (Used by Revise and perhaps other packages.)
122- default_methodloc (method:: Method ) = method. file, method. line
123- const methodloc_callback = Ref {Function} (default_methodloc)
122+ const methodloc_callback = Ref {Union{Function, Nothing}} (nothing )
123+
124+ # This function does the method location updating
125+ function updated_methodloc (m:: Method ):: Tuple{String, Int32}
126+ file, line = m. file, m. line
127+ if methodloc_callback[] != = nothing
128+ try
129+ file, line = invokelatest (methodloc_callback[], m)
130+ catch
131+ end
132+ end
133+ # The file defining Base.Sys gets included after this file is included so make sure
134+ # this function is valid even in this intermediary state
135+ if isdefined (@__MODULE__ , :Sys ) && Sys. BUILD_STDLIB_PATH != Sys. STDLIB
136+ # BUILD_STDLIB_PATH gets defined in sysinfo.jl
137+ file = replace (string (file), normpath (Sys. BUILD_STDLIB_PATH) => normpath (Sys. STDLIB))
138+ end
139+ return string (file), line
140+ end
124141
125142functionloc (m:: Core.MethodInstance ) = functionloc (m. def)
126143
@@ -130,7 +147,7 @@ functionloc(m::Core.MethodInstance) = functionloc(m.def)
130147Returns a tuple `(filename,line)` giving the location of a `Method` definition.
131148"""
132149function functionloc (m:: Method )
133- file, ln = invokelatest (methodloc_callback[], m)
150+ file, ln = updated_methodloc ( m)
134151 if ln <= 0
135152 error (" could not determine location of method definition" )
136153 end
@@ -195,10 +212,7 @@ function show(io::IO, m::Method)
195212 show_method_params (io, tv)
196213 print (io, " in " , m. module)
197214 if line > 0
198- try
199- file, line = invokelatest (methodloc_callback[], m)
200- catch
201- end
215+ file, line = updated_methodloc (m)
202216 print (io, " at " , file, " :" , line)
203217 end
204218end
@@ -247,11 +261,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
247261 println (io)
248262 print (io, " [$(n) ] " )
249263 show (io, meth)
250- file, line = meth. file, meth. line
251- try
252- file, line = invokelatest (methodloc_callback[], meth)
253- catch
254- end
264+ file, line = updated_methodloc (meth)
255265 push! (LAST_SHOWN_LINE_INFOS, (string (file), line))
256266 else
257267 rest += 1
@@ -361,10 +371,7 @@ function show(io::IO, ::MIME"text/html", m::Method)
361371 end
362372 print (io, " in " , m. module)
363373 if line > 0
364- try
365- file, line = invokelatest (methodloc_callback[], m)
366- catch
367- end
374+ file, line = updated_methodloc (m)
368375 u = url (m)
369376 if isempty (u)
370377 print (io, " at " , file, " :" , line)
@@ -398,11 +405,7 @@ function show(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method})
398405 first = false
399406 print (io, " [$(i) ] " )
400407 show (io, m)
401- file, line = m. file, m. line
402- try
403- file, line = invokelatest (methodloc_callback[], m)
404- catch
405- end
408+ file, line = updated_methodloc (m)
406409 push! (LAST_SHOWN_LINE_INFOS, (string (file), line))
407410 end
408411end
0 commit comments