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

fix: only consider salient bytes in sharecommon eq, hash #5840

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

tkoeppe
Copy link
Contributor

@tkoeppe tkoeppe commented Oct 25, 2024

This PR changes lean_sharecommon_{eq,hash} to only consider the salient bytes of an object, and not any bytes of any unspecified/uninitialized unused capacity.

Accessing uninitialized storage results in undefined behaviour.

This does not seem to have any semantics disadvantages: If objects compare equal after this change, their salient bytes are still equal. By contrast, if the actual identity of allocations needs to be distinguished, that can be done by just comparing pointers to the storage.

If we wanted to retain the current logic, we would need initialize the otherwise unused parts to some specific value to avoid the undefined behaviour.

Closes #5831

@tkoeppe tkoeppe changed the title [sharecommon] Only consider salient bytes in eq, hash fix: Only consider salient bytes in sharecommon eq, hash Oct 25, 2024
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Oct 25, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Oct 25, 2024

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 4c0d12b3f1e8fdb4002eb01f8f5ff9be9ec4b25b --onto 193b6f2bec332ac0bce33e10856a96163d4be456. (2024-10-25 16:07:27)
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2024-11-18 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. (2024-11-18 10:21:43)

@leanprover-bot leanprover-bot added the P-high We will work on this issue label Nov 8, 2024
Copy link
Member

@Kha Kha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM all in all modulo comments

src/include/lean/lean.h Outdated Show resolved Hide resolved
src/runtime/sharecommon.cpp Outdated Show resolved Hide resolved
Change "lean_sharecommon_{eq,hash}" to only consider the salient bytes
of an object, and not any bytes of any unspecified/uninitialized unused
capacity.

Accessing uninitialized storage results in undefined behaviour.

This does not seem to have any semantics disadvantages: If objects
compare equal after this change, their salient bytes are still
equal. By contrast, if the actual identity of allocations needs to be
distinguished, that can be done by just comparing pointers to the
storage.

If we wanted to retain the current logic, we would need initialize the
otherwise unused parts to some specific value to avoid the undefined
behaviour.
@Kha Kha added the changelog-compiler Compiler, runtime, and FFI label Nov 19, 2024
@Kha Kha changed the title fix: Only consider salient bytes in sharecommon eq, hash fix: only consider salient bytes in sharecommon eq, hash Nov 19, 2024
@Kha Kha enabled auto-merge November 19, 2024 13:56
@Kha Kha added this pull request to the merge queue Nov 19, 2024
Merged via the queue into leanprover:master with commit 91c14c7 Nov 19, 2024
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-compiler Compiler, runtime, and FFI P-high We will work on this issue toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ShareCommon.Object.hash assigns mismatching hashes to equal objects
5 participants