Repository navigation
fix: choose LEAN_SCALAR_PTR_LITERAL by pointer size, not by LEAN_EMSCRIPTEN - #15816
basvandijk wants to merge 1 commit into
Conversation
…MSCRIPTEN` This PR fixes the scalar fields of static objects, such as the hashes of name literals, on 32-bit targets such as wasm32-wasip1 and i686, by choosing the form of `LEAN_SCALAR_PTR_LITERAL` by pointer size instead of by `LEAN_EMSCRIPTEN`. Since leanprover#12082, the compiler writes the scalar fields of static constructor objects in 8-byte chunks with `LEAN_SCALAR_PTR_LITERAL`. Unless `LEAN_EMSCRIPTEN` was defined, `lean.h` used its 64-bit form, which on a 32-bit target casts each chunk to a single 4-byte pointer: each object got one slot per chunk instead of two and lost the upper half of every chunk, without a compiler warning. A name literal then had a wrong hash, and compared unequal to the same name built at run time. Lean's build defines `LEAN_EMSCRIPTEN` only for its own C++ code, not for the C that `leanc` compiles, so this affected Emscripten too. On 64-bit targets, the preprocessed `lean.h` does not change. The new test `tests/compile/static_scalar_fields.lean` compares the scalar fields of several kinds of static objects, including a name literal's hash, with the same values built at run time. CI has no 32-bit job, so there it passes with or without this change; on wasm32-wasip1 it fails without it. Claude Code, an AI coding assistant, helped with the investigation, the change, the test and this description. I reviewed and checked them. Closes leanprover#15814 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
How this was tested:
The bug dates from #12082 (v4.29.0). CI's Web Assembly and Linux 32bit jobs had been disabled before that, in #6424 and #7924. A correction to #15814: generated C is affected on Emscripten too, since Lean's build defines
|
This PR fixes the scalar fields of static objects, such as the hashes of name literals, on 32-bit targets such as wasm32-wasip1 and i686, by choosing the form of
LEAN_SCALAR_PTR_LITERALby pointer size instead of byLEAN_EMSCRIPTEN.Since #12082, the compiler writes the scalar fields of static constructor objects in 8-byte chunks with
LEAN_SCALAR_PTR_LITERAL. UnlessLEAN_EMSCRIPTENwas defined,lean.hused its 64-bit form, which on a 32-bit target casts each chunk to a single 4-byte pointer: each object got one slot per chunk instead of two and lost the upper half of every chunk, without a compiler warning. A name literal then had a wrong hash, and compared unequal to the same name built at run time. Lean's build definesLEAN_EMSCRIPTENonly for its own C++ code, not for the C thatleanccompiles, so this affected Emscripten too. On 64-bit targets, the preprocessedlean.hdoes not change.The new test
tests/compile/static_scalar_fields.leancompares the scalar fields of several kinds of static objects, including a name literal's hash, with the same values built at run time. CI has no 32-bit job, so there it passes with or without this change; on wasm32-wasip1 it fails without it.Claude Code, an AI coding assistant, helped with the investigation, the change, the test and this description. I reviewed and checked them.
Closes #15814
🤖 Generated with Claude Code