Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,13 @@ pub(crate) fn exported_symbols(
exported_symbols_for_non_proc_macro(tcx, crate_type)
};

if crate_type == CrateType::Dylib || crate_type == CrateType::ProcMacro {
// Preserve the metadata symbol to ensure the metadata section doesn't get removed by the
// linker. On wasm however the metadata is put in a custom section, to which symbols can't
// refer, so there is no metadata symbol there. Luckily custom sections are always preserved by
// the linker.
if (crate_type == CrateType::Dylib || crate_type == CrateType::ProcMacro)
&& !tcx.sess.target.is_like_wasm
{
let metadata_symbol_name = exported_symbols::metadata_symbol_name(tcx);
symbols.push((metadata_symbol_name, SymbolExportKind::Data));
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4570,6 +4570,7 @@ impl<'hir> Item<'hir> {
HirId::make_owner(self.owner_id.def_id)
}

#[inline]
pub fn item_id(&self) -> ItemId {
ItemId { owner_id: self.owner_id }
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod diagnostics;
pub mod interface;
mod limits;
pub mod passes;
mod proc_macro_decls;
mod queries;
pub mod util;

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use rustc_trait_selection::{solve, traits};
use tracing::{info, instrument};

use crate::interface::Compiler;
use crate::{diagnostics, limits, proc_macro_decls, util};
use crate::{diagnostics, limits, util};

pub fn parse<'a>(sess: &'a Session) -> ast::Crate {
let mut krate = sess
Expand Down Expand Up @@ -897,9 +897,9 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
providers.queries.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).2;
providers.queries.early_lint_checks = early_lint_checks;
providers.queries.env_var_os = env_var_os;
providers.queries.proc_macro_decls_static = |tcx, _| tcx.hir_crate_items(()).proc_macro_decls();
rustc_ast_lowering::provide(&mut providers.queries);
limits::provide(&mut providers.queries);
proc_macro_decls::provide(&mut providers.queries);
rustc_expand::provide(&mut providers.queries);
rustc_const_eval::provide(providers);
rustc_middle::hir::provide(&mut providers.queries);
Expand Down
20 changes: 0 additions & 20 deletions compiler/rustc_interface/src/proc_macro_decls.rs

This file was deleted.

51 changes: 28 additions & 23 deletions compiler/rustc_middle/src/hir/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,8 +1275,10 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
opaques,
nested_bodies,
eiis,
proc_macro_decls,
..
} = collector;

ModuleItems {
add_root: false,
submodules: submodules.into_boxed_slice(),
Expand All @@ -1288,6 +1290,7 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod
opaques: opaques.into_boxed_slice(),
nested_bodies: nested_bodies.into_boxed_slice(),
eiis: eiis.into_boxed_slice(),
proc_macro_decls,
}
}

Expand All @@ -1310,6 +1313,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
opaques,
nested_bodies,
eiis,
proc_macro_decls,
..
} = collector;

Expand All @@ -1324,40 +1328,32 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
opaques: opaques.into_boxed_slice(),
nested_bodies: nested_bodies.into_boxed_slice(),
eiis: eiis.into_boxed_slice(),
proc_macro_decls,
}
}

struct ItemCollector<'tcx> {
// When true, it collects all items in the create,
// otherwise it collects items in some module.
// Converting this to generic const didn't lead to significant perf improvements
// (see <https://github.com/rust-lang/rust/pull/158119#issuecomment-4751513679>).
crate_collector: bool,
tcx: TyCtxt<'tcx>,
submodules: Vec<OwnerId>,
items: Vec<ItemId>,
trait_items: Vec<TraitItemId>,
impl_items: Vec<ImplItemId>,
foreign_items: Vec<ForeignItemId>,
body_owners: Vec<LocalDefId>,
opaques: Vec<LocalDefId>,
nested_bodies: Vec<LocalDefId>,
eiis: Vec<LocalDefId>,
submodules: Vec<OwnerId> = vec![],
items: Vec<ItemId> = vec![],
trait_items: Vec<TraitItemId> = vec![],
impl_items: Vec<ImplItemId> = vec![],
foreign_items: Vec<ForeignItemId> = vec![],
body_owners: Vec<LocalDefId> = vec![],
opaques: Vec<LocalDefId> = vec![],
nested_bodies: Vec<LocalDefId> = vec![],
eiis: Vec<LocalDefId> = vec![],
proc_macro_decls: Option<LocalDefId> = None,
}

impl<'tcx> ItemCollector<'tcx> {
fn new(tcx: TyCtxt<'tcx>, crate_collector: bool) -> ItemCollector<'tcx> {
ItemCollector {
crate_collector,
tcx,
submodules: Vec::default(),
items: Vec::default(),
trait_items: Vec::default(),
impl_items: Vec::default(),
foreign_items: Vec::default(),
body_owners: Vec::default(),
opaques: Vec::default(),
nested_bodies: Vec::default(),
eiis: Vec::default(),
}
ItemCollector { crate_collector, tcx, .. }
}
}

Expand All @@ -1373,7 +1369,16 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
self.body_owners.push(item.owner_id.def_id);
}

self.items.push(item.item_id());
let item_id = item.item_id();

if self.crate_collector
&& self.proc_macro_decls.is_none()
&& find_attr!(self.tcx, item_id.hir_id(), RustcProcMacroDecls)
{
self.proc_macro_decls = Some(item_id.owner_id.def_id);
}

self.items.push(item_id);

if let ItemKind::Static(..) | ItemKind::Fn { .. } | ItemKind::Macro(..) = &item.kind
&& item.eii
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub struct ModuleItems {

/// Statics and functions with an `EiiImpls` or `EiiExternTarget` attribute
eiis: Box<[LocalDefId]>,

// only filled with hir_crate_items, not with hir_module_items
proc_macro_decls: Option<LocalDefId>,
}

impl ModuleItems {
Expand All @@ -56,6 +59,11 @@ impl ModuleItems {
self.trait_items.iter().copied()
}

#[inline]
pub fn proc_macro_decls(&self) -> Option<LocalDefId> {
self.proc_macro_decls
}

pub fn eiis(&self) -> impl Iterator<Item = LocalDefId> {
self.eiis.iter().copied()
}
Expand Down
Loading
Loading