-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Maybe a tiny ARC bug #17712
Comments
Maybe valgrind output may help:
I can not test with refc GC because of currently. |
By the way, you can use |
|
--expandArc: nubly
var replaced = true
var rep_c = 0
block :tmp:
while replaced:
replaced = false
rep_c += 1
block :tmp_1:
var cv
var i = 0
let L = len(r.vertices)
block :tmp_2:
while i < L:
cv = r.vertices[i]
var stepPos = len(cv.attached_nets)
block :tmp_3:
while (
0 < stepPos):
block :tmp_4:
var
step
:tmp_5
:tmpD
:tmpD_1
prev_step
nxt_step
:tmp_6
:tmpD_2
:tmpD_3
pv
nv
try:
dec(stepPos, 1)
`=copy`(step, cv.attached_nets[stepPos])
:tmp_5 = default()
:tmp_5 = (
wasMoved(:tmpD)
`=copy`(:tmpD, step.pstep)
:tmpD,
wasMoved(:tmpD_1)
`=copy`(:tmpD_1, step.nstep)
:tmpD_1)
prev_step = :tmp_5[0]
nxt_step = :tmp_5[1]
:tmp_6 = default()
:tmp_6 = (
wasMoved(:tmpD_2)
`=copy_1`(:tmpD_2, step.prev)
:tmpD_2,
wasMoved(:tmpD_3)
`=copy_1`(:tmpD_3, step.next)
:tmpD_3)
pv = :tmp_6[0]
nv = :tmp_6[1]
var d = float(hypot(cv.x - pv.x, cv.y - pv.y) -
float(abs(prev_step.radius - step.radius)) * 1.02)
if d < 0.0:
if step.radius < prev_step.radius:
step.radius -= d
replaced = true
break :tmp_4
d = float(hypot(cv.x - nv.x, cv.y - nv.y) -
float(abs(nxt_step.radius - step.radius)) * 1.02)
if d < 0.0:
if step.radius < nxt_step.radius:
step.radius -= d
replaced = true
break :tmp_4
var (hx, hy) = convex_kkk(prev_step, step, nxt_step, r)
step.xt =
not (hx == 1e+300)
if collapse and step.xt:
var
:tmp_7
:tmpD_4
:tmpD_5
pv_1
nv_1
hv0
pp
ppv
nn
nnv
hv3
hv4
hv5
rep
:tmpD_6
:tmpD_7
:tmpD_8
:tmpD_9
:tmpD_10
hhh
try:
:tmp_7 = default()
:tmp_7 = (
wasMoved(:tmpD_4)
`=copy_1`(:tmpD_4, step.prev)
:tmpD_4,
wasMoved(:tmpD_5)
`=copy_1`(:tmpD_5, step.next)
:tmpD_5)
pv_1 = :tmp_7[0]
nv_1 = :tmp_7[1]
hv0 = XVertex()
initialize(hv0, hx, hy, 2000.0, 800.0)
const
loc`gensym451 = (
filename: "/home/salewski/Router/router.nim",
line: 2327, column: 17)
ploc`gensym451 = "/home/salewski/Router/router.nim(2327, 18)"
bind instantiationInfo
mixin failedAssertImpl
{.line: (filename: "/home/salewski/Router/router.nim",
line: 2327, column: 17).}:
if not
not (hv0.x == 0x7FF7FFFFFFFFFFFF'f64):
failedAssertImpl("/home/salewski/Router/router.nim(2327, 18) `hv0.x != NaN` ")
replaced = true
let pvx = pv_1.x
let pvy = pv_1.y
let nvx = nv_1.x
let nvy = nv_1.y
`=copy`(pp, prev_step.pstep)
if (
not (pp == nil)):
let _ = convex_kkk(pp, prev_step, step, nil)
hx = _[0]
hy = _[1]
ppv = default()
if
not (pp == nil) and
not (hx == 1e+300):
`=sink`(ppv, XVertex())
initialize(ppv, hx, hy, 2000.0, 800.0)
else:
`=copy_1`(ppv, pv_1)
if ppv.x == 0.0:
var :tmpD_11
try:
echo [
:tmpD_11 = `$`(Vertex(ppv))
:tmpD_11]
const
loc`gensym456 = (
filename: "/home/salewski/Router/router.nim",
line: 2343, column: 29)
ploc`gensym456 = "/home/salewski/Router/router.nim(2343, 30)"
bind instantiationInfo
mixin failedAssertImpl
{.line: (filename: "/home/salewski/Router/router.nim",
line: 2343, column: 29).}:
if true:
failedAssertImpl("/home/salewski/Router/router.nim(2343, 30) `false` ")
finally:
`=destroy`(:tmpD_11)
`=copy`(nn, nxt_step.nstep)
if (
not (nn == nil)):
let __1 = convex_kkk(step, nxt_step, nn, nil)
hx = __1[0]
hy = __1[1]
nnv = default()
if
not (nn == nil) and
not (hx == 1e+300):
`=sink`(nnv, XVertex())
initialize(nnv, hx, hy, 2000.0, 800.0)
else:
`=copy_1`(nnv, nv_1)
hx = nvx - pvx
hy = nvy - pvy
var vec_x: float
var vec_y: float
if step.rgt:
let __2 = (hy, -hx)
vec_x = __2[0]
vec_y = __2[1]
else:
let __3 = (-hy, hx)
vec_x = __3[0]
vec_y = __3[1]
hv3 = XVertex(x: pvx + hx / 2.0 + vec_x,
y: pvy + hy / 2.0 + vec_y)
initialize(hv3, pvx + hx / 2.0 + vec_x,
pvy + hy / 2.0 + vec_y, 2000.0, 800.0)
hx *= 2.0
hy *= 2.0
vec_x *= 2.0
vec_y *= 2.0
hv4 = XVertex(x: pvx - hx + vec_x, y: pvy - hy + vec_y,
tradius: 100.0)
initialize(hv4, pvx - hx + vec_x, pvy - hy + vec_y,
2000.0, 800.0)
hv5 = XVertex(x: nvx + hx + vec_x, y: nvy + hy + vec_y,
tradius: 100.0)
initialize(hv5, nvx + hx + vec_x, nvy + hy + vec_y,
2000.0, 800.0)
rep =
:tmpD_10 = vertices_in_polygon(
:tmpD_9 = @[
wasMoved(:tmpD_6)
`=copy_1`(:tmpD_6, ppv)
:tmpD_6,
let blitTmp = hv0
wasMoved(hv0)
blitTmp,
wasMoved(:tmpD_7)
`=copy_1`(:tmpD_7, nnv)
:tmpD_7,
wasMoved(:tmpD_8)
`=copy_1`(:tmpD_8, hv3)
:tmpD_8]
:tmpD_9, r.vertices)
:tmpD_10 -_2
[pv_1, nv_1, ppv, cv, nnv, hv3]
block :tmp_8:
var el
try:
el = default()
var i_1 = 0
block :tmp_9:
while true:
`=copy_1`(el, [ppv, hv0, nnv, hv3][i_1])
echo ["-----"]
arc(r.pic, el.x, el.y, 600.0, 0.0,
6.283185307179586)
if el.trgt:
setSource(r.pic, 0.0, 0.0, 1.0)
else:
setSource(r.pic, 0.0, 0.0, 1.0)
fill(r.pic)
stroke(r.pic)
if (
3 <= i_1):
break :tmp_9
inc(i_1, 1)
finally:
`=destroy_1`(el)
`=copy_2`(hhh, rep)
if (
0 < len(rep)):
var net
try:
`=copy_3`(net, step.net_desc)
block :tmp_10:
var v
var i_2 = 0
let L_1 = len(rep)
block :tmp_11:
while i_2 < L_1:
v = rep[i_2]
v.trgt = not step.rgt
v.tradius = v.radius_1 +
max([net.trace_clearance, v.separation]) +
net.trace_width / 2.0
inc(i_2, 1)
const
loc`gensym162 = (filename: "/home/salewski/Nim/lib/system/iterators.nim",
line: 240, column: 10)
ploc`gensym162 = "/home/salewski/Nim/lib/system/iterators.nim(240, 11)"
bind instantiationInfo
mixin failedAssertImpl
{.line: (filename: "/home/salewski/Nim/lib/system/iterators.nim",
line: 240, column: 10).}:
if not (len(rep) == L_1):
failedAssertImpl("/home/salewski/Nim/lib/system/iterators.nim(240, 11) `len(a) == L` the length of the seq changed while iterating over it")
pv_1.trgt = step.pstep.rgt
pv_1.tradius = step.pstep.radius
nv_1.trgt = step.nstep.rgt
nv_1.tradius = step.nstep.radius
`=sink_1`(rep,
new_convex_vertices(rep, pv_1, nv_1, hv4,
hv5))
block :tmp_12:
var el_1
var i_3 = 0
let L_2 = len(rep)
block :tmp_13:
while i_3 < L_2:
el_1 = rep[i_3]
if true:
break :tmp_12
arc(r.pic, el_1.x, el_1.y, 600.0, 0.0,
6.283185307179586)
if el_1.trgt:
setSource(r.pic, 1.0, 0.0, 0.0)
else:
setSource(r.pic, 0.0, 1.0, 0.0)
fill(r.pic)
stroke(r.pic)
inc(i_3, 1)
const
loc`gensym162 = (filename: "/home/salewski/Nim/lib/system/iterators.nim",
line: 240, column: 10)
ploc`gensym162 = "/home/salewski/Nim/lib/system/iterators.nim(240, 11)"
bind instantiationInfo
mixin failedAssertImpl
{.line: (filename: "/home/salewski/Nim/lib/system/iterators.nim",
line: 240, column: 10).}:
if not (len(rep) == L_2):
failedAssertImpl("/home/salewski/Nim/lib/system/iterators.nim(240, 11) `len(a) == L` the length of the seq changed while iterating over it")
finally:
`=destroy_2`(net)
smart_replace(step, rep)
finally:
`=destroy_3`(hhh)
`=destroy_3`(:tmpD_10)
`=destroy_3`(:tmpD_9)
`=destroy_3`(rep)
`=destroy_1`(hv5)
`=destroy_1`(hv4)
`=destroy_1`(hv3)
`=destroy_1`(nnv)
`=destroy_4`(nn)
`=destroy_1`(ppv)
`=destroy_4`(pp)
`=destroy_1`(hv0)
`=destroy_1`(nv_1)
`=destroy_1`(pv_1)
finally:
`=destroy_1`(nv)
`=destroy_1`(pv)
`=destroy_4`(nxt_step)
`=destroy_4`(prev_step)
`=destroy_4`(step)
inc(i, 1)
const
loc`gensym162 = (
filename: "/home/salewski/Nim/lib/system/iterators.nim",
line: 240, column: 10)
ploc`gensym162 = "/home/salewski/Nim/lib/system/iterators.nim(240, 11)"
bind instantiationInfo
mixin failedAssertImpl
{.line: (filename: "/home/salewski/Nim/lib/system/iterators.nim",
line: 240, column: 10).}:
if not (len(r.vertices) == L):
failedAssertImpl("/home/salewski/Nim/lib/system/iterators.nim(240, 11) `len(a) == L` the length of the seq changed while iterating over it")
-- end of expandArc ------------------------ fore more comfortable viewing :) |
Yes, seems to be really a wired ARC bug: I can add #discard hv0 == nil
#discard hv3 == nil
for el in [ppv, hv0, nnv, hv3]:
echo "-----"
echo "el? ", el == nil and get
|
Can you try with |
OK, I hope this test is OK for you: from math import hypot
const
NilFloat = 1e300
PinRadius = 100.0
type
Router = ref object of RootRef
pic: int # cairo.Context
vertices: seq[XVertex]
Vertex = ref object of RootRef
x, y: float
XVertex = ref object of Vertex
attached_nets: seq[Step]
tradius: float
radius: float
separation: float
trgt: bool
Step = ref object of RootRef
net_desc: Net
x, y: float
radius: float
prev, next: XVertex
pstep, nstep: Step
xt: bool
rgt: bool
Net = ref object of RootRef
trace_clearance: float
trace_width: float
proc initialize(v: XVertex; x, y: float) =
v.x = x
v.y = y
proc smart_replace(step: Step; rep: seq[XVertex]) =
discard
proc vertices_in_polygon(a, b: seq[XVertex]): seq[XVertex] =
result = a
if b.len > 0:
result.add(b[0])
proc nubly(r: Router; collapse = false) =
var replaced = true
var rep_c = 0
while replaced:
replaced = false
rep_c += 1
for cv in r.vertices:
var stepPos = cv.attached_nets.len
while stepPos > 0:
dec(stepPos)
var step = cv.attached_nets[stepPos]
#for step in cv.attached_nets.reversed:
let (prev_step, nxt_step) = (step.pstep, step.nstep)
let (pv, nv) = (step.prev, step.next)
var d = 0.0 # (hypot(cv.x - pv.x, cv.y - pv.y) - (prev_step.radius - step.radius).abs.float * 1.02).float
if d < 0:
if step.radius < prev_step.radius:
step.radius -= d
replaced = true
continue
d = 0.0 # (hypot(cv.x - nv.x, cv.y - nv.y) - (nxt_step.radius - step.radius).abs.float * 1.02).float
if d < 0:
if step.radius < nxt_step.radius:
step.radius -= d
replaced = true
continue
var (hx, hy) = (0.0, 0.0) # convex_kkk(prev_step, step, nxt_step, r)
step.xt = hx != NilFloat
if true: # collapse and step.xt:
let (pv, nv) = (step.prev, step.next)
var hv0 = XVertex()
initialize(hv0, hx, hy)
assert hv0.x != NaN
replaced = true
let pvx = pv.x
let pvy = pv.y
let nvx = nv.x
let nvy = nv.y
var pp: Step = nil # prev_step.pstep
if (pp != nil):
(hx, hy) = (0.0, 0.0) # convex_kkk(pp, prev_step, step)
var ppv: XVertex
if pp != nil and hx != NilFloat:
ppv = XVertex()
initialize(ppv, hx, hy)
else:
ppv = pv
if ppv.x == 0:
echo ppv.x# ; assert false
let nn: Step = nil # = nxt_step.nstep
if nn != nil:
(hx, hy) = (0.0, 0.0) # convex_kkk(step, nxt_step, nn)
var nnv: XVertex
if nn != nil and hx != NilFloat:
nnv = XVertex()
initialize(nnv, hx, hy)
else:
nnv = nv
hx = nvx - pvx
hy = nvy - pvy
var vec_x, vec_y: float
if step.rgt:
(vec_x, vec_y) = (hy, -hx)
else:
(vec_x, vec_y) = (-hy, hx)
let hv3 = XVertex(x: pvx + hx / 2 + vec_x, y: pvy + hy / 2 + vec_y)
initialize(hv3, pvx + hx / 2 + vec_x, pvy + hy / 2 + vec_y)
hx *= 2
hy *= 2
vec_x *= 2
vec_y *= 2
let hv4 = XVertex(x: pvx - hx + vec_x, y: pvy - hy + vec_y, tradius: 100)
initialize(hv4, pvx - hx + vec_x, pvy - hy + vec_y)
let hv5 = XVertex(x: nvx + hx + vec_x, y: nvy + hy + vec_y, tradius: 100)
initialize(hv5, nvx + hx + vec_x, nvy + hy + vec_y)
var rep: seq[XVertex] = vertices_in_polygon(@[ppv, hv0, nnv, hv3], r.vertices)# - [pv, nv, ppv, cv, nnv, hv3]
#discard hv0 == nil
#discard hv3 == nil
# [
for el in [ppv, hv0, nnv, hv3]:
echo "-----"
echo el.x
let hhh = rep
if rep.len > 100:
let net = step.net_desc
for v in rep:
v.trgt = not step.rgt
v.tradius = v.radius + [net.trace_clearance, v.separation].max + net.trace_width / 2
pv.trgt = step.pstep.rgt
pv.tradius = step.pstep.radius
nv.trgt = step.nstep.rgt
nv.tradius = step.nstep.radius
rep = @[] # new_convex_vertices(rep, pv, nv, hv4, hv5)
for el in rep:
if true: break
smart_replace(step, rep)
proc main =
var r = Router()
var v = XVertex()
var s = Step()
s.next = XVertex()
s.prev = XVertex()
v.attached_nets.add(s)
initialize(v, 0, 0)
r.vertices.add(v)
nubly(r)
main() Runs without terminating with refc, but with ARC
I think the core issue is vertices_in_polygon(), the refs are moved to that proc, but used later in the constructed array. |
--cursorInference: off does not help. |
Unfortunately I can not create a tiny example that shows the bug -- my tiny example works fine.
I have this proc, which is a bit ugly still as it is converted from my ugly Ruby code:
In this form the program compiled with arc crash:
Uncomenting the two
makes it work fine. Initially I used echo instead of discard, with echo enabled it works fine too. Guess was that scope based destructors release the local references hv0 and hv3 too early. And indeed, when we look at the C sources
may confirm this impression? First hv0 = 0; and later T99_[1] = hv0;
Will close this issue tomorrow, maybe I can reopen in some months when I have more information or a self contained tiny example.
The text was updated successfully, but these errors were encountered: