Skip to content

Commit

Permalink
Rollup merge of rust-lang#129723 - compiler-errors:extern-providers, …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
workingjubilee committed Aug 31, 2024
2 parents 7002788 + 8c798c8 commit 3209940
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 43 deletions.
32 changes: 0 additions & 32 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,34 +1070,6 @@ impl<'a> CrateMetadataRef<'a> {
)
}

fn get_explicit_item_bounds<'tcx>(
self,
index: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
let lazy = self.root.tables.explicit_item_bounds.get(self, index);
let output = if lazy.is_default() {
&mut []
} else {
tcx.arena.alloc_from_iter(lazy.decode((self, tcx)))
};
ty::EarlyBinder::bind(&*output)
}

fn get_explicit_item_super_predicates<'tcx>(
self,
index: DefIndex,
tcx: TyCtxt<'tcx>,
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
let lazy = self.root.tables.explicit_item_super_predicates.get(self, index);
let output = if lazy.is_default() {
&mut []
} else {
tcx.arena.alloc_from_iter(lazy.decode((self, tcx)))
};
ty::EarlyBinder::bind(&*output)
}

fn get_variant(
self,
kind: DefKind,
Expand Down Expand Up @@ -1323,10 +1295,6 @@ impl<'a> CrateMetadataRef<'a> {
self.root.tables.optimized_mir.get(self, id).is_some()
}

fn cross_crate_inlinable(self, id: DefIndex) -> bool {
self.root.tables.cross_crate_inlinable.get(self, id)
}

fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
self.root
.tables
Expand Down
32 changes: 21 additions & 11 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ trait ProcessQueryValue<'tcx, T> {
fn process_decoded(self, _tcx: TyCtxt<'tcx>, _err: impl Fn() -> !) -> T;
}

impl<T> ProcessQueryValue<'_, Option<T>> for Option<T> {
impl<T> ProcessQueryValue<'_, T> for T {
#[inline(always)]
fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Option<T> {
fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> T {
self
}
}

impl<'tcx, T> ProcessQueryValue<'tcx, ty::EarlyBinder<'tcx, T>> for T {
#[inline(always)]
fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> ty::EarlyBinder<'tcx, T> {
ty::EarlyBinder::bind(self)
}
}

impl<T> ProcessQueryValue<'_, T> for Option<T> {
#[inline(always)]
fn process_decoded(self, _tcx: TyCtxt<'_>, err: impl Fn() -> !) -> T {
Expand Down Expand Up @@ -103,7 +110,12 @@ macro_rules! provide_one {
provide_one! {
$tcx, $def_id, $other, $cdata, $name => {
let lazy = $cdata.root.tables.$name.get($cdata, $def_id.index);
if lazy.is_default() { &[] } else { $tcx.arena.alloc_from_iter(lazy.decode(($cdata, $tcx))) }
let value = if lazy.is_default() {
&[] as &[_]
} else {
$tcx.arena.alloc_from_iter(lazy.decode(($cdata, $tcx)))
};
value.process_decoded($tcx, || panic!("{:?} does not have a {:?}", $def_id, stringify!($name)))
}
}
};
Expand Down Expand Up @@ -212,15 +224,15 @@ impl IntoArgs for (CrateNum, SimplifiedType) {
}

provide! { tcx, def_id, other, cdata,
explicit_item_bounds => { cdata.get_explicit_item_bounds(def_id.index, tcx) }
explicit_item_super_predicates => { cdata.get_explicit_item_super_predicates(def_id.index, tcx) }
explicit_item_bounds => { table_defaulted_array }
explicit_item_super_predicates => { table_defaulted_array }
explicit_predicates_of => { table }
generics_of => { table }
inferred_outlives_of => { table_defaulted_array }
explicit_super_predicates_of => { table }
explicit_implied_predicates_of => { table }
type_of => { table }
type_alias_is_lazy => { cdata.root.tables.type_alias_is_lazy.get(cdata, def_id.index) }
type_alias_is_lazy => { table_direct }
variances_of => { table }
fn_sig => { table }
codegen_fn_attrs => { table }
Expand All @@ -241,7 +253,7 @@ provide! { tcx, def_id, other, cdata,
lookup_default_body_stability => { table }
lookup_deprecation_entry => { table }
params_in_repr => { table }
unused_generic_params => { cdata.root.tables.unused_generic_params.get(cdata, def_id.index) }
unused_generic_params => { table_direct }
def_kind => { cdata.def_kind(def_id.index) }
impl_parent => { table }
defaultness => { table_direct }
Expand Down Expand Up @@ -287,9 +299,7 @@ provide! { tcx, def_id, other, cdata,
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
}

associated_type_for_effects => {
table
}
associated_type_for_effects => { table }
associated_types_for_impl_traits_in_associated_fn => { table_defaulted_array }

visibility => { cdata.get_visibility(def_id.index) }
Expand All @@ -310,7 +320,7 @@ provide! { tcx, def_id, other, cdata,
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
cross_crate_inlinable => { cdata.cross_crate_inlinable(def_id.index) }
cross_crate_inlinable => { table_direct }

dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
is_private_dep => { cdata.private_dep }
Expand Down

0 comments on commit 3209940

Please sign in to comment.