mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Simplify one MetaBlob impl.
It's currently an impl for `(CrateMetadataRef, TyCtxt)`, but (a) the `TyCtxt` is not used, and (b) the `CrateMetadataRef` can be simplified to a `CrateMetadata` because `CStore` access isn't required. This require changing `blob` to take `&self`, which is no big deal, and it simplifies many `get` calls.
This commit is contained in:
@@ -256,7 +256,7 @@ fn deref(&self) -> &Self::Target {
|
||||
}
|
||||
|
||||
pub(super) trait MetaBlob<'a>: Copy {
|
||||
fn blob(self) -> &'a MetadataBlob;
|
||||
fn blob(&self) -> &'a MetadataBlob;
|
||||
}
|
||||
|
||||
pub(super) trait MetaDecoder: Copy {
|
||||
@@ -266,7 +266,7 @@ pub(super) trait MetaDecoder: Copy {
|
||||
}
|
||||
|
||||
impl<'a> MetaBlob<'a> for &'a MetadataBlob {
|
||||
fn blob(self) -> &'a MetadataBlob {
|
||||
fn blob(&self) -> &'a MetadataBlob {
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -290,9 +290,9 @@ fn decoder(self, pos: usize) -> Self::Context {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> MetaBlob<'a> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
|
||||
fn blob(self) -> &'a MetadataBlob {
|
||||
&self.0.cdata.blob
|
||||
impl<'a> MetaBlob<'a> for &'a CrateMetadata {
|
||||
fn blob(&self) -> &'a MetadataBlob {
|
||||
&self.blob
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ impl<'a, 'tcx> MetaDecoder for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
|
||||
|
||||
fn decoder(self, pos: usize) -> MetadataDecodeContext<'a, 'tcx> {
|
||||
MetadataDecodeContext {
|
||||
blob_decoder: self.blob().decoder(pos),
|
||||
blob_decoder: self.0.cdata.blob().decoder(pos),
|
||||
cdata: self.0,
|
||||
tcx: self.1,
|
||||
alloc_decoding_session: self.0.cdata.alloc_decoding_state.new_decoding_session(),
|
||||
@@ -472,7 +472,7 @@ fn decode_syntax_context(&mut self) -> SyntaxContext {
|
||||
cdata
|
||||
.root
|
||||
.syntax_contexts
|
||||
.get((cdata, tcx), id)
|
||||
.get(cdata.cdata, id)
|
||||
.unwrap_or_else(|| panic!("Missing SyntaxContext {id:?} for crate {cname:?}"))
|
||||
.decode((cdata, tcx))
|
||||
})
|
||||
@@ -498,13 +498,13 @@ fn decode_expn_id(&mut self) -> ExpnId {
|
||||
let expn_data = crate_data
|
||||
.root
|
||||
.expn_data
|
||||
.get((crate_data, tcx), index)
|
||||
.get(crate_data.cdata, index)
|
||||
.unwrap()
|
||||
.decode((crate_data, tcx));
|
||||
let expn_hash = crate_data
|
||||
.root
|
||||
.expn_hashes
|
||||
.get((crate_data, tcx), index)
|
||||
.get(crate_data.cdata, index)
|
||||
.unwrap()
|
||||
.decode((crate_data, tcx));
|
||||
(expn_data, expn_hash)
|
||||
@@ -1021,7 +1021,7 @@ fn opt_item_ident(self, tcx: TyCtxt<'_>, item_index: DefIndex) -> Option<Ident>
|
||||
.root
|
||||
.tables
|
||||
.def_ident_span
|
||||
.get((self, tcx), item_index)
|
||||
.get(self.cdata, item_index)
|
||||
.unwrap_or_else(|| self.missing("def_ident_span", item_index))
|
||||
.decode((self, tcx));
|
||||
Some(Ident::new(name, span))
|
||||
@@ -1036,11 +1036,11 @@ pub(super) fn map_encoded_cnum_to_current(self, cnum: CrateNum) -> CrateNum {
|
||||
if cnum == LOCAL_CRATE { self.cnum } else { self.cnum_map[cnum] }
|
||||
}
|
||||
|
||||
fn def_kind(self, tcx: TyCtxt<'_>, item_id: DefIndex) -> DefKind {
|
||||
fn def_kind(self, _tcx: TyCtxt<'_>, item_id: DefIndex) -> DefKind {
|
||||
self.root
|
||||
.tables
|
||||
.def_kind
|
||||
.get((self, tcx), item_id)
|
||||
.get(self.cdata, item_id)
|
||||
.unwrap_or_else(|| self.missing("def_kind", item_id))
|
||||
}
|
||||
|
||||
@@ -1048,7 +1048,7 @@ fn get_span(self, tcx: TyCtxt<'_>, index: DefIndex) -> Span {
|
||||
self.root
|
||||
.tables
|
||||
.def_span
|
||||
.get((self, tcx), index)
|
||||
.get(self.cdata, index)
|
||||
.unwrap_or_else(|| self.missing("def_span", index))
|
||||
.decode((self, tcx))
|
||||
}
|
||||
@@ -1101,7 +1101,7 @@ fn get_variant(
|
||||
};
|
||||
|
||||
let data =
|
||||
self.root.tables.variant_data.get((self, tcx), index).unwrap().decode((self, tcx));
|
||||
self.root.tables.variant_data.get(self.cdata, index).unwrap().decode((self, tcx));
|
||||
|
||||
let variant_did =
|
||||
if adt_kind == ty::AdtKind::Enum { Some(self.local_def_id(index)) } else { None };
|
||||
@@ -1141,13 +1141,13 @@ fn get_adt_def<'tcx>(self, tcx: TyCtxt<'tcx>, item_id: DefIndex) -> ty::AdtDef<'
|
||||
_ => bug!("get_adt_def called on a non-ADT {:?}", did),
|
||||
};
|
||||
let repr =
|
||||
self.root.tables.repr_options.get((self, tcx), item_id).unwrap().decode((self, tcx));
|
||||
self.root.tables.repr_options.get(self.cdata, item_id).unwrap().decode((self, tcx));
|
||||
|
||||
let mut variants: Vec<_> = if let ty::AdtKind::Enum = adt_kind {
|
||||
self.root
|
||||
.tables
|
||||
.module_children_non_reexports
|
||||
.get((self, tcx), item_id)
|
||||
.get(self.cdata, item_id)
|
||||
.expect("variants are not encoded for an enum")
|
||||
.decode((self, tcx))
|
||||
.filter_map(|index| {
|
||||
@@ -1176,25 +1176,25 @@ fn get_visibility(self, tcx: TyCtxt<'_>, id: DefIndex) -> Visibility<DefId> {
|
||||
self.root
|
||||
.tables
|
||||
.visibility
|
||||
.get((self, tcx), id)
|
||||
.get(self.cdata, id)
|
||||
.unwrap_or_else(|| self.missing("visibility", id))
|
||||
.decode((self, tcx))
|
||||
.map_id(|index| self.local_def_id(index))
|
||||
}
|
||||
|
||||
fn get_safety(self, tcx: TyCtxt<'_>, id: DefIndex) -> Safety {
|
||||
self.root.tables.safety.get((self, tcx), id)
|
||||
fn get_safety(self, _tcx: TyCtxt<'_>, id: DefIndex) -> Safety {
|
||||
self.root.tables.safety.get(self.cdata, id)
|
||||
}
|
||||
|
||||
fn get_default_field(self, tcx: TyCtxt<'_>, id: DefIndex) -> Option<DefId> {
|
||||
self.root.tables.default_fields.get((self, tcx), id).map(|d| d.decode((self, tcx)))
|
||||
self.root.tables.default_fields.get(self.cdata, id).map(|d| d.decode((self, tcx)))
|
||||
}
|
||||
|
||||
fn get_expn_that_defined(self, tcx: TyCtxt<'_>, id: DefIndex) -> ExpnId {
|
||||
self.root
|
||||
.tables
|
||||
.expn_that_defined
|
||||
.get((self, tcx), id)
|
||||
.get(self.cdata, id)
|
||||
.unwrap_or_else(|| self.missing("expn_that_defined", id))
|
||||
.decode((self, tcx))
|
||||
}
|
||||
@@ -1286,12 +1286,12 @@ fn get_module_children(self, tcx: TyCtxt<'_>, id: DefIndex) -> impl Iterator<Ite
|
||||
} else {
|
||||
// Iterate over all children.
|
||||
let non_reexports =
|
||||
self.root.tables.module_children_non_reexports.get((self, tcx), id);
|
||||
self.root.tables.module_children_non_reexports.get(self.cdata, id);
|
||||
for child_index in non_reexports.unwrap().decode((self, tcx)) {
|
||||
yield self.get_mod_child(tcx, child_index);
|
||||
}
|
||||
|
||||
let reexports = self.root.tables.module_children_reexports.get((self, tcx), id);
|
||||
let reexports = self.root.tables.module_children_reexports.get(self.cdata, id);
|
||||
if !reexports.is_default() {
|
||||
for reexport in reexports.decode((self, tcx)) {
|
||||
yield reexport;
|
||||
@@ -1307,7 +1307,7 @@ fn get_ambig_module_children(
|
||||
id: DefIndex,
|
||||
) -> impl Iterator<Item = AmbigModChild> {
|
||||
gen move {
|
||||
let children = self.root.tables.ambig_module_children.get((self, tcx), id);
|
||||
let children = self.root.tables.ambig_module_children.get(self.cdata, id);
|
||||
if !children.is_default() {
|
||||
for child in children.decode((self, tcx)) {
|
||||
yield child;
|
||||
@@ -1316,15 +1316,15 @@ fn get_ambig_module_children(
|
||||
}
|
||||
}
|
||||
|
||||
fn is_item_mir_available(self, tcx: TyCtxt<'_>, id: DefIndex) -> bool {
|
||||
self.root.tables.optimized_mir.get((self, tcx), id).is_some()
|
||||
fn is_item_mir_available(self, _tcx: TyCtxt<'_>, id: DefIndex) -> bool {
|
||||
self.root.tables.optimized_mir.get(self.cdata, id).is_some()
|
||||
}
|
||||
|
||||
fn get_fn_has_self_parameter(self, tcx: TyCtxt<'_>, id: DefIndex) -> bool {
|
||||
self.root
|
||||
.tables
|
||||
.fn_arg_idents
|
||||
.get((self, tcx), id)
|
||||
.get(self.cdata, id)
|
||||
.expect("argument names not encoded for a function")
|
||||
.decode((self, tcx))
|
||||
.nth(0)
|
||||
@@ -1339,7 +1339,7 @@ fn get_associated_item_or_field_def_ids(
|
||||
self.root
|
||||
.tables
|
||||
.associated_item_or_field_def_ids
|
||||
.get((self, tcx), id)
|
||||
.get(self.cdata, id)
|
||||
.unwrap_or_else(|| self.missing("associated_item_or_field_def_ids", id))
|
||||
.decode((self, tcx))
|
||||
.map(move |child_index| self.local_def_id(child_index))
|
||||
@@ -1356,7 +1356,7 @@ fn get_associated_item(self, tcx: TyCtxt<'_>, id: DefIndex) -> ty::AssocItem {
|
||||
},
|
||||
DefKind::AssocTy => {
|
||||
let data = if let Some(rpitit_info) =
|
||||
self.root.tables.opt_rpitit_info.get((self, tcx), id)
|
||||
self.root.tables.opt_rpitit_info.get(self.cdata, id)
|
||||
{
|
||||
ty::AssocTypeData::Rpitit(rpitit_info.decode((self, tcx)))
|
||||
} else {
|
||||
@@ -1367,7 +1367,7 @@ fn get_associated_item(self, tcx: TyCtxt<'_>, id: DefIndex) -> ty::AssocItem {
|
||||
_ => bug!("cannot get associated-item of `{:?}`", self.def_key(id)),
|
||||
};
|
||||
let container =
|
||||
self.root.tables.assoc_container.get((self, tcx), id).unwrap().decode((self, tcx));
|
||||
self.root.tables.assoc_container.get(self.cdata, id).unwrap().decode((self, tcx));
|
||||
|
||||
ty::AssocItem { kind, def_id: self.local_def_id(id), container }
|
||||
}
|
||||
@@ -1379,7 +1379,7 @@ fn get_ctor(self, tcx: TyCtxt<'_>, node_id: DefIndex) -> Option<(CtorKind, DefId
|
||||
.root
|
||||
.tables
|
||||
.variant_data
|
||||
.get((self, tcx), node_id)
|
||||
.get(self.cdata, node_id)
|
||||
.unwrap()
|
||||
.decode((self, tcx));
|
||||
vdata.ctor.map(|(kind, index)| (kind, self.local_def_id(index)))
|
||||
@@ -1392,7 +1392,7 @@ fn get_item_attrs(self, tcx: TyCtxt<'_>, id: DefIndex) -> impl Iterator<Item = h
|
||||
self.root
|
||||
.tables
|
||||
.attributes
|
||||
.get((self, tcx), id)
|
||||
.get(self.cdata, id)
|
||||
.unwrap_or_else(|| {
|
||||
// Structure and variant constructors don't have any attributes encoded for them,
|
||||
// but we assume that someone passing a constructor ID actually wants to look at
|
||||
@@ -1403,7 +1403,7 @@ fn get_item_attrs(self, tcx: TyCtxt<'_>, id: DefIndex) -> impl Iterator<Item = h
|
||||
self.root
|
||||
.tables
|
||||
.attributes
|
||||
.get((self, tcx), parent_id)
|
||||
.get(self.cdata, parent_id)
|
||||
.expect("no encoded attributes for a structure or variant")
|
||||
})
|
||||
.decode((self, tcx))
|
||||
@@ -1418,7 +1418,7 @@ fn get_inherent_implementations_for_type<'tcx>(
|
||||
self.root
|
||||
.tables
|
||||
.inherent_impls
|
||||
.get((self, tcx), id)
|
||||
.get(self.cdata, id)
|
||||
.decode((self, tcx))
|
||||
.map(|index| self.local_def_id(index)),
|
||||
)
|
||||
@@ -1479,7 +1479,7 @@ fn get_proc_macro_quoted_span(self, tcx: TyCtxt<'_>, index: usize) -> Span {
|
||||
self.root
|
||||
.tables
|
||||
.proc_macro_quoted_spans
|
||||
.get((self, tcx), index)
|
||||
.get(self.cdata, index)
|
||||
.unwrap_or_else(|| panic!("Missing proc macro quoted span: {index:?}"))
|
||||
.decode((self, tcx))
|
||||
}
|
||||
@@ -1544,12 +1544,12 @@ fn exported_generic_symbols<'tcx>(
|
||||
fn get_macro(self, tcx: TyCtxt<'_>, id: DefIndex) -> ast::MacroDef {
|
||||
match self.def_kind(tcx, id) {
|
||||
DefKind::Macro(_) => {
|
||||
let macro_rules = self.root.tables.is_macro_rules.get((self, tcx), id);
|
||||
let macro_rules = self.root.tables.is_macro_rules.get(self.cdata, id);
|
||||
let body = self
|
||||
.root
|
||||
.tables
|
||||
.macro_definition
|
||||
.get((self, tcx), id)
|
||||
.get(self.cdata, id)
|
||||
.unwrap()
|
||||
.decode((self, tcx));
|
||||
ast::MacroDef { macro_rules, body: Box::new(body), eii_declaration: None }
|
||||
@@ -1590,11 +1590,8 @@ fn def_path_hash_to_def_index(self, hash: DefPathHash) -> Option<DefIndex> {
|
||||
|
||||
fn expn_hash_to_expn_id(self, tcx: TyCtxt<'_>, index_guess: u32, hash: ExpnHash) -> ExpnId {
|
||||
let index_guess = ExpnIndex::from_u32(index_guess);
|
||||
let old_hash = self
|
||||
.root
|
||||
.expn_hashes
|
||||
.get((self, tcx), index_guess)
|
||||
.map(|lazy| lazy.decode((self, tcx)));
|
||||
let old_hash =
|
||||
self.root.expn_hashes.get(self.cdata, index_guess).map(|lazy| lazy.decode((self, tcx)));
|
||||
|
||||
let index = if old_hash == Some(hash) {
|
||||
// Fast path: the expn and its index is unchanged from the
|
||||
@@ -1611,7 +1608,7 @@ fn expn_hash_to_expn_id(self, tcx: TyCtxt<'_>, index_guess: u32, hash: ExpnHash)
|
||||
UnhashMap::with_capacity_and_hasher(end_id as usize, Default::default());
|
||||
for i in 0..end_id {
|
||||
let i = ExpnIndex::from_u32(i);
|
||||
if let Some(hash) = self.root.expn_hashes.get((self, tcx), i) {
|
||||
if let Some(hash) = self.root.expn_hashes.get(self.cdata, i) {
|
||||
map.insert(hash.decode((self, tcx)), i);
|
||||
}
|
||||
}
|
||||
@@ -1620,7 +1617,7 @@ fn expn_hash_to_expn_id(self, tcx: TyCtxt<'_>, index_guess: u32, hash: ExpnHash)
|
||||
map[&hash]
|
||||
};
|
||||
|
||||
let data = self.root.expn_data.get((self, tcx), index).unwrap().decode((self, tcx));
|
||||
let data = self.root.expn_data.get(self.cdata, index).unwrap().decode((self, tcx));
|
||||
rustc_span::hygiene::register_expn_id(self.cnum, index, data, hash)
|
||||
}
|
||||
|
||||
@@ -1757,7 +1754,7 @@ fn filter<'a>(
|
||||
let source_file_to_import = self
|
||||
.root
|
||||
.source_map
|
||||
.get((self, tcx), source_file_index)
|
||||
.get(self.cdata, source_file_index)
|
||||
.expect("missing source file")
|
||||
.decode((self, tcx));
|
||||
|
||||
@@ -1858,19 +1855,19 @@ fn filter<'a>(
|
||||
.clone()
|
||||
}
|
||||
|
||||
fn get_attr_flags(self, tcx: TyCtxt<'_>, index: DefIndex) -> AttrFlags {
|
||||
self.root.tables.attr_flags.get((self, tcx), index)
|
||||
fn get_attr_flags(self, _tcx: TyCtxt<'_>, index: DefIndex) -> AttrFlags {
|
||||
self.root.tables.attr_flags.get(self.cdata, index)
|
||||
}
|
||||
|
||||
fn get_intrinsic(self, tcx: TyCtxt<'_>, index: DefIndex) -> Option<ty::IntrinsicDef> {
|
||||
self.root.tables.intrinsic.get((self, tcx), index).map(|d| d.decode((self, tcx)))
|
||||
self.root.tables.intrinsic.get(self.cdata, index).map(|d| d.decode((self, tcx)))
|
||||
}
|
||||
|
||||
fn get_doc_link_resolutions(self, tcx: TyCtxt<'_>, index: DefIndex) -> DocLinkResMap {
|
||||
self.root
|
||||
.tables
|
||||
.doc_link_resolutions
|
||||
.get((self, tcx), index)
|
||||
.get(self.cdata, index)
|
||||
.expect("no resolutions for a doc link")
|
||||
.decode((self, tcx))
|
||||
}
|
||||
@@ -1883,7 +1880,7 @@ fn get_doc_link_traits_in_scope(
|
||||
self.root
|
||||
.tables
|
||||
.doc_link_traits_in_scope
|
||||
.get((self, tcx), index)
|
||||
.get(self.cdata, index)
|
||||
.expect("no traits in scope for a doc link")
|
||||
.decode((self, tcx))
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ macro_rules! provide_one {
|
||||
.root
|
||||
.tables
|
||||
.$name
|
||||
.get(($cdata, $tcx), $def_id.index)
|
||||
.get($cdata.cdata, $def_id.index)
|
||||
.map(|lazy| lazy.decode(($cdata, $tcx)))
|
||||
.process_decoded($tcx, || panic!("{:?} does not have a {:?}", $def_id, stringify!($name)))
|
||||
}
|
||||
@@ -109,7 +109,7 @@ macro_rules! provide_one {
|
||||
($tcx:ident, $def_id:ident, $other:ident, $cdata:ident, $name:ident => { table_defaulted_array }) => {
|
||||
provide_one! {
|
||||
$tcx, $def_id, $other, $cdata, $name => {
|
||||
let lazy = $cdata.root.tables.$name.get(($cdata, $tcx), $def_id.index);
|
||||
let lazy = $cdata.root.tables.$name.get($cdata.cdata, $def_id.index);
|
||||
let value = if lazy.is_default() {
|
||||
&[] as &[_]
|
||||
} else {
|
||||
@@ -127,7 +127,7 @@ macro_rules! provide_one {
|
||||
.root
|
||||
.tables
|
||||
.$name
|
||||
.get(($cdata, $tcx), $def_id.index)
|
||||
.get($cdata.cdata, $def_id.index)
|
||||
.process_decoded($tcx, || panic!("{:?} does not have a {:?}", $def_id, stringify!($name)))
|
||||
}
|
||||
}
|
||||
@@ -264,7 +264,7 @@ fn into_args(self) -> (DefId, SimplifiedType) {
|
||||
.root
|
||||
.tables
|
||||
.coerce_unsized_info
|
||||
.get((cdata, tcx), def_id.index)
|
||||
.get(cdata.cdata, def_id.index)
|
||||
.map(|lazy| lazy.decode((cdata, tcx)))
|
||||
.process_decoded(tcx, || panic!("{def_id:?} does not have coerce_unsized_info"))) }
|
||||
mir_const_qualif => { table }
|
||||
@@ -280,7 +280,7 @@ fn into_args(self) -> (DefId, SimplifiedType) {
|
||||
.root
|
||||
.tables
|
||||
.eval_static_initializer
|
||||
.get((cdata, tcx), def_id.index)
|
||||
.get(cdata.cdata, def_id.index)
|
||||
.map(|lazy| lazy.decode((cdata, tcx)))
|
||||
.unwrap_or_else(|| panic!("{def_id:?} does not have eval_static_initializer")))
|
||||
}
|
||||
@@ -293,7 +293,7 @@ fn into_args(self) -> (DefId, SimplifiedType) {
|
||||
.root
|
||||
.tables
|
||||
.deduced_param_attrs
|
||||
.get((cdata, tcx), def_id.index)
|
||||
.get(cdata.cdata, def_id.index)
|
||||
.map(|lazy| {
|
||||
&*tcx.arena.alloc_from_iter(lazy.decode((cdata, tcx)))
|
||||
})
|
||||
@@ -306,7 +306,7 @@ fn into_args(self) -> (DefId, SimplifiedType) {
|
||||
.root
|
||||
.tables
|
||||
.trait_impl_trait_tys
|
||||
.get((cdata, tcx), def_id.index)
|
||||
.get(cdata.cdata, def_id.index)
|
||||
.map(|lazy| lazy.decode((cdata, tcx)))
|
||||
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user