Skip to content

Commit

Permalink
Auto merge of #73851 - matthewjasper:serialize-not-special, r=oli-obk
Browse files Browse the repository at this point in the history
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-obk
  • Loading branch information
bors committed Aug 15, 2020
2 parents 95879ad + c4f91bb commit 668a34e
Show file tree
Hide file tree
Showing 137 changed files with 2,149 additions and 2,343 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,7 @@ dependencies = [
"rustc_hir",
"rustc_incremental",
"rustc_index",
"rustc_macros",
"rustc_middle",
"rustc_serialize",
"rustc_session",
Expand Down Expand Up @@ -3364,6 +3365,7 @@ dependencies = [
"rustc-rayon-core",
"rustc_graphviz",
"rustc_index",
"rustc_macros",
"rustc_serialize",
"smallvec 1.4.0",
"stable_deref_trait",
Expand Down Expand Up @@ -3416,6 +3418,7 @@ dependencies = [
"annotate-snippets 0.8.0",
"atty",
"rustc_data_structures",
"rustc_macros",
"rustc_serialize",
"rustc_span",
"termcolor",
Expand All @@ -3437,6 +3440,7 @@ dependencies = [
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"rustc_macros",
"rustc_parse",
"rustc_serialize",
"rustc_session",
Expand Down Expand Up @@ -3499,6 +3503,7 @@ dependencies = [
"rustc_fs_util",
"rustc_graphviz",
"rustc_hir",
"rustc_macros",
"rustc_middle",
"rustc_serialize",
"rustc_session",
Expand All @@ -3511,6 +3516,7 @@ name = "rustc_index"
version = "0.0.0"
dependencies = [
"arrayvec 0.5.1",
"rustc_macros",
"rustc_serialize",
]

Expand Down Expand Up @@ -3640,6 +3646,7 @@ dependencies = [
"rustc_hir",
"rustc_hir_pretty",
"rustc_index",
"rustc_macros",
"rustc_middle",
"rustc_serialize",
"rustc_session",
Expand Down Expand Up @@ -3815,6 +3822,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_index",
"rustc_macros",
"rustc_serialize",
"rustc_span",
"smallvec 1.4.0",
Expand Down Expand Up @@ -3869,6 +3877,7 @@ name = "rustc_serialize"
version = "0.0.0"
dependencies = [
"indexmap",
"rustc_macros",
"smallvec 1.4.0",
]

Expand All @@ -3884,6 +3893,7 @@ dependencies = [
"rustc_errors",
"rustc_feature",
"rustc_fs_util",
"rustc_macros",
"rustc_serialize",
"rustc_span",
"rustc_target",
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_arena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,7 @@ macro_rules! which_arena_for_type {

#[macro_export]
macro_rules! declare_arena {
// This macro has to take the same input as
// `impl_arena_allocatable_decoders` which requires a second version of
// each type. We ignore that type until we can fix
// `impl_arena_allocatable_decoders`.
([], [$($a:tt $name:ident: $ty:ty, $_gen_ty:ty;)*], $tcx:lifetime) => {
([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => {
#[derive(Default)]
pub struct Arena<$tcx> {
pub dropless: $crate::DroplessArena,
Expand Down
Loading

0 comments on commit 668a34e

Please sign in to comment.