Skip to content

Commit

Permalink
Duplicate include(::String) for nicer stacktraces (#33087)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-levitt authored and JeffBezanson committed Aug 28, 2019
1 parent e9c6c42 commit 9a8b2fd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
24 changes: 23 additions & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,29 @@ end

# MainInclude exists to hide Main.include and eval from `names(Main)`.
baremodule MainInclude
include(fname::AbstractString) = Main.Base.include(Main, fname)
# We inline the definition of include from loading.jl/include_relative to get one-frame stacktraces.
# include(fname::AbstractString) = Main.Base.include(Main, fname)
function include(fname::AbstractString)
mod = Main
isa(fname, String) || (fname = String(fname))
path, prev = Main.Base._include_dependency(mod, fname)
for callback in Main.Base.include_callbacks # to preserve order, must come before Core.include
Main.Base.invokelatest(callback, mod, path)
end
tls = Main.Base.task_local_storage()
tls[:SOURCE_PATH] = path
local result
try
result = ccall(:jl_load_, Any, (Any, Any), mod, path)
finally
if prev === nothing
Main.Base.delete!(tls, :SOURCE_PATH)
else
tls[:SOURCE_PATH] = prev
end
end
return result
end
eval(x) = Core.eval(Main, x)
end

Expand Down
2 changes: 2 additions & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ function source_dir()
return p === nothing ? pwd() : dirname(p)
end

# These functions are duplicated in client.jl/include(::String) for
# nicer stacktraces. Modifications here have to be backported there
include_relative(mod::Module, path::AbstractString) = include_relative(mod, String(path))
function include_relative(mod::Module, _path::String)
path, prev = _include_dependency(mod, _path)
Expand Down
9 changes: 3 additions & 6 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,15 +561,12 @@ let exename = `$(Base.julia_cmd()) --startup-file=no`
"Bool(Base.JLOptions().use_sysimage_native_code)"`) == "false"
end

# backtrace contains type and line number info (esp. on windows #17179)
# backtrace contains line number info (esp. on windows #17179)
for precomp in ("yes", "no")
succ, out, bt = readchomperrors(`$(Base.julia_cmd()) --startup-file=no --sysimage-native-code=$precomp -E 'include("____nonexistent_file")'`)
succ, out, bt = readchomperrors(`$(Base.julia_cmd()) --startup-file=no --sysimage-native-code=$precomp -E 'sqrt(-2)'`)
@test !succ
@test out == ""
@test occursin("include_relative(::Module, ::String) at $(joinpath(".", "loading.jl"))", bt)
lno = match(r"at \.[\/\\]loading\.jl:(\d+)", bt)
@test length(lno.captures) == 1
@test parse(Int, lno.captures[1]) > 0
@test occursin(r"\.jl:(\d+)", bt)
end

# PR #23002
Expand Down

2 comments on commit 9a8b2fd

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.