1
Fork 0

Replace -Z default-hidden-visibility with -Z default-visibility

MCP: https://github.com/rust-lang/compiler-team/issues/782

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
This commit is contained in:
David Lattimore 2024-10-01 08:55:10 +10:00
parent fb4aebddd1
commit f48194ea55
14 changed files with 208 additions and 81 deletions

View file

@ -904,26 +904,22 @@ fn mono_item_visibility<'tcx>(
}
fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibility {
if !tcx.sess.default_hidden_visibility() {
return Visibility::Default;
}
let export_level = if is_generic {
// Generic functions never have export-level C.
SymbolExportLevel::Rust
} else {
match tcx.reachable_non_generics(id.krate).get(&id) {
Some(SymbolExportInfo { level: SymbolExportLevel::C, .. }) => SymbolExportLevel::C,
_ => SymbolExportLevel::Rust,
}
};
match export_level {
// C-export level items remain at `Default` to allow C code to
// access and interpose them.
SymbolExportLevel::C => Visibility::Default,
// Generic functions never have export-level C.
if is_generic {
return Visibility::Hidden;
}
// Things with export level C don't get instantiated in
// downstream crates.
if !id.is_local() {
return Visibility::Hidden;
}
// C-export level items remain at `Default`, all other internal
// items become `Hidden`.
match tcx.reachable_non_generics(id.krate).get(&id) {
Some(SymbolExportInfo { level: SymbolExportLevel::C, .. }) => Visibility::Default,
_ => Visibility::Hidden,
// For all other symbols, `default_visibility` determines which visibility to use.
SymbolExportLevel::Rust => tcx.sess.default_visibility().into(),
}
}