Skip to content

deeply-nested chain hangs with Item = u32 #70749

Open
@cuviper

Description

@cuviper

I tried this code:

pub fn foo() -> Box<Iterator<Item = u32>> {
    use std::iter::empty;

    Box::new(empty()
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty()) // 10th .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty()) // 16th .chain(empty())
    )
}

This is adapted from the deeply-nested test, just changing Item = () to Item = u32.

Building with rustc +nightly --crate-type lib -Copt-level=2 src/lib.rs seems to hang indefinitely.

I expected to see this happen: completion in a few seconds at most.

Instead, this happened: I'm still waiting...

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (537ccdf3a 2020-04-02)
binary: rustc
commit-hash: 537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae
commit-date: 2020-04-02
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0

Also happens on 1.42.0 and 1.43.0-beta.3.

Attaching rust-gdb, I see two busy LLVM threads:

Backtrace

Thread 6 (Thread 0x7f70bd5ff700 (LWP 207946)):
#0  0x00007f70c72133db in llvm::DominatorTreeBase<llvm::BasicBlock, false>::dominates(llvm::BasicBlock const*, llvm::BasicBlock const*) const () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#1  0x00007f70c7e2298a in llvm::GVN::findLeader(llvm::BasicBlock const*, unsigned int) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#2  0x00007f70c7e23279 in llvm::GVN::processInstruction(llvm::Instruction*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#3  0x00007f70c7e24977 in llvm::GVN::processBlock(llvm::BasicBlock*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#4  0x00007f70c7e1aff0 in llvm::GVN::runImpl(llvm::Function&, llvm::AssumptionCache&, llvm::DominatorTree&, llvm::TargetLibraryInfo const&, llvm::AAResults&, llvm::MemoryDependenceResults*, llvm::LoopInfo*, llvm::OptimizationRemarkEmitter*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#5  0x00007f70c7e27098 in llvm::gvn::GVNLegacyPass::runOnFunction(llvm::Function&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#6  0x00007f70c727842f in llvm::FPPassManager::runOnFunction(llvm::Function&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#7  0x00007f70c8233a78 in (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#8  0x00007f70c7279030 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#9  0x00007f70c71e210a in LLVMRunPassManager () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#10 0x00007f70caa79b43 in rustc_codegen_llvm::back::write::optimize () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#11 0x00007f70caa3ef17 in rustc_codegen_ssa::back::write::execute_work_item () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#12 0x00007f70cab2680e in std::sys_common::backtrace::__rust_begin_short_backtrace () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#13 0x00007f70caa08eb5 in core::ops::function::FnOnce::call_once{{vtable-shim}} () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#14 0x00007f70c9fe92ff in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae/src/liballoc/boxed.rs:1008
#15 0x00007f70ca01c813 in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae/src/liballoc/boxed.rs:1008
#16 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:13
#17 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:80
#18 0x00007f70c9f534e2 in start_thread () from /lib64/libpthread.so.0
#19 0x00007f70c9e706d3 in clone () from /lib64/libc.so.6

Thread 5 (Thread 0x7f70be1ff700 (LWP 207945)):
#0  0x00007f70c7213354 in llvm::DominatorTreeBase<llvm::BasicBlock, false>::dominates(llvm::BasicBlock const*, llvm::BasicBlock const*) const () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#1  0x00007f70c7e2298a in llvm::GVN::findLeader(llvm::BasicBlock const*, unsigned int) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#2  0x00007f70c7e23279 in llvm::GVN::processInstruction(llvm::Instruction*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#3  0x00007f70c7e24977 in llvm::GVN::processBlock(llvm::BasicBlock*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#4  0x00007f70c7e1aff0 in llvm::GVN::runImpl(llvm::Function&, llvm::AssumptionCache&, llvm::DominatorTree&, llvm::TargetLibraryInfo const&, llvm::AAResults&, llvm::MemoryDependenceResults*, llvm::LoopInfo*, llvm::OptimizationRemarkEmitter*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#5  0x00007f70c7e27098 in llvm::gvn::GVNLegacyPass::runOnFunction(llvm::Function&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#6  0x00007f70c727842f in llvm::FPPassManager::runOnFunction(llvm::Function&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#7  0x00007f70c8233a78 in (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#8  0x00007f70c7279030 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#9  0x00007f70c71e210a in LLVMRunPassManager () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#10 0x00007f70caa79b43 in rustc_codegen_llvm::back::write::optimize () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#11 0x00007f70caa3ef17 in rustc_codegen_ssa::back::write::execute_work_item () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#12 0x00007f70cab2680e in std::sys_common::backtrace::__rust_begin_short_backtrace () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#13 0x00007f70caa08eb5 in core::ops::function::FnOnce::call_once{{vtable-shim}} () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#14 0x00007f70c9fe92ff in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae/src/liballoc/boxed.rs:1008
#15 0x00007f70ca01c813 in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae/src/liballoc/boxed.rs:1008
#16 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:13
#17 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:80
#18 0x00007f70c9f534e2 in start_thread () from /lib64/libpthread.so.0
#19 0x00007f70c9e706d3 in clone () from /lib64/libc.so.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions