Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Requires.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ end
if isprecompiling()
precompile(loadpkg, (Base.PkgId,)) || @warn "Requires failed to precompile `loadpkg`"
precompile(withpath, (Any, String)) || @warn "Requires failed to precompile `withpath`"
precompile(err, (Any, Module, String)) || @warn "Requires failed to precompile `err`"
precompile(err, (Any, Module, String, String, Int)) || @warn "Requires failed to precompile `err`"
precompile(err, (Any, Module, String, String, Nothing)) || @warn "Requires failed to precompile `err`"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could clear out all the warnings (now that Julia 1.7 does this automatically), but that could be a separate PR.

precompile(parsepkg, (Expr,)) || @warn "Requires failed to precompile `parsepkg`"
precompile(listenpkg, (Any, Base.PkgId)) || @warn "Requires failed to precompile `listenpkg`"
precompile(callbacks, (Base.PkgId,)) || @warn "Requires failed to precompile `callbacks`"
Expand Down
9 changes: 6 additions & 3 deletions src/require.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ function withpath(@nospecialize(f), path::String)
end
end

function err(@nospecialize(f), listener::Module, modname::String)
function err(@nospecialize(f), listener::Module, modname::String, file::String, line)
try
f()
t = @elapsed ret = f()
@debug "Requires conditionally ran code in $t seconds: `$listener` detected `$modname`" _file = file _line = line
ret
catch exc
@warn "Error requiring `$modname` from `$listener`" exception=(exc,catch_backtrace())
end
Expand Down Expand Up @@ -90,11 +92,12 @@ macro require(pkg::Union{Symbol,Expr}, expr)
expr = isa(expr, Expr) ? replace_include(expr, __source__) : expr
expr = macroexpand(__module__, expr)
srcfile = string(__source__.file)
srcline = __source__.line
quote
if !isprecompiling()
listenpkg($pkg) do
withpath($srcfile) do
err($__module__, $modname) do
err($__module__, $modname, $srcfile, $srcline) do
$(esc(:(eval($(Expr(:quote, Expr(:block,
:(const $(Symbol(modname)) = Base.require($pkg)),
expr)))))))
Expand Down