]>
git.proxmox.com Git - rustc.git/blob - compiler/rustc_middle/src/middle/exported_symbols.rs
1 use crate::ty
::subst
::SubstsRef
;
2 use crate::ty
::{self, Ty, TyCtxt}
;
3 use rustc_hir
::def_id
::{DefId, LOCAL_CRATE}
;
4 use rustc_macros
::HashStable
;
6 /// The SymbolExportLevel of a symbols specifies from which kinds of crates
7 /// the symbol will be exported. `C` symbols will be exported from any
8 /// kind of crate, including cdylibs which export very few things.
9 /// `Rust` will only be exported if the crate produced is a Rust
11 #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
12 pub enum SymbolExportLevel
{
17 impl SymbolExportLevel
{
18 pub fn is_below_threshold(self, threshold
: SymbolExportLevel
) -> bool
{
19 threshold
== SymbolExportLevel
::Rust
// export everything from Rust dylibs
20 || self == SymbolExportLevel
::C
24 #[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
25 pub enum ExportedSymbol
<'tcx
> {
27 Generic(DefId
, SubstsRef
<'tcx
>),
29 NoDefId(ty
::SymbolName
<'tcx
>),
32 impl<'tcx
> ExportedSymbol
<'tcx
> {
33 /// This is the symbol name of an instance if it is instantiated in the
35 pub fn symbol_name_for_local_instance(&self, tcx
: TyCtxt
<'tcx
>) -> ty
::SymbolName
<'tcx
> {
37 ExportedSymbol
::NonGeneric(def_id
) => tcx
.symbol_name(ty
::Instance
::mono(tcx
, def_id
)),
38 ExportedSymbol
::Generic(def_id
, substs
) => {
39 tcx
.symbol_name(ty
::Instance
::new(def_id
, substs
))
41 ExportedSymbol
::DropGlue(ty
) => {
42 tcx
.symbol_name(ty
::Instance
::resolve_drop_in_place(tcx
, ty
))
44 ExportedSymbol
::NoDefId(symbol_name
) => symbol_name
,
49 pub fn metadata_symbol_name(tcx
: TyCtxt
<'_
>) -> String
{
51 "rust_metadata_{}_{}",
52 tcx
.original_crate_name(LOCAL_CRATE
),
53 tcx
.crate_disambiguator(LOCAL_CRATE
).to_fingerprint().to_hex()