Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate include(::String) for nicer stacktraces #33087

Merged
merged 3 commits into from
Aug 28, 2019
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
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