This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit 668a34e
committed
Auto merge of rust-lang#73851 - matthewjasper:serialize-not-special, r=oli-obk
Remove most specialization use in serialization
Switching from specialization to min_specialization in the compiler made the unsoundness of how we used these traits pretty clear. This changes how the `Encodable` and `Decodable` traits work to be more friendly for types need a `TyCtxt` to deserialize.
The alternative design of having both `Encodable` and `TyEncodable` traits was considered, but doesn't really work because the following impls would conflict:
```
impl<E: Ecodable> TyEncodable for Encodable
impl<E: TyEcodable> TyEncodable for [E]
```
## How-to guide
- `Rustc(De|En)codable` is now spelled `Ty(De|En)coable` in `rustc_middle`, `Metadata(En|De)codable` in `rustc_metadata` where needed, and `(De|En)codable` everywhere else.
- Manual implementations of `(De|En)codable` shouldn't be much different.
- If you're adding a new interned type that needs to be en/decodable then the simplest thing way to handle this is:
- Have the type be a wrapper around a reference to the interned data (i.e. do what `ty::Predicate` does, and not what all of the other interned types do)
- Derive `Ty(En|De)codable` on the inner type
- Implement `Encodable<impl TyEncoder>` by forwarding to the inner type.
- Implement `Decodable<impl TyDecoder>` by decoding the inner type and then creating the wrapper around that (using the `tcx` from the decoder as needed).
cc @rust-lang/compiler for opinions on this change
r? @oli-obkFile tree
137 files changed
+2149
-2343
lines changed- src
- librustc_arena
- librustc_ast
- ast
- librustc_attr
- librustc_codegen_ssa
- back
- librustc_data_structures
- librustc_errors
- json
- librustc_expand
- librustc_hir
- librustc_incremental
- persist
- librustc_index
- librustc_infer/infer
- librustc_macros/src
- librustc_metadata
- rmeta
- librustc_middle
- dep_graph
- hir
- infer
- middle
- mir
- interpret
- terminator
- traits
- ty
- consts
- query
- librustc_query_system
- dep_graph
- librustc_serialize
- tests
- librustc_session
- librustc_span
- librustc_target
- abi
- asm
- spec
- test
- run-make-fulldeps/save-analysis
- ui-fulldeps
- ui/ast-json
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
137 files changed
+2149
-2343
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3334 | 3334 | | |
3335 | 3335 | | |
3336 | 3336 | | |
| 3337 | + | |
3337 | 3338 | | |
3338 | 3339 | | |
3339 | 3340 | | |
| |||
3364 | 3365 | | |
3365 | 3366 | | |
3366 | 3367 | | |
| 3368 | + | |
3367 | 3369 | | |
3368 | 3370 | | |
3369 | 3371 | | |
| |||
3416 | 3418 | | |
3417 | 3419 | | |
3418 | 3420 | | |
| 3421 | + | |
3419 | 3422 | | |
3420 | 3423 | | |
3421 | 3424 | | |
| |||
3437 | 3440 | | |
3438 | 3441 | | |
3439 | 3442 | | |
| 3443 | + | |
3440 | 3444 | | |
3441 | 3445 | | |
3442 | 3446 | | |
| |||
3499 | 3503 | | |
3500 | 3504 | | |
3501 | 3505 | | |
| 3506 | + | |
3502 | 3507 | | |
3503 | 3508 | | |
3504 | 3509 | | |
| |||
3511 | 3516 | | |
3512 | 3517 | | |
3513 | 3518 | | |
| 3519 | + | |
3514 | 3520 | | |
3515 | 3521 | | |
3516 | 3522 | | |
| |||
3640 | 3646 | | |
3641 | 3647 | | |
3642 | 3648 | | |
| 3649 | + | |
3643 | 3650 | | |
3644 | 3651 | | |
3645 | 3652 | | |
| |||
3815 | 3822 | | |
3816 | 3823 | | |
3817 | 3824 | | |
| 3825 | + | |
3818 | 3826 | | |
3819 | 3827 | | |
3820 | 3828 | | |
| |||
3869 | 3877 | | |
3870 | 3878 | | |
3871 | 3879 | | |
| 3880 | + | |
3872 | 3881 | | |
3873 | 3882 | | |
3874 | 3883 | | |
| |||
3884 | 3893 | | |
3885 | 3894 | | |
3886 | 3895 | | |
| 3896 | + | |
3887 | 3897 | | |
3888 | 3898 | | |
3889 | 3899 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
611 | 611 | | |
612 | 612 | | |
613 | 613 | | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
| 614 | + | |
619 | 615 | | |
620 | 616 | | |
621 | 617 | | |
| |||
0 commit comments