Skip to content

Commit a466104

Browse files
authored
feat(turbo-tasks-hash): update twox-hash (#82518)
### What Avoid using two versions of `twox-hash`
1 parent ecb3441 commit a466104

File tree

534 files changed

+644
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

534 files changed

+644
-667
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ exclude = ["crates/next-error-code-swc-plugin"]
2222
too_many_arguments = "allow"
2323

2424
[workspace.lints.rust]
25-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust_analyzer)', 'cfg(fuzzing)'] }
25+
unexpected_cfgs = { level = "warn", check-cfg = [
26+
'cfg(rust_analyzer)',
27+
'cfg(fuzzing)',
28+
] }
2629

2730
# This crate is particularly sensitive to compiler optimizations
2831
[profile.dev.package.turbo-persistence]
@@ -370,22 +373,22 @@ lightningcss = { version = "1.0.0-alpha.67", features = [
370373
"serde",
371374
"visitor",
372375
"into_owned",
373-
"browserslist"
376+
"browserslist",
374377
] }
375378
lightningcss-napi = { version = "0.4.4", default-features = false, features = [
376379
"visitor",
377380
] }
378381
markdown = "1.0.0-alpha.18"
379382
mime = "0.3.16"
380383
napi = { version = "2", default-features = false, features = [
381-
"napi3",
382-
"serde-json",
383-
"tokio_rt",
384-
"error_anyhow",
385-
# Lightningcss uses this features
386-
"napi4",
387-
"napi5",
388-
"compat-mode"
384+
"napi3",
385+
"serde-json",
386+
"tokio_rt",
387+
"error_anyhow",
388+
# Lightningcss uses this features
389+
"napi4",
390+
"napi5",
391+
"compat-mode",
389392
] }
390393
notify = "8.1.0"
391394
once_cell = "1.17.1"
@@ -409,6 +412,7 @@ ringmap = "0.1.3"
409412
roaring = "0.10.10"
410413
rstest = "0.16.0"
411414
rustc-hash = "2.1.1"
415+
twox-hash = { version = "2.0.1", features = ["xxhash64"] }
412416
semver = "1.0.16"
413417
serde = { version = "1.0.217", features = ["derive"] }
414418
serde_json = "1.0.138"
@@ -437,12 +441,8 @@ triomphe = { git = "https://github.com/sokra/triomphe", branch = "sokra/unstable
437441
unsize = "1.1.0"
438442
url = "2.2.2"
439443
urlencoding = "2.1.2"
440-
vergen = { version = "9.0.6", features = [
441-
"cargo",
442-
] }
443-
vergen-gitcl = { version = "1.0.8", features = [
444-
"cargo",
445-
] }
444+
vergen = { version = "9.0.6", features = ["cargo"] }
445+
vergen-gitcl = { version = "1.0.8", features = ["cargo"] }
446446
webbrowser = "0.8.7"
447447

448448
[patch.crates-io]

test/e2e/app-dir/next-image/next-image-https.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe.skip('app dir - next-image (with https)', () => {
3636

3737
if (process.env.IS_TURBOPACK_TEST) {
3838
expect(src).toMatchInlineSnapshot(
39-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=90"`
39+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=90"`
4040
)
4141
} else {
4242
expect(src).toMatchInlineSnapshot(

test/e2e/app-dir/next-image/next-image-proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('next-image-proxy', () => {
8080

8181
if (process.env.IS_TURBOPACK_TEST) {
8282
expect(local).toMatchInlineSnapshot(
83-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=90"`
83+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=90"`
8484
)
8585
} else {
8686
expect(local).toMatchInlineSnapshot(

test/e2e/app-dir/next-image/next-image.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('app dir - next-image', () => {
1818

1919
if (process.env.IS_TURBOPACK_TEST) {
2020
expect(layout.attr('src')).toMatchInlineSnapshot(
21-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=85"`
21+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=85"`
2222
)
2323
} else {
2424
expect(layout.attr('src')).toMatchInlineSnapshot(
@@ -28,7 +28,7 @@ describe('app dir - next-image', () => {
2828

2929
if (process.env.IS_TURBOPACK_TEST) {
3030
expect(layout.attr('srcset')).toMatchInlineSnapshot(
31-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=640&q=85 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=85 2x"`
31+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=640&q=85 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=85 2x"`
3232
)
3333
} else {
3434
expect(layout.attr('srcset')).toMatchInlineSnapshot(
@@ -40,7 +40,7 @@ describe('app dir - next-image', () => {
4040

4141
if (process.env.IS_TURBOPACK_TEST) {
4242
expect(page.attr('src')).toMatchInlineSnapshot(
43-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=90"`
43+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=90"`
4444
)
4545
} else {
4646
expect(page.attr('src')).toMatchInlineSnapshot(
@@ -50,7 +50,7 @@ describe('app dir - next-image', () => {
5050

5151
if (process.env.IS_TURBOPACK_TEST) {
5252
expect(page.attr('srcset')).toMatchInlineSnapshot(
53-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=640&q=90 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=90 2x"`
53+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=640&q=90 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=90 2x"`
5454
)
5555
} else {
5656
expect(page.attr('srcset')).toMatchInlineSnapshot(
@@ -62,7 +62,7 @@ describe('app dir - next-image', () => {
6262

6363
if (process.env.IS_TURBOPACK_TEST) {
6464
expect(comp.attr('src')).toMatchInlineSnapshot(
65-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=80"`
65+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=80"`
6666
)
6767
} else {
6868
expect(comp.attr('src')).toMatchInlineSnapshot(
@@ -72,7 +72,7 @@ describe('app dir - next-image', () => {
7272

7373
if (process.env.IS_TURBOPACK_TEST) {
7474
expect(comp.attr('srcset')).toMatchInlineSnapshot(
75-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=640&q=80 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=80 2x"`
75+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=640&q=80 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=80 2x"`
7676
)
7777
} else {
7878
expect(comp.attr('srcset')).toMatchInlineSnapshot(
@@ -162,7 +162,7 @@ describe('app dir - next-image', () => {
162162

163163
if (process.env.IS_TURBOPACK_TEST) {
164164
expect(await layout.getAttribute('src')).toMatchInlineSnapshot(
165-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=85"`
165+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=85"`
166166
)
167167
} else {
168168
expect(await layout.getAttribute('src')).toMatchInlineSnapshot(
@@ -172,7 +172,7 @@ describe('app dir - next-image', () => {
172172

173173
if (process.env.IS_TURBOPACK_TEST) {
174174
expect(await layout.getAttribute('srcset')).toMatchInlineSnapshot(
175-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=640&q=85 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=85 2x"`
175+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=640&q=85 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=85 2x"`
176176
)
177177
} else {
178178
expect(await layout.getAttribute('srcset')).toMatchInlineSnapshot(
@@ -184,7 +184,7 @@ describe('app dir - next-image', () => {
184184

185185
if (process.env.IS_TURBOPACK_TEST) {
186186
expect(await page.getAttribute('src')).toMatchInlineSnapshot(
187-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=90"`
187+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=90"`
188188
)
189189
} else {
190190
expect(await page.getAttribute('src')).toMatchInlineSnapshot(
@@ -194,7 +194,7 @@ describe('app dir - next-image', () => {
194194

195195
if (process.env.IS_TURBOPACK_TEST) {
196196
expect(await page.getAttribute('srcset')).toMatchInlineSnapshot(
197-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=640&q=90 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=90 2x"`
197+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=640&q=90 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=90 2x"`
198198
)
199199
} else {
200200
expect(await page.getAttribute('srcset')).toMatchInlineSnapshot(
@@ -206,7 +206,7 @@ describe('app dir - next-image', () => {
206206

207207
if (process.env.IS_TURBOPACK_TEST) {
208208
expect(await comp.getAttribute('src')).toMatchInlineSnapshot(
209-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=80"`
209+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=80"`
210210
)
211211
} else {
212212
expect(await comp.getAttribute('src')).toMatchInlineSnapshot(
@@ -216,7 +216,7 @@ describe('app dir - next-image', () => {
216216

217217
if (process.env.IS_TURBOPACK_TEST) {
218218
expect(await comp.getAttribute('srcset')).toMatchInlineSnapshot(
219-
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=640&q=80 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.308c602d.png&w=828&q=80 2x"`
219+
`"/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=640&q=80 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Ftest.4813cd24.png&w=828&q=80 2x"`
220220
)
221221
} else {
222222
expect(await comp.getAttribute('srcset')).toMatchInlineSnapshot(

test/integration/css/test/basic-global-support.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,17 +557,17 @@ module.exports = {
557557
expect(cssContent).toMatchInlineSnapshot(`
558558
[
559559
"/_next/static/chunks/HASH.css:
560-
.red-text{color:red;background-image:url(../media/dark.993bedd3.svg),url(../media/dark2.993bedd3.svg)}
561-
.blue-text{color:orange;background-image:url(../media/light.180573e4.svg);font-weight:bolder}
560+
.red-text{color:red;background-image:url(../media/dark.8425d343.svg),url(../media/dark2.8425d343.svg)}
561+
.blue-text{color:orange;background-image:url(../media/light.fc9b5caa.svg);font-weight:bolder}
562562
.blue-text{color:#00f}",
563563
]
564564
`)
565565
} else if (process.env.IS_TURBOPACK_TEST && !useLightningcss) {
566566
expect(cssContent).toMatchInlineSnapshot(`
567567
[
568568
"/_next/static/chunks/HASH.css:
569-
.red-text{color:red;background-image:url(../media/dark.993bedd3.svg),url(../media/dark2.993bedd3.svg)}
570-
.blue-text{color:orange;background-image:url(../media/light.180573e4.svg);font-weight:bolder}
569+
.red-text{color:red;background-image:url(../media/dark.8425d343.svg),url(../media/dark2.8425d343.svg)}
570+
.blue-text{color:orange;background-image:url(../media/light.fc9b5caa.svg);font-weight:bolder}
571571
.blue-text{color:#00f}",
572572
]
573573
`)
@@ -626,8 +626,8 @@ describe('CSS URL via `file-loader` and asset prefix (1)', () => {
626626
expect(cssContent).toMatchInlineSnapshot(`
627627
[
628628
"/_next/static/chunks/HASH.css:
629-
.red-text{color:red;background-image:url(../media/dark.993bedd3.svg) url(../media/dark2.993bedd3.svg)}
630-
.blue-text{color:orange;background-image:url(../media/light.180573e4.svg);font-weight:bolder}
629+
.red-text{color:red;background-image:url(../media/dark.8425d343.svg) url(../media/dark2.8425d343.svg)}
630+
.blue-text{color:orange;background-image:url(../media/light.fc9b5caa.svg);font-weight:bolder}
631631
.blue-text{color:#00f}",
632632
]
633633
`)
@@ -678,8 +678,8 @@ describe('CSS URL via `file-loader` and asset prefix (2)', () => {
678678
expect(cssContent).toMatchInlineSnapshot(`
679679
[
680680
"/_next/static/chunks/HASH.css:
681-
.red-text{color:red;background-image:url(../media/dark.993bedd3.svg) url(../media/dark2.993bedd3.svg)}
682-
.blue-text{color:orange;background-image:url(../media/light.180573e4.svg);font-weight:bolder}
681+
.red-text{color:red;background-image:url(../media/dark.8425d343.svg) url(../media/dark2.8425d343.svg)}
682+
.blue-text{color:orange;background-image:url(../media/light.fc9b5caa.svg);font-weight:bolder}
683683
.blue-text{color:#00f}",
684684
]
685685
`)

turbopack/crates/turbo-persistence/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ print_stats = ["stats"]
1313

1414
[dependencies]
1515
anyhow = { workspace = true }
16-
either = { workspace = true}
16+
either = { workspace = true }
1717
pot = "3.0.0"
1818
byteorder = "1.5.0"
1919
jiff = "0.2.10"
@@ -24,10 +24,10 @@ qfilter = { version = "0.2.4", features = ["serde"] }
2424
quick_cache = { workspace = true }
2525
rayon = { workspace = true }
2626
rustc-hash = { workspace = true }
27-
smallvec = { workspace = true}
27+
smallvec = { workspace = true }
2828
thread_local = { workspace = true }
2929
tracing = { workspace = true }
30-
twox-hash = { version = "2.0.1", features = ["xxhash64"] }
30+
twox-hash = { workspace = true }
3131
zstd = { version = "0.13.2", features = ["zdict_builder"] }
3232

3333
[dev-dependencies]

turbopack/crates/turbo-tasks-hash/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ workspace = true
1414

1515
[dependencies]
1616
turbo-tasks-macros = { workspace = true }
17-
twox-hash = "1.6.3"
17+
twox-hash = { workspace = true }

turbopack/crates/turbo-tasks-hash/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ mod xxh3_hash64;
1111
pub use crate::{
1212
deterministic_hash::{DeterministicHash, DeterministicHasher},
1313
hex::encode_hex,
14-
xxh3_hash64::{Xxh3Hash64Hasher, hash_xxh3_hash64, hash_xxh3_hash128},
14+
xxh3_hash64::{Xxh3Hash64Hasher, hash_xxh3_hash64},
1515
};

turbopack/crates/turbo-tasks-hash/src/xxh3_hash64.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::hash::Hasher;
22

3-
use twox_hash::xxh3::{self, HasherExt};
3+
use twox_hash::XxHash3_64;
44

55
use crate::{DeterministicHash, DeterministicHasher};
66

@@ -11,35 +11,13 @@ pub fn hash_xxh3_hash64<T: DeterministicHash>(input: T) -> u64 {
1111
hasher.finish()
1212
}
1313

14-
/// Hash some content with the Xxh3Hash128 non-cryptographic hash function. This longer hash is
15-
/// useful for avoiding collisions.
16-
pub fn hash_xxh3_hash128<T: DeterministicHash>(input: T) -> u128 {
17-
// this isn't fully compatible with the 64-bit Hasher/DeterministicHasher APIs, so just use a
18-
// private impl for this
19-
struct Xxh3Hash128Hasher(xxh3::Hash128);
20-
21-
impl DeterministicHasher for Xxh3Hash128Hasher {
22-
fn finish(&self) -> u64 {
23-
unimplemented!("call self.0.finish_ext() instead!")
24-
}
25-
26-
fn write_bytes(&mut self, bytes: &[u8]) {
27-
self.0.write(bytes);
28-
}
29-
}
30-
31-
let mut hasher = Xxh3Hash128Hasher(xxh3::Hash128::with_seed(0));
32-
input.deterministic_hash(&mut hasher);
33-
hasher.0.finish_ext()
34-
}
35-
3614
/// Xxh3Hash64 hasher.
37-
pub struct Xxh3Hash64Hasher(xxh3::Hash64);
15+
pub struct Xxh3Hash64Hasher(XxHash3_64);
3816

3917
impl Xxh3Hash64Hasher {
4018
/// Create a new hasher.
4119
pub fn new() -> Self {
42-
Self(xxh3::Hash64::with_seed(0))
20+
Self(XxHash3_64::with_seed(0))
4321
}
4422

4523
/// Uses the DeterministicHash trait to hash the input in a

0 commit comments

Comments
 (0)