Skip to content

Commit 9510beb

Browse files
authored
Rollup merge of #129723 - compiler-errors:extern-providers, r=lcnr
Simplify some extern providers Simplifies some extern crate providers: 1. Generalize the `ProcessQueryValue` identity impl to work on non-`Option` types. 2. Allow `ProcessQueryValue` to wrap its output in an `EarlyBinder`, to simplify `explicit_item_bounds`/`explicit_item_super_predicates`. 3. Use `{ table }` and friends more when possible.
2 parents 10fb626 + 8c798c8 commit 9510beb

File tree

2 files changed

+21
-43
lines changed

2 files changed

+21
-43
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

-32
Original file line numberDiff line numberDiff line change
@@ -1070,34 +1070,6 @@ impl<'a> CrateMetadataRef<'a> {
10701070
)
10711071
}
10721072

1073-
fn get_explicit_item_bounds<'tcx>(
1074-
self,
1075-
index: DefIndex,
1076-
tcx: TyCtxt<'tcx>,
1077-
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
1078-
let lazy = self.root.tables.explicit_item_bounds.get(self, index);
1079-
let output = if lazy.is_default() {
1080-
&mut []
1081-
} else {
1082-
tcx.arena.alloc_from_iter(lazy.decode((self, tcx)))
1083-
};
1084-
ty::EarlyBinder::bind(&*output)
1085-
}
1086-
1087-
fn get_explicit_item_super_predicates<'tcx>(
1088-
self,
1089-
index: DefIndex,
1090-
tcx: TyCtxt<'tcx>,
1091-
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
1092-
let lazy = self.root.tables.explicit_item_super_predicates.get(self, index);
1093-
let output = if lazy.is_default() {
1094-
&mut []
1095-
} else {
1096-
tcx.arena.alloc_from_iter(lazy.decode((self, tcx)))
1097-
};
1098-
ty::EarlyBinder::bind(&*output)
1099-
}
1100-
11011073
fn get_variant(
11021074
self,
11031075
kind: DefKind,
@@ -1323,10 +1295,6 @@ impl<'a> CrateMetadataRef<'a> {
13231295
self.root.tables.optimized_mir.get(self, id).is_some()
13241296
}
13251297

1326-
fn cross_crate_inlinable(self, id: DefIndex) -> bool {
1327-
self.root.tables.cross_crate_inlinable.get(self, id)
1328-
}
1329-
13301298
fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
13311299
self.root
13321300
.tables

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ trait ProcessQueryValue<'tcx, T> {
3232
fn process_decoded(self, _tcx: TyCtxt<'tcx>, _err: impl Fn() -> !) -> T;
3333
}
3434

35-
impl<T> ProcessQueryValue<'_, Option<T>> for Option<T> {
35+
impl<T> ProcessQueryValue<'_, T> for T {
3636
#[inline(always)]
37-
fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Option<T> {
37+
fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> T {
3838
self
3939
}
4040
}
4141

42+
impl<'tcx, T> ProcessQueryValue<'tcx, ty::EarlyBinder<'tcx, T>> for T {
43+
#[inline(always)]
44+
fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> ty::EarlyBinder<'tcx, T> {
45+
ty::EarlyBinder::bind(self)
46+
}
47+
}
48+
4249
impl<T> ProcessQueryValue<'_, T> for Option<T> {
4350
#[inline(always)]
4451
fn process_decoded(self, _tcx: TyCtxt<'_>, err: impl Fn() -> !) -> T {
@@ -103,7 +110,12 @@ macro_rules! provide_one {
103110
provide_one! {
104111
$tcx, $def_id, $other, $cdata, $name => {
105112
let lazy = $cdata.root.tables.$name.get($cdata, $def_id.index);
106-
if lazy.is_default() { &[] } else { $tcx.arena.alloc_from_iter(lazy.decode(($cdata, $tcx))) }
113+
let value = if lazy.is_default() {
114+
&[] as &[_]
115+
} else {
116+
$tcx.arena.alloc_from_iter(lazy.decode(($cdata, $tcx)))
117+
};
118+
value.process_decoded($tcx, || panic!("{:?} does not have a {:?}", $def_id, stringify!($name)))
107119
}
108120
}
109121
};
@@ -212,15 +224,15 @@ impl IntoArgs for (CrateNum, SimplifiedType) {
212224
}
213225

214226
provide! { tcx, def_id, other, cdata,
215-
explicit_item_bounds => { cdata.get_explicit_item_bounds(def_id.index, tcx) }
216-
explicit_item_super_predicates => { cdata.get_explicit_item_super_predicates(def_id.index, tcx) }
227+
explicit_item_bounds => { table_defaulted_array }
228+
explicit_item_super_predicates => { table_defaulted_array }
217229
explicit_predicates_of => { table }
218230
generics_of => { table }
219231
inferred_outlives_of => { table_defaulted_array }
220232
explicit_super_predicates_of => { table }
221233
explicit_implied_predicates_of => { table }
222234
type_of => { table }
223-
type_alias_is_lazy => { cdata.root.tables.type_alias_is_lazy.get(cdata, def_id.index) }
235+
type_alias_is_lazy => { table_direct }
224236
variances_of => { table }
225237
fn_sig => { table }
226238
codegen_fn_attrs => { table }
@@ -241,7 +253,7 @@ provide! { tcx, def_id, other, cdata,
241253
lookup_default_body_stability => { table }
242254
lookup_deprecation_entry => { table }
243255
params_in_repr => { table }
244-
unused_generic_params => { cdata.root.tables.unused_generic_params.get(cdata, def_id.index) }
256+
unused_generic_params => { table_direct }
245257
def_kind => { cdata.def_kind(def_id.index) }
246258
impl_parent => { table }
247259
defaultness => { table_direct }
@@ -287,9 +299,7 @@ provide! { tcx, def_id, other, cdata,
287299
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
288300
}
289301

290-
associated_type_for_effects => {
291-
table
292-
}
302+
associated_type_for_effects => { table }
293303
associated_types_for_impl_traits_in_associated_fn => { table_defaulted_array }
294304

295305
visibility => { cdata.get_visibility(def_id.index) }
@@ -310,7 +320,7 @@ provide! { tcx, def_id, other, cdata,
310320
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
311321
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
312322
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
313-
cross_crate_inlinable => { cdata.cross_crate_inlinable(def_id.index) }
323+
cross_crate_inlinable => { table_direct }
314324

315325
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
316326
is_private_dep => { cdata.private_dep }

0 commit comments

Comments
 (0)