Skip to content

Commit

Permalink
Merge pull request #76 from timholy/teh/ji0.7
Browse files Browse the repository at this point in the history
Fix on recent Julia & Revise versions
  • Loading branch information
timholy authored Jan 18, 2020
2 parents d246b61 + ec29870 commit 2322c76
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ os:
- osx
julia:
- 1.0
- 1.1
- 1
- nightly
notifications:
email: false
Expand Down
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Rebugger"
uuid = "ee283ea6-eecd-56e3-beb3-83eb4d3c31e9"
version = "0.3.2"
version = "0.3.3"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand All @@ -12,7 +12,10 @@ Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
CodeTracking = "0.5"
HeaderREPLs = "0.3"
JuliaInterpreter = "0.7"
Revise = "2.1.10"
julia = "1"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion src/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ function generate_let_command(method::Method, uuid::UUID)
@assert method == s.method
argstring = '(' * join(s.varnames, ", ") * (length(s.varnames)==1 ? ",)" : ')')
Revise.get_def(method; modified_files=String[]) # to avoid mtime updates
body = convert(Expr, striplines!(definition(method).args[end]))
body = convert(Expr, striplines!(unwrap(definition(method)).args[end]))
return """
@eval $(method.module) let $argstring = Main.Rebugger.getstored(\"$uuid\")
$body
Expand Down
25 changes: 19 additions & 6 deletions src/deepcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,28 @@ function Base.deepcopy_internal(@nospecialize(x), stackdict::WrappedIdDict)
if haskey(stackdict, x)
return stackdict[x]
end
y = ccall(:jl_new_struct_uninit, Any, (Any,), T)
if T.mutable
y = ccall(:jl_new_struct_uninit, Any, (Any,), T)
stackdict[x] = y
end
for i in 1:nf
if isdefined(x,i)
ccall(:jl_set_nth_field, Cvoid, (Any, Csize_t, Any), y, i-1,
Base.deepcopy_internal(getfield(x,i), stackdict))
for i in 1:nf
if isdefined(x,i)
ccall(:jl_set_nth_field, Cvoid, (Any, Csize_t, Any), y, i-1,
Base.deepcopy_internal(getfield(x,i), stackdict))
end
end
else
flds = Vector{Any}(undef, nf)
for i in 1:nf
if isdefined(x, i)
xi = getfield(x, i)
xi = Base.deepcopy_internal(xi, stackdict)::typeof(xi)
flds[i] = xi
else
nf = i - 1 # rest of tail must be undefined values
break
end
end
y = ccall(:jl_new_structv, Any, (Any, Ptr{Any}, UInt32), T, flds, nf)
end
return y::T
end
Expand Down
8 changes: 6 additions & 2 deletions src/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ end
LineNumberIO(io::IO, line::Integer, file::Symbol) = LineNumberIO(io, Union{Missing,Int}[line], file)
LineNumberIO(io::IO, line::Integer, file::AbstractString) = LineNumberIO(io, line, Symbol(file))

const LNIO = Union{LineNumberIO, IOContext{LineNumberIO}}

# Instead of printing the source line number to `io.io`, associate it with the
# corresponding line of the printout
function Base.show_linenumber(io::LineNumberIO, line, file)
Expand All @@ -25,8 +27,9 @@ function Base.show_linenumber(io::LineNumberIO, line, file)
end
return nothing
end
Base.show_linenumber(io::LineNumberIO, line, ::Nothing) = nothing
Base.show_linenumber(io::LineNumberIO, line) = nothing
Base.show_linenumber(io::LNIO, line, file) = Base.show_linenumber(io.io, line, file)
Base.show_linenumber(io::LNIO, line, ::Nothing) = nothing
Base.show_linenumber(io::LNIO, line) = nothing

# TODO? intercept `\n` here and break the result up into lines at writing time?
Base.write(io::LineNumberIO, x::UInt8) = write(io.io, x)
Expand All @@ -40,6 +43,7 @@ function expression_lines(method::Method)
methstrings = split(chomp(src), '\n')
return Vector(range(Int(line1), length=length(methstrings))), line1, methstrings
end
def = unwrap(def)
# We'll use the file in LineNumberNodes to make sure line numbers refer to the "outer"
# method (and does not get confused by macros etc). Because of symlinks and non-normalized paths,
# it's more reliable to grab the first LNN for the template filename than to use method.file.
Expand Down
6 changes: 4 additions & 2 deletions test/edit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ uuidextractor(str) = UUID(match(r"getstored\(\"([a-z0-9\-]+)\"\)", str).captures
struct ErrorsOnShow end
Base.show(io::IO, ::ErrorsOnShow) = throw(ArgumentError("no show"))

const SPACE = VERSION < v"1.5.0-DEV.0" ? "" : " " # maybe 1.4.0-DEV.537? most likely 1.4.0-DEV.604

@testset "Rebugger" begin
id = uuid1()
@test uuidextractor("vars = getstored(\"$id\") and more stuff") == id
Expand Down Expand Up @@ -220,7 +222,7 @@ Base.show(io::IO, ::ErrorsOnShow) = throw(ArgumentError("no show"))
@test cmd == """
@eval Main.RebuggerTesting let (x, kw1, kwargs) = Main.Rebugger.getstored("$uuid")
begin
kwvarargs2(x; kw1=kw1, kwargs...)
kwvarargs2(x; kw1$(SPACE)=$(SPACE)kw1, kwargs...)
end
end"""
@test Rebugger.getstored(string(uuid)) == (1, 1, empty_kwvarargs)
Expand All @@ -232,7 +234,7 @@ Base.show(io::IO, ::ErrorsOnShow) = throw(ArgumentError("no show"))
@test cmd == """
@eval Main.RebuggerTesting let (x, kw1, kwargs) = Main.Rebugger.getstored("$uuid")
begin
kwvarargs2(x; kw1=kw1, kwargs...)
kwvarargs2(x; kw1$(SPACE)=$(SPACE)kw1, kwargs...)
end
end"""
@test Rebugger.getstored(string(uuid)) == (1, 1, pairs((passthrough=false,)))
Expand Down
6 changes: 3 additions & 3 deletions test/interpret_ui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ function run_terminal_test(cmd, validation, commands)
end
end

Revise.track(Base) # just to get Info printing out of the way
includet("my_gcd.jl")

CTRL_C = "\x3"
EOT = "\x4"
UP_ARROW = "\e[A"

run_terminal_test("gcd(10, 20)",
run_terminal_test("my_gcd(10, 20)",
"gcd.multiout",
['\n'])
run_terminal_test("__gcdval__ = gcd(10, 20);",
run_terminal_test("__gcdval__ = my_gcd(10, 20);",
"gcdsc.multiout",
['\n'])
@test __gcdval__ == gcd(10, 20)
22 changes: 22 additions & 0 deletions test/my_gcd.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# From base, but copied here to make sure we don't fail bacause base changed
function my_gcd(a::T, b::T) where T<:Union{Int8,UInt8,Int16,UInt16,Int32,UInt32,
Int64,UInt64,Int128,UInt128}
a == 0 && return abs(b)
b == 0 && return abs(a)
za = trailing_zeros(a)
zb = trailing_zeros(b)
k = min(za, zb)
u = unsigned(abs(a >> za))
v = unsigned(abs(b >> zb))
while u != v
if u > v
u, v = v, u
end
v -= u
v >>= trailing_zeros(v)
end
r = u << k
# T(r) would throw InexactError; we want OverflowError instead
r > typemax(T) && throw(OverflowError("gcd($a, $b) overflows"))
r % T
end
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Rebugger, Test

@info "These tests manipulate the console. Wait until you see \"Done\""
include("edit.jl")
include("interpret.jl")
if Sys.isunix() && VERSION >= v"1.1.0"
include("interpret_ui.jl")
else
@warn "Skipping UI tests"
end
println("done") # there is so much terminal manipulation, best to let the user know
println("Done")
6 changes: 2 additions & 4 deletions test/ui/v1.2/gcd.multiout
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
++++++++++++++++++++++++++++++++++++++++++++++++++
|gcd(10, 20)
|gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt1
|6, UInt32, UInt64, UInt8} in Base at /home/tim/src/julia-master/base/intfuncs.jl
|:31
|6, UInt32, UInt64, UInt8} in Base at /home/tim/src/julia-1/base/intfuncs.jl:31
| a = 10
| b = 20
| T = Int64
Expand All @@ -14,8 +13,7 @@
--------------------------------------------------
|AAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAA
|AAAAAAAA
|AAAAAAAAAAA
Expand Down
6 changes: 2 additions & 4 deletions test/ui/v1.2/gcdsc.multiout
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
++++++++++++++++++++++++++++++++++++++++++++++++++
|__gcdval__ = gcd(10, 20);
|gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt1
|6, UInt32, UInt64, UInt8} in Base at /home/tim/src/julia-master/base/intfuncs.jl
|:31
|6, UInt32, UInt64, UInt8} in Base at /home/tim/src/julia-1/base/intfuncs.jl:31
| a = 10
| b = 20
| T = Int64
Expand All @@ -14,8 +13,7 @@
--------------------------------------------------
|AAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAA
|AAAAAAAA
|AAAAAAAAAAA
Expand Down
20 changes: 10 additions & 10 deletions test/ui/v1.3/gcd.multiout
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
++++++++++++++++++++++++++++++++++++++++++++++++++
|gcd(10, 20)
|gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt1
|6, UInt32, UInt64, UInt8} in Base at /home/tim/src/julia-master/base/intfuncs.jl
|:31
|my_gcd(10, 20)
|my_gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UI
|nt16, UInt32, UInt64, UInt8} in Main at /home/tim/.julia/dev/Rebugger/test/my_gc
|d.jl:4
| a = 10
| b = 20
| T = Int64
| 30 function gcd(a::T, b::T) where T <: Union{Int8, UInt8, Int16, UInt16, Int
| 31 a == 0 && return abs(b)
| 32 b == 0 && return abs(a)
| 33 za = trailing_zeros(a)
| 3 function my_gcd(a::T, b::T) where T <: Union{Int8, UInt8, Int16, UInt16, …
| 4 a == 0 && return abs(b)
| 5 b == 0 && return abs(a)
| 6 za = trailing_zeros(a)
|
--------------------------------------------------
|AAAAAAAAAAA
|AAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAA
|AAAAAA
|AAAAAAAA
|AAAAAAAA
|AAAAAAAAAAA
Expand Down
20 changes: 10 additions & 10 deletions test/ui/v1.3/gcdsc.multiout
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
++++++++++++++++++++++++++++++++++++++++++++++++++
|__gcdval__ = gcd(10, 20);
|gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt1
|6, UInt32, UInt64, UInt8} in Base at /home/tim/src/julia-master/base/intfuncs.jl
|:31
|__gcdval__ = my_gcd(10, 20);
|my_gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UI
|nt16, UInt32, UInt64, UInt8} in Main at /home/tim/.julia/dev/Rebugger/test/my_gc
|d.jl:4
| a = 10
| b = 20
| T = Int64
| 30 function gcd(a::T, b::T) where T <: Union{Int8, UInt8, Int16, UInt16, Int
| 31 a == 0 && return abs(b)
| 32 b == 0 && return abs(a)
| 33 za = trailing_zeros(a)
| 3 function my_gcd(a::T, b::T) where T <: Union{Int8, UInt8, Int16, UInt16, …
| 4 a == 0 && return abs(b)
| 5 b == 0 && return abs(a)
| 6 za = trailing_zeros(a)
|
--------------------------------------------------
|AAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAA
|AAAAAA
|AAAAAAAA
|AAAAAAAA
|AAAAAAAAAAA
Expand Down
26 changes: 26 additions & 0 deletions test/ui/v1.5/gcd.multiout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
++++++++++++++++++++++++++++++++++++++++++++++++++
|my_gcd(10, 20)
|my_gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UI
|nt16, UInt32, UInt64, UInt8} in Main at /home/tim/.julia/dev/Rebugger/test/my_gc
|d.jl:4
| a = 10
| b = 20
| T = Int64
| 3 function my_gcd(a::T, b::T) where T <: Union{Int8, UInt8, Int16, UInt16, …
| 4 a == 0 && return abs(b)
| 5 b == 0 && return abs(a)
| 6 za = trailing_zeros(a)
|
--------------------------------------------------
|AAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAA
|AAAAAAAA
|AAAAAAAA
|AAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
26 changes: 26 additions & 0 deletions test/ui/v1.5/gcdsc.multiout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
++++++++++++++++++++++++++++++++++++++++++++++++++
|__gcdval__ = my_gcd(10, 20);
|my_gcd(a::T, b::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UI
|nt16, UInt32, UInt64, UInt8} in Main at /home/tim/.julia/dev/Rebugger/test/my_gc
|d.jl:4
| a = 10
| b = 20
| T = Int64
| 3 function my_gcd(a::T, b::T) where T <: Union{Int8, UInt8, Int16, UInt16, …
| 4 a == 0 && return abs(b)
| 5 b == 0 && return abs(a)
| 6 za = trailing_zeros(a)
|
--------------------------------------------------
|AAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAA
|AAAAAAAA
|AAAAAAAA
|AAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|

0 comments on commit 2322c76

Please sign in to comment.