From cf126a1bda99446b7dcf8fc86c6969052ce5eeb9 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Wed, 2 Jun 2021 12:18:05 +0200 Subject: [PATCH 1/4] improve handling of duplicate slotnames --- src/breakpoints.jl | 19 +++++++++---------- test/breakpoints.jl | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/breakpoints.jl b/src/breakpoints.jl index 9ffc922b..f8922130 100644 --- a/src/breakpoints.jl +++ b/src/breakpoints.jl @@ -189,19 +189,18 @@ end function prepare_slotfunction(framecode::FrameCode, body::Union{Symbol,Expr}) uslotnames = Set{Symbol}() - slotnames = Symbol[] - for name in framecode.src.slotnames - if name ∉ uslotnames - push!(slotnames, name) - push!(uslotnames, name) - end - end framename, dataname = gensym("frame"), gensym("data") assignments = Expr[:($dataname = $framename.framedata)] default = Unassigned() - for i = 1:length(slotnames) - slotname = framecode.src.slotnames[i] - qslotname = QuoteNode(slotname) + for slotname in framecode.src.slotnames + if slotname === Symbol("") + continue + end + if slotname ∉ uslotnames + push!(uslotnames, slotname) + else + continue + end list = framecode.slotnamelists[slotname] if length(list) == 1 maxexpr = :($dataname.last_reference[$(list[1])] > 0 ? $(list[1]) : 0) diff --git a/test/breakpoints.jl b/test/breakpoints.jl index 0b883ae6..440f71b1 100644 --- a/test/breakpoints.jl +++ b/test/breakpoints.jl @@ -433,3 +433,25 @@ empty!(breakpoint_update_hooks) remove() end end + +@testset "duplicate slotnames" begin + tmp_dupl() = (1,2,3,4) + ln = @__LINE__ + function duplnames(x) + for iter in Iterators.CartesianIndices(x) + i = iter[1] + c = i + a, b, c, d = tmp_dupl() + end + return x + end + bp = breakpoint(@__FILE__, ln+5, :(i == 1)) + c = @code_lowered(duplnames((1,2))) + if length(unique(c.slotnames)) < length(c.slotnames) + f = JuliaInterpreter.enter_call(duplnames, (1,2)) + ex = JuliaInterpreter.prepare_slotfunction(f.framecode, :(i==1)) + @test ex isa Expr + @test ex.args[end].args[end-1].args[1] == :i + @test last(JuliaInterpreter.debug_command(f, :c)) isa BreakpointRef + end +end From dbb3ac3fa278e4b64f04bb90db6ba1dada2cd906 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Wed, 2 Jun 2021 12:46:29 +0200 Subject: [PATCH 2/4] don't rely on slot order in test --- test/breakpoints.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/breakpoints.jl b/test/breakpoints.jl index 440f71b1..bbddab24 100644 --- a/test/breakpoints.jl +++ b/test/breakpoints.jl @@ -451,7 +451,13 @@ end f = JuliaInterpreter.enter_call(duplnames, (1,2)) ex = JuliaInterpreter.prepare_slotfunction(f.framecode, :(i==1)) @test ex isa Expr - @test ex.args[end].args[end-1].args[1] == :i + found = false + for arg in ex.args[end].args + if arg.args[1] == :i + found = true + end + end + @test found @test last(JuliaInterpreter.debug_command(f, :c)) isa BreakpointRef end end From c9d662778c1bfe782273f5cdfb6913bdcd9695ed Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Wed, 2 Jun 2021 12:49:25 +0200 Subject: [PATCH 3/4] remove unnecessary check --- src/breakpoints.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/breakpoints.jl b/src/breakpoints.jl index f8922130..efa54daa 100644 --- a/src/breakpoints.jl +++ b/src/breakpoints.jl @@ -193,9 +193,6 @@ function prepare_slotfunction(framecode::FrameCode, body::Union{Symbol,Expr}) assignments = Expr[:($dataname = $framename.framedata)] default = Unassigned() for slotname in framecode.src.slotnames - if slotname === Symbol("") - continue - end if slotname ∉ uslotnames push!(uslotnames, slotname) else From b71da5a02707f5b9abfbf5675d23379c8729307a Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Wed, 2 Jun 2021 12:59:14 +0200 Subject: [PATCH 4/4] clean up code --- src/breakpoints.jl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/breakpoints.jl b/src/breakpoints.jl index efa54daa..278f754b 100644 --- a/src/breakpoints.jl +++ b/src/breakpoints.jl @@ -188,16 +188,10 @@ function shouldbreak(frame::Frame, pc::Int) end function prepare_slotfunction(framecode::FrameCode, body::Union{Symbol,Expr}) - uslotnames = Set{Symbol}() framename, dataname = gensym("frame"), gensym("data") assignments = Expr[:($dataname = $framename.framedata)] default = Unassigned() - for slotname in framecode.src.slotnames - if slotname ∉ uslotnames - push!(uslotnames, slotname) - else - continue - end + for slotname in unique(framecode.src.slotnames) list = framecode.slotnamelists[slotname] if length(list) == 1 maxexpr = :($dataname.last_reference[$(list[1])] > 0 ? $(list[1]) : 0)