1
Fork 0

Rollup merge of #131686 - Urgau:fast-path-vis, r=lqd

Add fast-path when computing the default visibility

This PR adds (or more correctly re-adds the) fast-path when computing the default visibility, by taking advantage of the fact that the "interposable" requested visibility always return the "default" codegen visibility.

Should address the small regression observed in https://github.com/rust-lang/rust/pull/131111#issuecomment-2402273967.

r? `@lqd`
This commit is contained in:
Matthias Krüger 2024-10-16 19:18:31 +02:00 committed by GitHub
commit 2560453256
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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.