leanprover / leanprover/lean4

Building Lean 4.15-rc1 with default build settings runs into a Stack Overflow in Data/UInt/Lemmas.lean

Open
#6,434 18 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

Building Lean 4.15-rc1 from source with the default build settings fails with a stack overflow when compiling Data/UInt/Lemmas.lean for stage1.

Context

I am not sure if this is specific to my system, or if others might be running into the same issue. Also, not sure why it doesn't happen in CI. Compiling Lean 4.14 with identical settings was working fine on the same machine.

Looking at the call-stack in the crashdump, there are over 3000 recursions of l_Lean_IR_NormalizeIds_normFnBody. However, it is not an infinite recursion, as increasing the thread stack size via LEAN_EXTRA_MAKE_OPTS allows to work around this build issue.
I haven't tested what stack size exactly is needed, but passing -DLEAN_EXTRA_MAKE_OPTS="-s 262144" to cmake allowed the build to finish.

Depending on the question if anyone else sees this, it might be a good idea to set a higher default stack size while building Lean.

Steps to Reproduce
  1. Compile Lean 4.15-rc1 from source with default settings on AMD64 Linux

Expected behavior: The build succeeds

Actual behavior: The build fails with a stack overflow when compiling Data/UInt/Lemmas.lean

Versions

Gentoo Linux, kernel 6.6.62, gcc (Gentoo 14.2.1_p20241116 p3) 14.2.1 20241116

Additional Information

I've used an ebuild to build lean4. Not sure if this is relevant, but for the sake of completeness:
Edit: This is the ebuild that already passes -DLEAN_EXTRA_MAKE_OPTS="-s 262144". To repro the issue with it, please remove the respective line.


MAJOR="$(ver_cut 1)"

CMAKE_MAKEFILE_GENERATOR="emake"
PYTHON_COMPAT=( python3_{10..12} )

inherit cmake flag-o-matic python-any-r1

DESCRIPTION="The Lean Theorem Prover"
HOMEPAGE="https://leanprover-community.github.io/"

if [[ "${PV}" == *9999* ]] ; then
	inherit git-r3

	EGIT_REPO_URI="https://github.com/leanprover/${PN}${MAJOR}.git"
else
	SRC_URI="https://github.com/leanprover/${PN}${MAJOR}/archive/refs/tags/v${PV/_/-}.tar.gz
		-> ${P}.tar.gz"
	S="${WORKDIR}/${PN}${MAJOR}-${PV/_/-}"

	KEYWORDS="~amd64 ~x86"
fi

LICENSE="Apache-2.0"
SLOT="0/${MAJOR}"
IUSE="debug source"

RDEPEND="
	dev-libs/gmp:=
	sci-mathematics/cadical
"
DEPEND="
	${RDEPEND}
"
BDEPEND="
	${PYTHON_DEPS}
"

pkg_setup() {
	python-any-r1_pkg_setup
}

src_prepare() {
	filter-lto

	sed -e "s|-O[23]|${CFLAGS}|g" -i src/CMakeLists.txt || die

	cmake_src_prepare
}

src_configure() {
	local CMAKE_BUILD_TYPE

	if use debug ; then
		CMAKE_BUILD_TYPE="Debug"
	else
		CMAKE_BUILD_TYPE="Release"
	fi

	local -a mycmakeargs=(
		-DLEAN_EXTRA_CXX_FLAGS="${CXXFLAGS}"
		-DLEAN_EXTRA_LINKER_FLAGS="${LDFLAGS}"
		-DLEAN_EXTRA_MAKE_OPTS="-s 262144"
		-DINSTALL_CADICAL=OFF
	)
	cmake_src_configure
}

src_install() {
	cmake_src_install

	rm "${ED}/usr/LICENSE"* || die

	if ! use source ; then
		rm -r "${ED}/usr/src" || die
	fi
}
Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the stage1 build on AMD64 Linux with default settings and observe compilation of Data/UInt/Lemmas.lean. Compare it with the LEAN_EXTRA_MAKE_OPTS="-s 262144" workaround, then determine a suitable default-build change; done means Lean 4.15-rc1 builds successfully without manually increasing the stack size.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.