In following I show some code for the problem program, but don’t have a small demo for the problem, and at this point don’t have permission to post the whole 800-line program. I hope that someone can say what causes the problem and how to avoid the errors.
Program toverflow3.jl
runs to completion in Julia 1.7.0-rc2, 1.7.2, and 1.9.0-DEV with ~17 sec. compilation, ~ 70 milliseconds computation. Slightly-different toverflow4.jl
running in 1.7.2 produced 136000 error-message lines (repeating exactly the same error message set about 10000 times, plus ~80 scattered variants) in about 15 minutes before it reached an 8MiB limit I’d set via script
. In 1.9.0-DEV, toverflow4.jl
ran to ok completion in 27 seconds while producing some 5 dozen error-message lines. The two lines shown below repeated 30 times each:
Internal error: stack overflow in type inference of (::findRP.var"#findMore#15"{findRP.OptValues, Array{Array{Float64, N} where N, 1}, Array{Tuple, 1}, Array{Array{Float64, 1}, 1}, Array{Int32, 1}, Array{Int32, 1}, Array{Float64, 1}, Int64, Float64})(Int64).
This might be caused by recursion over very long tuples or argument lists.
It’s true that findMore
is recursive, but it doesn’t recurse more than 3 levels deep, and it has only one argument, level
. In outline, it is like:
function findMore(level)::Nothing
for v[level] in cots[v[level-1]]
...
if level ≥ tVerts
writeRP(vops, points, v[1:tVerts])
else
findMore(level+1)
end
end
return nothing
end
where findmore, v, cots, and tVerts all are defined in the function findPoly3(vops, points, sds, maxVerts, cots)
and non-recursive writeRP is defined elsewhere in the module, via
function writeRP(vops, points, v)::Nothing
...
<Compute f1, f2, then output with them - see below>
...
return nothing
end
Note, I added ::Nothing
and return nothing
phrases for both findMore and writeRP with the notion that that might aid Julia in type inference. It made no difference; results were the same with or without those phrases.
The difference between toverflow3.jl
and toverflow4.jl
is shown next, along with wc
results for both; Julia --version output; using
line. The 10 lines marked with ! are what differ between the two files.
> diff -C3 toverflow3.jl toverflow4.jl
*** toverflow3.jl 2022-05-07 21:11:28.705168072 -0600
--- toverflow4.jl 2022-05-07 21:11:30.325142445 -0600
***************
*** 221,231 ****
println(fos("raxi",raxi), fos("zaxi",zaxi), fos("atra",atra)); flush(stdout)
pz = [vj-1 for vj in v] # Zero-base the point indices in following
f1 = vops.q ?
! # j n r s cx cy cz nx ny nz
! "{:4d} {:2d} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f}" :
! # j n r s cx cy cz nx ny nz
! " RPFace({:4d}, {:2d}, {:8.5f}, {:8.5f}, [{:8.5f}, {:8.5f}, {:8.5f}], [{:8.5f}, {:8.5f}, {:8.5f}], "
! printfmt(DRP.Pfi, f1, DRP.RPnumber, n, r, s, c[1],c[2],c[3], nnnv[1],nnnv[2],nnnv[3])
f2 = vops.q ?
string([" {:3d}" for i in pz]..., '\n') :
string('[', [" {:3d}," for i in pz]..., "]);\n")
--- 221,231 ----
println(fos("raxi",raxi), fos("zaxi",zaxi), fos("atra",atra)); flush(stdout)
pz = [vj-1 for vj in v] # Zero-base the point indices in following
f1 = vops.q ?
! # j n r s raxi zaxi cx cy cz nx ny nz
! "{:4d} {:2d} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f} {:9.5f}" :
! # j n r s raxi zaxi cx cy cz nx ny nz
! " RPFace({:4d}, {:2d}, {:8.5f}, {:8.5f}, {:8.5f}, {:8.5f}, [{:8.5f}, {:8.5f}, {:8.5f}], [{:8.5f}, {:8.5f}, {:8.5f}], "
! printfmt(DRP.Pfi, f1, DRP.RPnumber, n, r, s, raxi, zaxi, c[1],c[2],c[3], nnnv[1],nnnv[2],nnnv[3])
f2 = vops.q ?
string([" {:3d}" for i in pz]..., '\n') :
string('[', [" {:3d}," for i in pz]..., "]);\n")
> wc toverflow3.jl toverflow4.jl
780 3349 29658 toverflow3.jl
780 3359 29738 toverflow4.jl
1560 6708 59396 total
> julia-1.7.0 --version
julia version 1.7.0-rc2
> julia-latest --version
julia version 1.9.0-DEV
> julia --version
julia version 1.7.2
> grep using toverflow3.jl
using Formatting, LinearAlgebra, Rotations, JSON3
In above, fos
prints a value as a formatted string. Also, the last lines of output from toverflow3 and toverflow4 are
RPFace( 28, 3, 1.41421, 2.44949, [ 0.00000, 0.00000, 0.00000], [-3.00000, 3.00000, -3.00000], [ 3, 8, 5,]);
RPFace( 28, 3, 1.41421, 2.44949, -0.36137, 2.96468, [ 0.00000, 0.00000, 0.00000], [-3.00000, 3.00000, -3.00000], [ 3, 8, 5,]);
respectively.