Skip to content

Commit a7a65c2

Browse files
authored
Better handling of CGlobal & :call unnesting (#456)
This supports SSAValue args for cglobal while also fixing a bug in which a GotoIfNot ended up going to the wrong statement. The latter was a consequence of incorrect :call unnesting. Fixes #455 Fixes #454 Fixes #415 Fixes JuliaDebug/Debugger.jl#275 Improves #354
1 parent fc3b614 commit a7a65c2

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
- windows-latest
2727
arch:
2828
- x64
29+
env:
30+
PYTHON: ""
2931
steps:
3032
- uses: actions/checkout@v2
3133
- uses: julia-actions/setup-julia@v1

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ julia = "1"
1616
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1717
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1818
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
19+
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
1920
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2021
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
22+
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
2123
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2224
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2325
TableReader = "70df011a-6618-58d7-8e16-3cf9e384cb47"
2426
Tensors = "48a634ad-e948-5137-8d70-aa71f2a747f4"
2527
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2628

2729
[targets]
28-
test = ["Test", "Dates", "Distributed", "LinearAlgebra", "Mmap", "SHA", "SparseArrays", "Tensors", "TableReader", "DataFrames"]
30+
test = ["Test", "Dates", "Distributed", "HTTP", "LinearAlgebra", "Mmap", "PyCall", "SHA", "SparseArrays", "Tensors", "TableReader", "DataFrames"]

src/builtins.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,14 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
231231
# Intrinsics
232232
elseif f === Base.cglobal
233233
if nargs == 1
234+
call_expr = copy(call_expr)
235+
args2 = args[2]
236+
call_expr.args[2] = isa(args2, QuoteNode) ? args2 : @lookup(frame, args2)
234237
return Some{Any}(Core.eval(moduleof(frame), call_expr))
235238
elseif nargs == 2
236239
call_expr = copy(call_expr)
240+
args2 = args[2]
241+
call_expr.args[2] = isa(args2, QuoteNode) ? args2 : @lookup(frame, args2)
237242
call_expr.args[3] = @lookup(frame, args[3])
238243
return Some{Any}(Core.eval(moduleof(frame), call_expr))
239244
end

src/optimize.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,30 @@ function replace_ssa!(stmt, ssalookup)
4040
end
4141

4242
function renumber_ssa!(stmts::Vector{Any}, ssalookup)
43+
# When updating jumps, when lines get split into multiple lines
44+
# (see "Un-nest :call expressions" below), we need to jump to the first of them.
45+
# Consequently we use the previous "old-code" offset and add one.
46+
# Fixes #455.
47+
jumplookup(l, idx) = idx > 1 ? l[idx-1] + 1 : idx
48+
4349
for (i, stmt) in enumerate(stmts)
4450
if isa(stmt, GotoNode)
45-
stmts[i] = GotoNode(ssalookup[stmt.label])
51+
stmts[i] = GotoNode(jumplookup(ssalookup, stmt.label))
4652
elseif isa(stmt, SSAValue)
4753
stmts[i] = SSAValue(ssalookup[stmt.id])
4854
elseif isa(stmt, NewSSAValue)
4955
stmts[i] = SSAValue(stmt.id)
5056
elseif isa(stmt, Expr)
5157
replace_ssa!(stmt, ssalookup)
5258
if (stmt.head === :gotoifnot || stmt.head === :enter) && isa(stmt.args[end], Int)
53-
stmt.args[end] = ssalookup[stmt.args[end]]
59+
stmt.args[end] = jumplookup(ssalookup, stmt.args[end])
5460
end
5561
elseif is_GotoIfNot(stmt)
5662
cond = stmt.cond
5763
if isa(cond, SSAValue)
5864
cond = SSAValue(ssalookup[cond.id])
5965
end
60-
stmts[i] = Core.GotoIfNot(cond, ssalookup[stmt.dest])
66+
stmts[i] = Core.GotoIfNot(cond, jumplookup(ssalookup, stmt.dest))
6167
elseif is_ReturnNode(stmt)
6268
val = (stmt::Core.ReturnNode).val
6369
if isa(val, SSAValue)

test/interpret.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ val = @interpret(BigInt())
212212
@test isa(val, BigInt) && val == 0
213213
@test isa(@interpret(Base.GMP.version()), VersionNumber)
214214

215+
# Issue #455
216+
using PyCall
217+
let np = pyimport("numpy")
218+
@test @interpret(PyCall.pystring_query(np.zeros)) === Union{}
219+
end
220+
# Issue #354 (partial fix)
221+
using HTTP
222+
headers = Dict("User-Agent" => "Debugger.jl")
223+
@test_broken @interpret(HTTP.request("GET", "https://api.github.com/", headers))
224+
215225
# "correct" line numbers
216226
defline = @__LINE__() + 1
217227
function f(x)

0 commit comments

Comments
 (0)