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

Remove byte swap of valtree hash on big endian #103231

Merged
merged 1 commit into from
Oct 22, 2022
Merged

Conversation

ecnelises
Copy link
Contributor

This addresses problem reported in #103183. The code was originally introduced in e14b34c. (see #96591)

On big-endian environment, this operation sequence actually put the other half from 128-bit result, thus we got different hash result on LE and BE.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 19, 2022
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 19, 2022
@ecnelises
Copy link
Contributor Author

FYI @lcnr @b-naber

Another suspicious thing is how downcast from u128 to u64 is handled in each platform. Per my understanding, it should always be cut so higher 64-bits are removed.

@lcnr
Copy link
Contributor

lcnr commented Oct 19, 2022

i remember this not working before, i guess lets go with

@bors r+ rollup=iffy

@bors
Copy link
Contributor

bors commented Oct 19, 2022

📌 Commit 7b5a366 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 19, 2022
@lcnr lcnr assigned lcnr and unassigned estebank Oct 19, 2022
@b-naber
Copy link
Contributor

b-naber commented Oct 19, 2022

Wasn't the problem that the StableHasherResult impl for u64 was wrong? We just use the first value of the tuple that StableHasher::finalize returns. This causes different values values on LE and BE machines afaict. Seems like that should be fixed instead.

@bors
Copy link
Contributor

bors commented Oct 22, 2022

⌛ Testing commit 7b5a366 with merge f8c86c8...

@bors
Copy link
Contributor

bors commented Oct 22, 2022

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing f8c86c8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 22, 2022
@bors bors merged commit f8c86c8 into rust-lang:master Oct 22, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 22, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f8c86c8): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.3% [4.6%, 5.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Footnotes

  1. the arithmetic mean of the percent change

  2. number of relevant changes

@ecnelises
Copy link
Contributor Author

ecnelises commented Oct 26, 2022

Wasn't the problem that the StableHasherResult impl for u64 was wrong? We just use the first value of the tuple that StableHasher::finalize returns. This causes different values values on LE and BE machines afaict. Seems like that should be fixed instead.

Hi, I tried print the value:

impl StableHasherResult for u128 {
    #[inline]
    fn finish(hasher: StableHasher) -> Self {
        let (_0, _1) = hasher.finalize();
        u128::from(_0) | (u128::from(_1) << 64)
    }
}

impl StableHasherResult for u64 {
    #[inline]
    fn finish(hasher: StableHasher) -> Self {
        let f = hasher.finalize();
        println!("{} {}", f.0, f.1);
        f.0
    }
}

For the case, both little-endian and big-endian machine print:

7154186058328073752 6777639898671907003

Not sure if this can trigger the failure you mentioned, but here the cut for u64 and u128 construction look correct to me.

@b-naber
Copy link
Contributor

b-naber commented Oct 26, 2022

Thanks for investigating. I'm not really sure what's going on, it's seems weird to me. I remember that when we had the CI failure in that PR the values were flipped on that one machine and we had the hypothesis that this was an endianness problem and making the change in that commit did fix the CI failure. Can't explain why the original version of that code works now.

Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
Remove byte swap of valtree hash on big endian

This addresses problem reported in rust-lang#103183. The code was originally introduced in rust-lang@e14b34c. (see rust-lang#96591)

On big-endian environment, this operation sequence actually put the other half from 128-bit result, thus we got different hash result on LE and BE.
@ecnelises ecnelises deleted the le_fix branch March 23, 2023 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants