Commit 7abd808
authored
Turbopack: use the same serialization method for lookup as for storing (#84765)
### What?
This makes sure to use the same method for serializing CachedTaskType for storing and lookup.
Before that we instantiated the serialization twice and that caused some weird behavior on linux.
Before this fix I was seeing that serialization of CachedTaskType was not byte to byte identical between storing and lookup. This caused tasks to not be found, which will lead to very weird effects: stale tasks, cell not found, etc.
I was expecting that pot serialization is deterministic, but turns out it isn't fully deterministic. It has some logic to deduplicate Symbols (like enum variant names). But it deduplicates these `&'static str`s based on the pointer address of the static string. Turns out that Rust doesn't guarantee that static strings are deduplicated in all cases.
I assume that we are somehow running into that problem when having two variants of the serialization. They ended up serializing task types differently (one didn't have a symbol deduplicated in the serialized form. But that's more a wild guess. It did fix the bug, but I have a hard time understanding why this is happening.
On long term, I think we should change pot to avoid using pointer addresses and do a real comparision instead.
> why does the `inline(never)` fix it?
I'm not super sure, but here is my theory. The rust compiler on linux is very aggressive in inlining the whole stuff, up to the point where it inlines the Serialize implementation of CachedTaskType and RawVc into the call side (`turbo-tasks-backend` crate). It can't inline the Serialize implementation that's behind the `arg` `MagicAny` stuff. So we are duplicating the RawVc Serialize logic into two crates. This way we end up with two `&'static str` of `TaskCell` for the enum variant. This string is not deduplicated during linking for whatever reason (It's not guaranteed). So in the end the Symbol is not deduplicated in the serialized form of the CachedTaskType.
The stuff above might happen or not. It's in the fate of the compiler. And we also don't rely on that the Symbol is deduplicated. But we rely on a deterministic serialized version. The problem is that the lookup path and the store path have two separate calls to `serialize`, so it might end up inlining into two different places. So that might end up being aggressive in one place and not so aggressive in the other place. So in the end it might end up deduplicating in the lookup path and not deduplicating in the store path, which would cause different serialized versions in the two paths.
To avoid that, I changed to code to use the `serialize_task_type` function in both places. And the `inline(never)` ensures that it won't be duplicated by inlining.
Don't ask me how long it took to figure that out...1 parent 04c7cef commit 7abd808
File tree
1 file changed
+30
-10
lines changed- turbopack/crates/turbo-tasks-backend/src
1 file changed
+30
-10
lines changedLines changed: 30 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
357 | 357 | | |
358 | 358 | | |
359 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
360 | 365 | | |
361 | | - | |
362 | 366 | | |
363 | 367 | | |
364 | 368 | | |
| |||
441 | 445 | | |
442 | 446 | | |
443 | 447 | | |
| 448 | + | |
444 | 449 | | |
445 | | - | |
446 | 450 | | |
447 | 451 | | |
448 | 452 | | |
| |||
499 | 503 | | |
500 | 504 | | |
501 | 505 | | |
502 | | - | |
503 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
504 | 510 | | |
505 | 511 | | |
506 | 512 | | |
| |||
645 | 651 | | |
646 | 652 | | |
647 | 653 | | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
648 | 662 | | |
649 | | - | |
| 663 | + | |
650 | 664 | | |
651 | | - | |
| 665 | + | |
652 | 666 | | |
653 | 667 | | |
654 | 668 | | |
655 | | - | |
656 | | - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
657 | 677 | | |
658 | 678 | | |
659 | 679 | | |
660 | 680 | | |
661 | 681 | | |
662 | 682 | | |
663 | | - | |
664 | | - | |
| 683 | + | |
| 684 | + | |
665 | 685 | | |
666 | 686 | | |
667 | 687 | | |
| |||
0 commit comments