From 67b85e2a1f4e7632e5805fcc6e6a6f53501dd357 Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 14 Oct 2024 16:37:54 +0200 Subject: [PATCH] Add fast-path when computing the default visibility --- compiler/rustc_monomorphize/src/partitioning.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 5bd484d7bb002..9bf7e67417eff 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -119,6 +119,7 @@ use rustc_middle::util::Providers; use rustc_session::CodegenUnits; use rustc_session::config::{DumpMonoStatsFormat, SwitchWithOptPath}; use rustc_span::symbol::Symbol; +use rustc_target::spec::SymbolVisibility; use tracing::debug; use crate::collector::{self, MonoItemCollectionStrategy, UsageMap}; @@ -904,6 +905,11 @@ fn mono_item_visibility<'tcx>( } fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibility { + // Fast-path to avoid expensive query call below + if tcx.sess.default_visibility() == SymbolVisibility::Interposable { + return Visibility::Default; + } + let export_level = if is_generic { // Generic functions never have export-level C. SymbolExportLevel::Rust @@ -913,6 +919,7 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit _ => SymbolExportLevel::Rust, } }; + match export_level { // C-export level items remain at `Default` to allow C code to // access and interpose them.