1#![feature(assert_matches)]
3#![feature(box_patterns)]
4#![feature(file_buffered)]
5#![feature(if_let_guard)]
6#![feature(negative_impls)]
7#![feature(string_from_utf8_lossy_owned)]
8#![feature(trait_alias)]
9#![feature(try_blocks)]
10#![recursion_limit = "256"]
11use std::collections::BTreeSet;
18use std::io;
19use std::path::{Path, PathBuf};
20use std::sync::Arc;
21
22use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
23use rustc_data_structures::unord::UnordMap;
24use rustc_hir::CRATE_HIR_ID;
25use rustc_hir::attrs::{CfgEntry, NativeLibKind, WindowsSubsystemKind};
26use rustc_hir::def_id::CrateNum;
27use rustc_macros::{Decodable, Encodable};
28use rustc_metadata::EncodedMetadata;
29use rustc_middle::dep_graph::WorkProduct;
30use rustc_middle::lint::LevelAndSource;
31use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
32use rustc_middle::middle::dependency_format::Dependencies;
33use rustc_middle::middle::exported_symbols::SymbolExportKind;
34use rustc_middle::ty::TyCtxt;
35use rustc_middle::util::Providers;
36use rustc_serialize::opaque::{FileEncoder, MemDecoder};
37use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
38use rustc_session::Session;
39use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT};
40use rustc_session::cstore::{self, CrateSource};
41use rustc_session::lint::builtin::LINKER_MESSAGES;
42use rustc_span::Symbol;
43
44pub mod assert_module_sources;
45pub mod back;
46pub mod base;
47pub mod codegen_attrs;
48pub mod common;
49pub mod debuginfo;
50pub mod errors;
51pub mod meth;
52pub mod mir;
53pub mod mono_item;
54pub mod size_of_val;
55pub mod target_features;
56pub mod traits;
57
58pub struct ModuleCodegen<M> {
59 pub name: String,
66 pub module_llvm: M,
67 pub kind: ModuleKind,
68 pub thin_lto_buffer: Option<Vec<u8>>,
70}
71
72impl<M> ModuleCodegen<M> {
73 pub fn new_regular(name: impl Into<String>, module: M) -> Self {
74 Self {
75 name: name.into(),
76 module_llvm: module,
77 kind: ModuleKind::Regular,
78 thin_lto_buffer: None,
79 }
80 }
81
82 pub fn new_allocator(name: impl Into<String>, module: M) -> Self {
83 Self {
84 name: name.into(),
85 module_llvm: module,
86 kind: ModuleKind::Allocator,
87 thin_lto_buffer: None,
88 }
89 }
90
91 pub fn into_compiled_module(
92 self,
93 emit_obj: bool,
94 emit_dwarf_obj: bool,
95 emit_bc: bool,
96 emit_asm: bool,
97 emit_ir: bool,
98 outputs: &OutputFilenames,
99 invocation_temp: Option<&str>,
100 ) -> CompiledModule {
101 let object = emit_obj
102 .then(|| outputs.temp_path_for_cgu(OutputType::Object, &self.name, invocation_temp));
103 let dwarf_object =
104 emit_dwarf_obj.then(|| outputs.temp_path_dwo_for_cgu(&self.name, invocation_temp));
105 let bytecode = emit_bc
106 .then(|| outputs.temp_path_for_cgu(OutputType::Bitcode, &self.name, invocation_temp));
107 let assembly = emit_asm
108 .then(|| outputs.temp_path_for_cgu(OutputType::Assembly, &self.name, invocation_temp));
109 let llvm_ir = emit_ir.then(|| {
110 outputs.temp_path_for_cgu(OutputType::LlvmAssembly, &self.name, invocation_temp)
111 });
112
113 CompiledModule {
114 name: self.name,
115 kind: self.kind,
116 object,
117 dwarf_object,
118 bytecode,
119 assembly,
120 llvm_ir,
121 links_from_incr_cache: Vec::new(),
122 }
123 }
124}
125
126#[derive(#[automatically_derived]
impl ::core::fmt::Debug for CompiledModule {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["name", "kind", "object", "dwarf_object", "bytecode",
"assembly", "llvm_ir", "links_from_incr_cache"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.name, &self.kind, &self.object, &self.dwarf_object,
&self.bytecode, &self.assembly, &self.llvm_ir,
&&self.links_from_incr_cache];
::core::fmt::Formatter::debug_struct_fields_finish(f,
"CompiledModule", names, values)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for CompiledModule {
fn encode(&self, __encoder: &mut __E) {
match *self {
CompiledModule {
name: ref __binding_0,
kind: ref __binding_1,
object: ref __binding_2,
dwarf_object: ref __binding_3,
bytecode: ref __binding_4,
assembly: ref __binding_5,
llvm_ir: ref __binding_6,
links_from_incr_cache: ref __binding_7 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_3,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_4,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_5,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_6,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_7,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for CompiledModule {
fn decode(__decoder: &mut __D) -> Self {
CompiledModule {
name: ::rustc_serialize::Decodable::decode(__decoder),
kind: ::rustc_serialize::Decodable::decode(__decoder),
object: ::rustc_serialize::Decodable::decode(__decoder),
dwarf_object: ::rustc_serialize::Decodable::decode(__decoder),
bytecode: ::rustc_serialize::Decodable::decode(__decoder),
assembly: ::rustc_serialize::Decodable::decode(__decoder),
llvm_ir: ::rustc_serialize::Decodable::decode(__decoder),
links_from_incr_cache: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
127pub struct CompiledModule {
128 pub name: String,
129 pub kind: ModuleKind,
130 pub object: Option<PathBuf>,
131 pub dwarf_object: Option<PathBuf>,
132 pub bytecode: Option<PathBuf>,
133 pub assembly: Option<PathBuf>, pub llvm_ir: Option<PathBuf>, pub links_from_incr_cache: Vec<PathBuf>,
136}
137
138impl CompiledModule {
139 pub fn for_each_output(&self, mut emit: impl FnMut(&Path, OutputType)) {
141 if let Some(path) = self.object.as_deref() {
142 emit(path, OutputType::Object);
143 }
144 if let Some(path) = self.bytecode.as_deref() {
145 emit(path, OutputType::Bitcode);
146 }
147 if let Some(path) = self.llvm_ir.as_deref() {
148 emit(path, OutputType::LlvmAssembly);
149 }
150 if let Some(path) = self.assembly.as_deref() {
151 emit(path, OutputType::Assembly);
152 }
153 }
154}
155
156pub(crate) struct CachedModuleCodegen {
157 pub name: String,
158 pub source: WorkProduct,
159}
160
161#[derive(#[automatically_derived]
impl ::core::marker::Copy for ModuleKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ModuleKind {
#[inline]
fn clone(&self) -> ModuleKind { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ModuleKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ModuleKind::Regular => "Regular",
ModuleKind::Allocator => "Allocator",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for ModuleKind {
#[inline]
fn eq(&self, other: &ModuleKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for ModuleKind {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ModuleKind::Regular => { 0usize }
ModuleKind::Allocator => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ModuleKind::Regular => {}
ModuleKind::Allocator => {}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for ModuleKind {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { ModuleKind::Regular }
1usize => { ModuleKind::Allocator }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ModuleKind`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable)]
162pub enum ModuleKind {
163 Regular,
164 Allocator,
165}
166
167pub struct MemFlags(<MemFlags as
::bitflags::__private::PublicFlags>::Internal);
#[automatically_derived]
impl ::core::fmt::Debug for MemFlags {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "MemFlags",
&&self.0)
}
}
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for MemFlags { }
#[automatically_derived]
impl ::core::clone::Clone for MemFlags {
#[inline]
fn clone(&self) -> MemFlags {
let _:
::core::clone::AssertParamIsClone<<MemFlags as
::bitflags::__private::PublicFlags>::Internal>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for MemFlags { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for MemFlags { }
#[automatically_derived]
impl ::core::cmp::PartialEq for MemFlags {
#[inline]
fn eq(&self, other: &MemFlags) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for MemFlags {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _:
::core::cmp::AssertParamIsEq<<MemFlags as
::bitflags::__private::PublicFlags>::Internal>;
}
}
impl MemFlags {
#[allow(deprecated, non_upper_case_globals,)]
pub const VOLATILE: Self = Self::from_bits_retain(1 << 0);
#[allow(deprecated, non_upper_case_globals,)]
pub const NONTEMPORAL: Self = Self::from_bits_retain(1 << 1);
#[allow(deprecated, non_upper_case_globals,)]
pub const UNALIGNED: Self = Self::from_bits_retain(1 << 2);
}
impl ::bitflags::Flags for MemFlags {
const FLAGS: &'static [::bitflags::Flag<MemFlags>] =
&[{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("VOLATILE", MemFlags::VOLATILE)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("NONTEMPORAL", MemFlags::NONTEMPORAL)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("UNALIGNED", MemFlags::UNALIGNED)
}];
type Bits = u8;
fn bits(&self) -> u8 { MemFlags::bits(self) }
fn from_bits_retain(bits: u8) -> MemFlags {
MemFlags::from_bits_retain(bits)
}
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: indexing_slicing, clippy :: same_name_method,
clippy :: iter_without_into_iter,)]
const _: () =
{
#[repr(transparent)]
pub struct InternalBitFlags(u8);
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for InternalBitFlags { }
#[automatically_derived]
impl ::core::clone::Clone for InternalBitFlags {
#[inline]
fn clone(&self) -> InternalBitFlags {
let _: ::core::clone::AssertParamIsClone<u8>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for InternalBitFlags { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for InternalBitFlags { }
#[automatically_derived]
impl ::core::cmp::PartialEq for InternalBitFlags {
#[inline]
fn eq(&self, other: &InternalBitFlags) -> bool {
self.0 == other.0
}
}
#[automatically_derived]
impl ::core::cmp::Eq for InternalBitFlags {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u8>;
}
}
#[automatically_derived]
impl ::core::cmp::PartialOrd for InternalBitFlags {
#[inline]
fn partial_cmp(&self, other: &InternalBitFlags)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::cmp::Ord for InternalBitFlags {
#[inline]
fn cmp(&self, other: &InternalBitFlags) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::hash::Hash for InternalBitFlags {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
impl ::bitflags::__private::PublicFlags for MemFlags {
type Primitive = u8;
type Internal = InternalBitFlags;
}
impl ::bitflags::__private::core::default::Default for
InternalBitFlags {
#[inline]
fn default() -> Self { InternalBitFlags::empty() }
}
impl ::bitflags::__private::core::fmt::Debug for InternalBitFlags {
fn fmt(&self,
f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
-> ::bitflags::__private::core::fmt::Result {
if self.is_empty() {
f.write_fmt(format_args!("{0:#x}",
<u8 as ::bitflags::Bits>::EMPTY))
} else {
::bitflags::__private::core::fmt::Display::fmt(self, f)
}
}
}
impl ::bitflags::__private::core::fmt::Display for InternalBitFlags {
fn fmt(&self,
f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
-> ::bitflags::__private::core::fmt::Result {
::bitflags::parser::to_writer(&MemFlags(*self), f)
}
}
impl ::bitflags::__private::core::str::FromStr for InternalBitFlags {
type Err = ::bitflags::parser::ParseError;
fn from_str(s: &str)
->
::bitflags::__private::core::result::Result<Self,
Self::Err> {
::bitflags::parser::from_str::<MemFlags>(s).map(|flags|
flags.0)
}
}
impl ::bitflags::__private::core::convert::AsRef<u8> for
InternalBitFlags {
fn as_ref(&self) -> &u8 { &self.0 }
}
impl ::bitflags::__private::core::convert::From<u8> for
InternalBitFlags {
fn from(bits: u8) -> Self { Self::from_bits_retain(bits) }
}
#[allow(dead_code, deprecated, unused_attributes)]
impl InternalBitFlags {
#[inline]
pub const fn empty() -> Self {
Self(<u8 as ::bitflags::Bits>::EMPTY)
}
#[inline]
pub const fn all() -> Self {
let mut truncated = <u8 as ::bitflags::Bits>::EMPTY;
let mut i = 0;
{
{
let flag =
<MemFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<MemFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<MemFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
let _ = i;
Self(truncated)
}
#[inline]
pub const fn bits(&self) -> u8 { self.0 }
#[inline]
pub const fn from_bits(bits: u8)
-> ::bitflags::__private::core::option::Option<Self> {
let truncated = Self::from_bits_truncate(bits).0;
if truncated == bits {
::bitflags::__private::core::option::Option::Some(Self(bits))
} else { ::bitflags::__private::core::option::Option::None }
}
#[inline]
pub const fn from_bits_truncate(bits: u8) -> Self {
Self(bits & Self::all().0)
}
#[inline]
pub const fn from_bits_retain(bits: u8) -> Self { Self(bits) }
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
{
if name == "VOLATILE" {
return ::bitflags::__private::core::option::Option::Some(Self(MemFlags::VOLATILE.bits()));
}
};
;
{
if name == "NONTEMPORAL" {
return ::bitflags::__private::core::option::Option::Some(Self(MemFlags::NONTEMPORAL.bits()));
}
};
;
{
if name == "UNALIGNED" {
return ::bitflags::__private::core::option::Option::Some(Self(MemFlags::UNALIGNED.bits()));
}
};
;
let _ = name;
::bitflags::__private::core::option::Option::None
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.0 == <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn is_all(&self) -> bool {
Self::all().0 | self.0 == self.0
}
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0 & other.0 != <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0 & other.0 == other.0
}
#[inline]
pub fn insert(&mut self, other: Self) {
*self = Self(self.0).union(other);
}
#[inline]
pub fn remove(&mut self, other: Self) {
*self = Self(self.0).difference(other);
}
#[inline]
pub fn toggle(&mut self, other: Self) {
*self = Self(self.0).symmetric_difference(other);
}
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0 ^ other.0)
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self::from_bits_truncate(!self.0)
}
}
impl ::bitflags::__private::core::fmt::Binary for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for InternalBitFlags {
type Output = Self;
#[inline]
fn bitor(self, other: InternalBitFlags) -> Self {
self.union(other)
}
}
impl ::bitflags::__private::core::ops::BitOrAssign for
InternalBitFlags {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for InternalBitFlags {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for
InternalBitFlags {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for InternalBitFlags {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for
InternalBitFlags {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for InternalBitFlags {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for InternalBitFlags
{
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for InternalBitFlags {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<InternalBitFlags> for
InternalBitFlags {
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<InternalBitFlags>
for InternalBitFlags {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl InternalBitFlags {
#[inline]
pub const fn iter(&self) -> ::bitflags::iter::Iter<MemFlags> {
::bitflags::iter::Iter::__private_const_new(<MemFlags as
::bitflags::Flags>::FLAGS,
MemFlags::from_bits_retain(self.bits()),
MemFlags::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<MemFlags> {
::bitflags::iter::IterNames::__private_const_new(<MemFlags as
::bitflags::Flags>::FLAGS,
MemFlags::from_bits_retain(self.bits()),
MemFlags::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for
InternalBitFlags {
type Item = MemFlags;
type IntoIter = ::bitflags::iter::Iter<MemFlags>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
impl InternalBitFlags {
#[inline]
pub fn bits_mut(&mut self) -> &mut u8 { &mut self.0 }
}
#[allow(dead_code, deprecated, unused_attributes)]
impl MemFlags {
#[inline]
pub const fn empty() -> Self { Self(InternalBitFlags::empty()) }
#[inline]
pub const fn all() -> Self { Self(InternalBitFlags::all()) }
#[inline]
pub const fn bits(&self) -> u8 { self.0.bits() }
#[inline]
pub const fn from_bits(bits: u8)
-> ::bitflags::__private::core::option::Option<Self> {
match InternalBitFlags::from_bits(bits) {
::bitflags::__private::core::option::Option::Some(bits) =>
::bitflags::__private::core::option::Option::Some(Self(bits)),
::bitflags::__private::core::option::Option::None =>
::bitflags::__private::core::option::Option::None,
}
}
#[inline]
pub const fn from_bits_truncate(bits: u8) -> Self {
Self(InternalBitFlags::from_bits_truncate(bits))
}
#[inline]
pub const fn from_bits_retain(bits: u8) -> Self {
Self(InternalBitFlags::from_bits_retain(bits))
}
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
match InternalBitFlags::from_name(name) {
::bitflags::__private::core::option::Option::Some(bits) =>
::bitflags::__private::core::option::Option::Some(Self(bits)),
::bitflags::__private::core::option::Option::None =>
::bitflags::__private::core::option::Option::None,
}
}
#[inline]
pub const fn is_empty(&self) -> bool { self.0.is_empty() }
#[inline]
pub const fn is_all(&self) -> bool { self.0.is_all() }
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0.intersects(other.0)
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0.contains(other.0)
}
#[inline]
pub fn insert(&mut self, other: Self) { self.0.insert(other.0) }
#[inline]
pub fn remove(&mut self, other: Self) { self.0.remove(other.0) }
#[inline]
pub fn toggle(&mut self, other: Self) { self.0.toggle(other.0) }
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
self.0.set(other.0, value)
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0.intersection(other.0))
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0.union(other.0))
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0.difference(other.0))
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0.symmetric_difference(other.0))
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self(self.0.complement())
}
}
impl ::bitflags::__private::core::fmt::Binary for MemFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for MemFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for MemFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for MemFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for MemFlags {
type Output = Self;
#[inline]
fn bitor(self, other: MemFlags) -> Self { self.union(other) }
}
impl ::bitflags::__private::core::ops::BitOrAssign for MemFlags {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for MemFlags {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for MemFlags {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for MemFlags {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for MemFlags {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for MemFlags {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for MemFlags {
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for MemFlags {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<MemFlags> for MemFlags
{
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<MemFlags> for
MemFlags {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl MemFlags {
#[inline]
pub const fn iter(&self) -> ::bitflags::iter::Iter<MemFlags> {
::bitflags::iter::Iter::__private_const_new(<MemFlags as
::bitflags::Flags>::FLAGS,
MemFlags::from_bits_retain(self.bits()),
MemFlags::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<MemFlags> {
::bitflags::iter::IterNames::__private_const_new(<MemFlags as
::bitflags::Flags>::FLAGS,
MemFlags::from_bits_retain(self.bits()),
MemFlags::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for MemFlags {
type Item = MemFlags;
type IntoIter = ::bitflags::iter::Iter<MemFlags>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
};bitflags::bitflags! {
168 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
169 pub struct MemFlags: u8 {
170 const VOLATILE = 1 << 0;
171 const NONTEMPORAL = 1 << 1;
172 const UNALIGNED = 1 << 2;
173 }
174}
175
176#[derive(#[automatically_derived]
impl ::core::clone::Clone for NativeLib {
#[inline]
fn clone(&self) -> NativeLib {
NativeLib {
kind: ::core::clone::Clone::clone(&self.kind),
name: ::core::clone::Clone::clone(&self.name),
filename: ::core::clone::Clone::clone(&self.filename),
cfg: ::core::clone::Clone::clone(&self.cfg),
verbatim: ::core::clone::Clone::clone(&self.verbatim),
dll_imports: ::core::clone::Clone::clone(&self.dll_imports),
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for NativeLib {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["kind", "name", "filename", "cfg", "verbatim", "dll_imports"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.kind, &self.name, &self.filename, &self.cfg,
&self.verbatim, &&self.dll_imports];
::core::fmt::Formatter::debug_struct_fields_finish(f, "NativeLib",
names, values)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for NativeLib {
fn encode(&self, __encoder: &mut __E) {
match *self {
NativeLib {
kind: ref __binding_0,
name: ref __binding_1,
filename: ref __binding_2,
cfg: ref __binding_3,
verbatim: ref __binding_4,
dll_imports: ref __binding_5 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_3,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_4,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_5,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for NativeLib {
fn decode(__decoder: &mut __D) -> Self {
NativeLib {
kind: ::rustc_serialize::Decodable::decode(__decoder),
name: ::rustc_serialize::Decodable::decode(__decoder),
filename: ::rustc_serialize::Decodable::decode(__decoder),
cfg: ::rustc_serialize::Decodable::decode(__decoder),
verbatim: ::rustc_serialize::Decodable::decode(__decoder),
dll_imports: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
182pub struct NativeLib {
183 pub kind: NativeLibKind,
184 pub name: Symbol,
185 pub filename: Option<Symbol>,
186 pub cfg: Option<CfgEntry>,
187 pub verbatim: bool,
188 pub dll_imports: Vec<cstore::DllImport>,
189}
190
191impl From<&cstore::NativeLib> for NativeLib {
192 fn from(lib: &cstore::NativeLib) -> Self {
193 NativeLib {
194 kind: lib.kind,
195 filename: lib.filename,
196 name: lib.name,
197 cfg: lib.cfg.clone(),
198 verbatim: lib.verbatim.unwrap_or(false),
199 dll_imports: lib.dll_imports.clone(),
200 }
201 }
202}
203
204#[derive(#[automatically_derived]
impl ::core::fmt::Debug for CrateInfo {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["target_cpu", "target_features", "crate_types",
"exported_symbols", "linked_symbols", "local_crate_name",
"compiler_builtins", "profiler_runtime", "is_no_builtins",
"native_libraries", "crate_name", "used_libraries",
"used_crate_source", "used_crates", "dependency_formats",
"windows_subsystem", "natvis_debugger_visualizers",
"lint_levels", "metadata_symbol"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.target_cpu, &self.target_features, &self.crate_types,
&self.exported_symbols, &self.linked_symbols,
&self.local_crate_name, &self.compiler_builtins,
&self.profiler_runtime, &self.is_no_builtins,
&self.native_libraries, &self.crate_name,
&self.used_libraries, &self.used_crate_source,
&self.used_crates, &self.dependency_formats,
&self.windows_subsystem, &self.natvis_debugger_visualizers,
&self.lint_levels, &&self.metadata_symbol];
::core::fmt::Formatter::debug_struct_fields_finish(f, "CrateInfo",
names, values)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for CrateInfo {
fn encode(&self, __encoder: &mut __E) {
match *self {
CrateInfo {
target_cpu: ref __binding_0,
target_features: ref __binding_1,
crate_types: ref __binding_2,
exported_symbols: ref __binding_3,
linked_symbols: ref __binding_4,
local_crate_name: ref __binding_5,
compiler_builtins: ref __binding_6,
profiler_runtime: ref __binding_7,
is_no_builtins: ref __binding_8,
native_libraries: ref __binding_9,
crate_name: ref __binding_10,
used_libraries: ref __binding_11,
used_crate_source: ref __binding_12,
used_crates: ref __binding_13,
dependency_formats: ref __binding_14,
windows_subsystem: ref __binding_15,
natvis_debugger_visualizers: ref __binding_16,
lint_levels: ref __binding_17,
metadata_symbol: ref __binding_18 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_3,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_4,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_5,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_6,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_7,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_8,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_9,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_10,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_11,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_12,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_13,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_14,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_15,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_16,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_17,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_18,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for CrateInfo {
fn decode(__decoder: &mut __D) -> Self {
CrateInfo {
target_cpu: ::rustc_serialize::Decodable::decode(__decoder),
target_features: ::rustc_serialize::Decodable::decode(__decoder),
crate_types: ::rustc_serialize::Decodable::decode(__decoder),
exported_symbols: ::rustc_serialize::Decodable::decode(__decoder),
linked_symbols: ::rustc_serialize::Decodable::decode(__decoder),
local_crate_name: ::rustc_serialize::Decodable::decode(__decoder),
compiler_builtins: ::rustc_serialize::Decodable::decode(__decoder),
profiler_runtime: ::rustc_serialize::Decodable::decode(__decoder),
is_no_builtins: ::rustc_serialize::Decodable::decode(__decoder),
native_libraries: ::rustc_serialize::Decodable::decode(__decoder),
crate_name: ::rustc_serialize::Decodable::decode(__decoder),
used_libraries: ::rustc_serialize::Decodable::decode(__decoder),
used_crate_source: ::rustc_serialize::Decodable::decode(__decoder),
used_crates: ::rustc_serialize::Decodable::decode(__decoder),
dependency_formats: ::rustc_serialize::Decodable::decode(__decoder),
windows_subsystem: ::rustc_serialize::Decodable::decode(__decoder),
natvis_debugger_visualizers: ::rustc_serialize::Decodable::decode(__decoder),
lint_levels: ::rustc_serialize::Decodable::decode(__decoder),
metadata_symbol: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
213pub struct CrateInfo {
214 pub target_cpu: String,
215 pub target_features: Vec<String>,
216 pub crate_types: Vec<CrateType>,
217 pub exported_symbols: UnordMap<CrateType, Vec<(String, SymbolExportKind)>>,
218 pub linked_symbols: FxIndexMap<CrateType, Vec<(String, SymbolExportKind)>>,
219 pub local_crate_name: Symbol,
220 pub compiler_builtins: Option<CrateNum>,
221 pub profiler_runtime: Option<CrateNum>,
222 pub is_no_builtins: FxHashSet<CrateNum>,
223 pub native_libraries: FxIndexMap<CrateNum, Vec<NativeLib>>,
224 pub crate_name: UnordMap<CrateNum, Symbol>,
225 pub used_libraries: Vec<NativeLib>,
226 pub used_crate_source: UnordMap<CrateNum, Arc<CrateSource>>,
227 pub used_crates: Vec<CrateNum>,
228 pub dependency_formats: Arc<Dependencies>,
229 pub windows_subsystem: Option<WindowsSubsystemKind>,
230 pub natvis_debugger_visualizers: BTreeSet<DebuggerVisualizerFile>,
231 pub lint_levels: CodegenLintLevels,
232 pub metadata_symbol: String,
233}
234
235pub struct TargetConfig {
239 pub target_features: Vec<Symbol>,
241 pub unstable_target_features: Vec<Symbol>,
243 pub has_reliable_f16: bool,
245 pub has_reliable_f16_math: bool,
247 pub has_reliable_f128: bool,
249 pub has_reliable_f128_math: bool,
251}
252
253#[derive(const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for CodegenResults {
fn encode(&self, __encoder: &mut __E) {
match *self {
CodegenResults {
modules: ref __binding_0,
allocator_module: ref __binding_1,
crate_info: ref __binding_2 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for CodegenResults {
fn decode(__decoder: &mut __D) -> Self {
CodegenResults {
modules: ::rustc_serialize::Decodable::decode(__decoder),
allocator_module: ::rustc_serialize::Decodable::decode(__decoder),
crate_info: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
254pub struct CodegenResults {
255 pub modules: Vec<CompiledModule>,
256 pub allocator_module: Option<CompiledModule>,
257 pub crate_info: CrateInfo,
258}
259
260pub enum CodegenErrors {
261 WrongFileType,
262 EmptyVersionNumber,
263 EncodingVersionMismatch { version_array: String, rlink_version: u32 },
264 RustcVersionMismatch { rustc_version: String },
265 CorruptFile,
266}
267
268pub fn provide(providers: &mut Providers) {
269 crate::back::symbol_export::provide(providers);
270 crate::base::provide(&mut providers.queries);
271 crate::target_features::provide(&mut providers.queries);
272 crate::codegen_attrs::provide(&mut providers.queries);
273 providers.queries.global_backend_features = |_tcx: TyCtxt<'_>, ()| ::alloc::vec::Vec::new()vec![];
274}
275
276pub fn looks_like_rust_object_file(filename: &str) -> bool {
279 let path = Path::new(filename);
280 let ext = path.extension().and_then(|s| s.to_str());
281 if ext != Some(OutputType::Object.extension()) {
282 return false;
284 }
285
286 let ext2 = path.file_stem().and_then(|s| Path::new(s).extension()).and_then(|s| s.to_str());
288
289 ext2 == Some(RUST_CGU_EXT)
291}
292
293const RLINK_VERSION: u32 = 1;
294const RLINK_MAGIC: &[u8] = b"rustlink";
295
296impl CodegenResults {
297 pub fn serialize_rlink(
298 sess: &Session,
299 rlink_file: &Path,
300 codegen_results: &CodegenResults,
301 metadata: &EncodedMetadata,
302 outputs: &OutputFilenames,
303 ) -> Result<usize, io::Error> {
304 let mut encoder = FileEncoder::new(rlink_file)?;
305 encoder.emit_raw_bytes(RLINK_MAGIC);
306 encoder.emit_raw_bytes(&RLINK_VERSION.to_be_bytes());
309 encoder.emit_str(sess.cfg_version);
310 Encodable::encode(codegen_results, &mut encoder);
311 Encodable::encode(metadata, &mut encoder);
312 Encodable::encode(outputs, &mut encoder);
313 encoder.finish().map_err(|(_path, err)| err)
314 }
315
316 pub fn deserialize_rlink(
317 sess: &Session,
318 data: Vec<u8>,
319 ) -> Result<(Self, EncodedMetadata, OutputFilenames), CodegenErrors> {
320 if !data.starts_with(RLINK_MAGIC) {
323 return Err(CodegenErrors::WrongFileType);
324 }
325 let data = &data[RLINK_MAGIC.len()..];
326 if data.len() < 4 {
327 return Err(CodegenErrors::EmptyVersionNumber);
328 }
329
330 let mut version_array: [u8; 4] = Default::default();
331 version_array.copy_from_slice(&data[..4]);
332 if u32::from_be_bytes(version_array) != RLINK_VERSION {
333 return Err(CodegenErrors::EncodingVersionMismatch {
334 version_array: String::from_utf8_lossy(&version_array).to_string(),
335 rlink_version: RLINK_VERSION,
336 });
337 }
338
339 let Ok(mut decoder) = MemDecoder::new(&data[4..], 0) else {
340 return Err(CodegenErrors::CorruptFile);
341 };
342 let rustc_version = decoder.read_str();
343 if rustc_version != sess.cfg_version {
344 return Err(CodegenErrors::RustcVersionMismatch {
345 rustc_version: rustc_version.to_string(),
346 });
347 }
348
349 let codegen_results = CodegenResults::decode(&mut decoder);
350 let metadata = EncodedMetadata::decode(&mut decoder);
351 let outputs = OutputFilenames::decode(&mut decoder);
352 Ok((codegen_results, metadata, outputs))
353 }
354}
355
356#[derive(#[automatically_derived]
impl ::core::marker::Copy for CodegenLintLevels { }Copy, #[automatically_derived]
impl ::core::clone::Clone for CodegenLintLevels {
#[inline]
fn clone(&self) -> CodegenLintLevels {
let _: ::core::clone::AssertParamIsClone<LevelAndSource>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for CodegenLintLevels {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"CodegenLintLevels", "linker_messages", &&self.linker_messages)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for CodegenLintLevels {
fn encode(&self, __encoder: &mut __E) {
match *self {
CodegenLintLevels { linker_messages: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for CodegenLintLevels {
fn decode(__decoder: &mut __D) -> Self {
CodegenLintLevels {
linker_messages: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
362pub struct CodegenLintLevels {
363 linker_messages: LevelAndSource,
364}
365
366impl CodegenLintLevels {
367 pub fn from_tcx(tcx: TyCtxt<'_>) -> Self {
368 Self { linker_messages: tcx.lint_level_at_node(LINKER_MESSAGES, CRATE_HIR_ID) }
369 }
370}