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

Nested tuple construction hangs forever in 1.10 and earlier #56052

Open
luchr opened this issue Oct 8, 2024 · 3 comments
Open

Nested tuple construction hangs forever in 1.10 and earlier #56052

luchr opened this issue Oct 8, 2024 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference

Comments

@luchr
Copy link

luchr commented Oct 8, 2024

Take the following test file nestedtuples.jl:

function please_return()
  tup = ()
  for _ in 1:2
    tup = (tup, ())
  end
  return tup
end

@show please_return()

The function please_return does not terminate (julia hangs forever) for version 1.10.5. It does terminate and returns the expected result in version 1.11.0 though.

Output:

julia> versioninfo()
Julia Version 1.10.5
Commit 6f3fdf7b362 (2024-08-27 14:19 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × 12th Gen Intel(R) Core(TM) i5-1240P
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

julia> include("./nestedtuples.jl")

<<<hangs forever>>>

For comparison the output of 1.11:

julia> versioninfo()
Julia Version 1.11.0
Commit 501a4f25c2b (2024-10-07 11:40 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × 12th Gen Intel(R) Core(TM) i5-1240P
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)


julia> include("./nestedtuples.jl")
please_return() = (((), ()), ())
(((), ()), ())

Is this a known bug/feature?

@oscardssmith oscardssmith added bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference labels Oct 8, 2024
@oscardssmith
Copy link
Member

This appears to be a bug in tmerge that goes back at least as far as 1.6. Good to see that it's fixed in 1.11.

@oscardssmith
Copy link
Member

specifically, the bug is that

T = Tuple{}
T_old = Union{}
while T != T_old
    T_old, T = T, Core.Compiler.tmerge(T, Tuple{T, Tuple{}})
end

is an infinite loop prior to 1.11

@oscardssmith
Copy link
Member

oscardssmith commented Oct 8, 2024

This was likely fixed by some combination of #55757, #50927, and #53876. @Keno, @vtjnash any opinions on the backport-ability of these?

@oscardssmith oscardssmith changed the title Nested tuple construction hangs forever in 1.10.5 Nested tuple construction hangs forever in 1.10 and earlier Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

2 participants