From: Camille GILLOT Date: Fri, 18 Feb 2022 18:23:58 +0000 (+0100) Subject: Add fn_arg_names table. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=381d32e7d6ac5037be4ce23aca7c7b38404928a8;p=rust.git Add fn_arg_names table. --- diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index dc4909bbf5c..6f9cd871e91 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1395,15 +1395,6 @@ fn get_missing_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [lang_items::LangIte tcx.arena.alloc_from_iter(self.root.lang_items_missing.decode(self)) } - fn get_fn_param_names(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Ident] { - let param_names = match self.kind(id) { - EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).param_names, - EntryKind::AssocFn(data) => data.decode(self).fn_data.param_names, - _ => Lazy::empty(), - }; - LazyQueryDecodable::decode_query(Some(param_names), self, tcx, || unreachable!()) - } - fn exported_symbols( self, tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 240792a939b..d53631d49d3 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -139,6 +139,7 @@ fn into_args(self) -> (DefId, DefId) { mir_const_qualif => { table } rendered_const => { table } asyncness => { table } + fn_arg_names => { table } trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) } adt_def => { cdata.get_adt_def(def_id.index, tcx) } @@ -154,7 +155,6 @@ fn into_args(self) -> (DefId, DefId) { static_mutability => { cdata.static_mutability(def_id.index) } generator_kind => { cdata.generator_kind(def_id.index) } item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) } - fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) } trait_of_item => { cdata.get_trait_of_item(def_id.index) } is_mir_available => { cdata.is_item_mir_available(def_id.index) } is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 7142242aac7..9821a63dfaa 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1195,12 +1195,16 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) { } ty::AssocKind::Fn => { let fn_data = if let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind { - let param_names = match *m { - hir::TraitFn::Required(ref names) => self.encode_fn_param_names(names), - hir::TraitFn::Provided(body) => self.encode_fn_param_names_for_body(body), + match *m { + hir::TraitFn::Required(ref names) => { + record!(self.tables.fn_arg_names[def_id] <- *names) + } + hir::TraitFn::Provided(body) => { + record!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)) + } }; record!(self.tables.asyncness[def_id] <- m_sig.header.asyncness); - FnData { constness: hir::Constness::NotConst, param_names } + FnData { constness: hir::Constness::NotConst } } else { bug!() }; @@ -1262,6 +1266,7 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) { ty::AssocKind::Fn => { let fn_data = if let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind { record!(self.tables.asyncness[def_id] <- sig.header.asyncness); + record!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)); FnData { // Can be inside `impl const Trait`, so using sig.header.constness is not reliable constness: if self.tcx.is_const_fn_raw(def_id) { @@ -1269,7 +1274,6 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) { } else { hir::Constness::NotConst }, - param_names: self.encode_fn_param_names_for_body(body), } } else { bug!() @@ -1294,14 +1298,6 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) { } } - fn encode_fn_param_names_for_body(&mut self, body_id: hir::BodyId) -> Lazy<[Ident]> { - self.lazy(self.tcx.hir().body_param_names(body_id)) - } - - fn encode_fn_param_names(&mut self, param_names: &[Ident]) -> Lazy<[Ident]> { - self.lazy(param_names.iter()) - } - fn encode_mir(&mut self) { if self.is_proc_macro { return; @@ -1405,10 +1401,8 @@ fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item<'tcx>) { } hir::ItemKind::Fn(ref sig, .., body) => { record!(self.tables.asyncness[def_id] <- sig.header.asyncness); - let data = FnData { - constness: sig.header.constness, - param_names: self.encode_fn_param_names_for_body(body), - }; + record!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)); + let data = FnData { constness: sig.header.constness }; EntryKind::Fn(self.lazy(data)) } @@ -1874,13 +1868,13 @@ fn encode_info_for_foreign_item(&mut self, def_id: DefId, nitem: &hir::ForeignIt match nitem.kind { hir::ForeignItemKind::Fn(_, ref names, _) => { record!(self.tables.asyncness[def_id] <- hir::IsAsync::NotAsync); + record!(self.tables.fn_arg_names[def_id] <- *names); let data = FnData { constness: if self.tcx.is_const_fn_raw(def_id) { hir::Constness::Const } else { hir::Constness::NotConst }, - param_names: self.encode_fn_param_names(names), }; record!(self.tables.kind[def_id] <- EntryKind::ForeignFn(self.lazy(data))); } diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index d3d3fc61e4c..b3255f6f570 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -311,6 +311,7 @@ fn encode(&self, buf: &mut Encoder) -> LazyTables<'tcx> { mir_const_qualif: Table, rendered_const: Table, asyncness: Table, + fn_arg_names: Table, trait_item_def_id: Table>, inherent_impls: Table>, @@ -363,7 +364,6 @@ enum EntryKind { #[derive(MetadataEncodable, MetadataDecodable)] struct FnData { constness: hir::Constness, - param_names: Lazy<[Ident]>, } #[derive(TyEncodable, TyDecodable)]