Skip to content
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

Regression: simple loop in v1.9 hangs when iterating over elements of a linked list #49935

Closed
berndblasius opened this issue May 23, 2023 · 4 comments
Labels
backport 1.9 Change should be backported to release-1.9 regression Regression in behavior compared to a previous version

Comments

@berndblasius
Copy link

Here is a conceived example of simple heterogeneous linked list:

struct List{T}
  head :: T
  tail :: List{T}
  List{T}() where T = new()    # emply list is incompletely defined
  List{T}(x::T,l::List{T}) where T = new(x,l)
end

const ElemType = Union{Int,List}
const NIL = List{ElemType}()
cons(x,y) = List{ElemType}(x,y) 

pop(q::List) = (q.head, q.tail)
iscons(q::List) = isdefined(q,:tail)

When running reverse2 function over a small list Julia hangs (the loop does not terminate)

function reverse2(q)
  println("start")
  q1 = NIL
  while iscons(q)
  #while q != NIL  # generates the same problem
    head, q = pop(q)
    q1 = cons(head,q1)
  end
  q1
end

reverse2(cons(1, NIL))

The function does not even print "start", so maybe it is stuck already during compilation (?)
The problem appears with Julia 1.9.0. This was not an issue for earlier Julia versions, e.g. 1.6 or 1.7 (did not check on 1.8).

Interstingly, the problem does not appear when the list is not passed to, but constructed inside, the function

function reverse1()
  println("start")  
  q = cons(1,NIL)  
  q1 = NIL
  while iscons(q)
    head, q = pop(q)
    q1 = cons(head,q1)
  end
  q1
end

reverse1()
@KristofferC
Copy link
Member

KristofferC commented May 23, 2023

Seems fixed on master.

julia> reverse2(cons(1, NIL))
start
List{ElemType}(1, List{ElemType}(#undef, #undef))

On 1.9, Ctrl+C gives

julia> reverse2(cons(1, NIL))
^C^C^C^C^CWARNING: Force throwing a SIGINT
Internal error: encountered unexpected error in runtime:
InterruptException()
isvarargtype at ./essentials.jl:377 [inlined]
⊑ at ./compiler/typelattice.jl:263
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
^C⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
^C⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
⊑ at ./compiler/typelattice.jl:273
....

@gbaraldi
Copy link
Member

Fix bisected to #49271. Not sure when it broke. During the bisect the sigint printing changed but it still hung.

@vtjnash
Copy link
Member

vtjnash commented May 23, 2023

Fascinating to get a test case for that PR finally, 1 month after writing it.

@gbaraldi
Copy link
Member

Is that PR backportable to 1.9?

@brenhinkeller brenhinkeller added the regression Regression in behavior compared to a previous version label Aug 4, 2023
@vtjnash vtjnash closed this as completed Feb 6, 2024
@vtjnash vtjnash added the backport 1.9 Change should be backported to release-1.9 label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.9 Change should be backported to release-1.9 regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

5 participants