leanprover-community / leanprover-community/lean
`is_bi_equal` use of BinderInfo-unaware hashes causes many collisions (a.k.a. timeout when saving oleans)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 434
- Forks
- 79
- PR merge metrics
- No merged PRs in 30d
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Checked that your issue isn't already filed.
- Specifically, check out the wishlist, open RFCs,
or feature requests.
- Specifically, check out the wishlist, open RFCs,
- Reduced the issue to a self-contained, reproducible test case.
- Checked that your issue isn't already filed.
Description
@digama0's testcase from https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/.22saving.20olean.22.3F, reproduced below, fails to produce oleans with lean --make -T100000 test.lean:
import algebra.field.basic
import algebra.order.ring
set_option old_structure_cmd true
class linear_ordered_semifield (α : Type*)
extends linear_ordered_semiring α, semifield α
class linear_ordered_field (α : Type*) extends linear_ordered_comm_ring α, field α
I investigated the problem a bit and found out that serializing those objects involves a lot of comparisons which increment the heartbeat counter. In particular, a lot of time is spent comparing deep expressions for BinderInfo-aware equality; the expression hash used in the comparison does not include BinderInfo data, and the above example seems to involve expressions which all have the same hash despite being different for the purposes of is_bi_equal.
Since there are only two comparison modes, a possible fix would be to have two hashes, one for each choice of CompareBinderInfo. I can't tell if this is worth the extra time and memory.
(Note: The above example may hit #748 on a debug build. Those issues may or may not be related.)
Steps to Reproduce
- Run
lean --make -T100000 test.leanon the above file
Expected behavior: Valid oleans should be output
Actual behavior: Empty oleans
Reproduces how often: 100%
Versions
Lean (version 3.45.0, commit 22b09be35ef6, Release)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the supplied test.lean command and inspect src/util/object_serializer.h, src/kernel/expr_eq_fn.cpp, and the BinderInfo-aware comparison and hashing paths referenced in the report. Done means the testcase produces valid, non-empty oleans without the timeout or excessive comparisons described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100