Skip to content

Commit 668a34e

Browse files
committed
Auto merge of #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-obk
2 parents 95879ad + c4f91bb commit 668a34e

File tree

137 files changed

+2149
-2343
lines changed

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

Cargo.lock

+10
Original file line numberDiff line numberDiff line change
@@ -3334,6 +3334,7 @@ dependencies = [
33343334
"rustc_hir",
33353335
"rustc_incremental",
33363336
"rustc_index",
3337+
"rustc_macros",
33373338
"rustc_middle",
33383339
"rustc_serialize",
33393340
"rustc_session",
@@ -3364,6 +3365,7 @@ dependencies = [
33643365
"rustc-rayon-core",
33653366
"rustc_graphviz",
33663367
"rustc_index",
3368+
"rustc_macros",
33673369
"rustc_serialize",
33683370
"smallvec 1.4.0",
33693371
"stable_deref_trait",
@@ -3416,6 +3418,7 @@ dependencies = [
34163418
"annotate-snippets 0.8.0",
34173419
"atty",
34183420
"rustc_data_structures",
3421+
"rustc_macros",
34193422
"rustc_serialize",
34203423
"rustc_span",
34213424
"termcolor",
@@ -3437,6 +3440,7 @@ dependencies = [
34373440
"rustc_errors",
34383441
"rustc_feature",
34393442
"rustc_lexer",
3443+
"rustc_macros",
34403444
"rustc_parse",
34413445
"rustc_serialize",
34423446
"rustc_session",
@@ -3499,6 +3503,7 @@ dependencies = [
34993503
"rustc_fs_util",
35003504
"rustc_graphviz",
35013505
"rustc_hir",
3506+
"rustc_macros",
35023507
"rustc_middle",
35033508
"rustc_serialize",
35043509
"rustc_session",
@@ -3511,6 +3516,7 @@ name = "rustc_index"
35113516
version = "0.0.0"
35123517
dependencies = [
35133518
"arrayvec 0.5.1",
3519+
"rustc_macros",
35143520
"rustc_serialize",
35153521
]
35163522

@@ -3640,6 +3646,7 @@ dependencies = [
36403646
"rustc_hir",
36413647
"rustc_hir_pretty",
36423648
"rustc_index",
3649+
"rustc_macros",
36433650
"rustc_middle",
36443651
"rustc_serialize",
36453652
"rustc_session",
@@ -3815,6 +3822,7 @@ dependencies = [
38153822
"rustc_data_structures",
38163823
"rustc_errors",
38173824
"rustc_index",
3825+
"rustc_macros",
38183826
"rustc_serialize",
38193827
"rustc_span",
38203828
"smallvec 1.4.0",
@@ -3869,6 +3877,7 @@ name = "rustc_serialize"
38693877
version = "0.0.0"
38703878
dependencies = [
38713879
"indexmap",
3880+
"rustc_macros",
38723881
"smallvec 1.4.0",
38733882
]
38743883

@@ -3884,6 +3893,7 @@ dependencies = [
38843893
"rustc_errors",
38853894
"rustc_feature",
38863895
"rustc_fs_util",
3896+
"rustc_macros",
38873897
"rustc_serialize",
38883898
"rustc_span",
38893899
"rustc_target",

src/librustc_arena/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,7 @@ macro_rules! which_arena_for_type {
611611

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

0 commit comments

Comments
 (0)