rustc: Move crate_types
from Session
to GlobalCtxt
Removes a piece of mutable state. Follow up to #114578.
This commit is contained in:
parent
8838c73e86
commit
0b89aac08d
26 changed files with 108 additions and 108 deletions
|
@ -69,7 +69,7 @@ pub fn link_binary<'a>(
|
|||
let _timer = sess.timer("link_binary");
|
||||
let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata);
|
||||
let mut tempfiles_for_stdout_output: Vec<PathBuf> = Vec::new();
|
||||
for &crate_type in sess.crate_types().iter() {
|
||||
for &crate_type in &codegen_results.crate_info.crate_types {
|
||||
// Ignore executable crates if we have -Z no-codegen, as they will error.
|
||||
if (sess.opts.unstable_opts.no_codegen || !sess.opts.output_types.should_codegen())
|
||||
&& !output_metadata
|
||||
|
|
|
@ -19,7 +19,7 @@ use rustc_session::config::{CrateType, OomStrategy};
|
|||
use rustc_target::spec::SanitizerSet;
|
||||
|
||||
pub fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
|
||||
crates_export_threshold(&tcx.sess.crate_types())
|
||||
crates_export_threshold(tcx.crate_types())
|
||||
}
|
||||
|
||||
fn crate_export_threshold(crate_type: CrateType) -> SymbolExportLevel {
|
||||
|
@ -290,8 +290,8 @@ fn exported_symbols_provider_local(
|
|||
}));
|
||||
}
|
||||
|
||||
if tcx.sess.crate_types().contains(&CrateType::Dylib)
|
||||
|| tcx.sess.crate_types().contains(&CrateType::ProcMacro)
|
||||
if tcx.crate_types().contains(&CrateType::Dylib)
|
||||
|| tcx.crate_types().contains(&CrateType::ProcMacro)
|
||||
{
|
||||
let symbol_name = metadata_symbol_name(tcx);
|
||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
|
||||
|
|
|
@ -123,7 +123,7 @@ pub struct ModuleConfig {
|
|||
impl ModuleConfig {
|
||||
fn new(
|
||||
kind: ModuleKind,
|
||||
sess: &Session,
|
||||
tcx: TyCtxt<'_>,
|
||||
no_builtins: bool,
|
||||
is_compiler_builtins: bool,
|
||||
) -> ModuleConfig {
|
||||
|
@ -135,6 +135,7 @@ impl ModuleConfig {
|
|||
};
|
||||
}
|
||||
|
||||
let sess = tcx.sess;
|
||||
let opt_level_and_size = if_regular!(Some(sess.opts.optimize), None);
|
||||
|
||||
let save_temps = sess.opts.cg.save_temps;
|
||||
|
@ -166,7 +167,7 @@ impl ModuleConfig {
|
|||
// `#![no_builtins]` is assumed to not participate in LTO and
|
||||
// instead goes on to generate object code.
|
||||
EmitObj::Bitcode
|
||||
} else if need_bitcode_in_object(sess) {
|
||||
} else if need_bitcode_in_object(tcx) {
|
||||
EmitObj::ObjectCode(BitcodeSection::Full)
|
||||
} else {
|
||||
EmitObj::ObjectCode(BitcodeSection::None)
|
||||
|
@ -414,9 +415,10 @@ pub struct CompiledModules {
|
|||
pub allocator_module: Option<CompiledModule>,
|
||||
}
|
||||
|
||||
fn need_bitcode_in_object(sess: &Session) -> bool {
|
||||
fn need_bitcode_in_object(tcx: TyCtxt<'_>) -> bool {
|
||||
let sess = tcx.sess;
|
||||
let requested_for_rlib = sess.opts.cg.embed_bitcode
|
||||
&& sess.crate_types().contains(&CrateType::Rlib)
|
||||
&& tcx.crate_types().contains(&CrateType::Rlib)
|
||||
&& sess.opts.output_types.contains_key(&OutputType::Exe);
|
||||
let forced_by_target = sess.target.forces_embed_bitcode;
|
||||
requested_for_rlib || forced_by_target
|
||||
|
@ -450,11 +452,11 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
|
|||
let crate_info = CrateInfo::new(tcx, target_cpu);
|
||||
|
||||
let regular_config =
|
||||
ModuleConfig::new(ModuleKind::Regular, sess, no_builtins, is_compiler_builtins);
|
||||
ModuleConfig::new(ModuleKind::Regular, tcx, no_builtins, is_compiler_builtins);
|
||||
let metadata_config =
|
||||
ModuleConfig::new(ModuleKind::Metadata, sess, no_builtins, is_compiler_builtins);
|
||||
ModuleConfig::new(ModuleKind::Metadata, tcx, no_builtins, is_compiler_builtins);
|
||||
let allocator_config =
|
||||
ModuleConfig::new(ModuleKind::Allocator, sess, no_builtins, is_compiler_builtins);
|
||||
ModuleConfig::new(ModuleKind::Allocator, tcx, no_builtins, is_compiler_builtins);
|
||||
|
||||
let (shared_emitter, shared_emitter_main) = SharedEmitter::new();
|
||||
let (codegen_worker_send, codegen_worker_receive) = channel();
|
||||
|
@ -1092,7 +1094,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
|||
};
|
||||
|
||||
let cgcx = CodegenContext::<B> {
|
||||
crate_types: sess.crate_types().to_vec(),
|
||||
crate_types: tcx.crate_types().to_vec(),
|
||||
each_linked_rlib_for_lto,
|
||||
lto: sess.lto(),
|
||||
fewer_names: sess.fewer_names(),
|
||||
|
@ -2063,7 +2065,7 @@ fn msvc_imps_needed(tcx: TyCtxt<'_>) -> bool {
|
|||
);
|
||||
|
||||
tcx.sess.target.is_like_windows &&
|
||||
tcx.sess.crate_types().iter().any(|ct| *ct == CrateType::Rlib) &&
|
||||
tcx.crate_types().iter().any(|ct| *ct == CrateType::Rlib) &&
|
||||
// ThinLTO can't handle this workaround in all cases, so we don't
|
||||
// emit the `__imp_` symbols. Instead we make them unnecessary by disallowing
|
||||
// dynamic linking when linker plugin LTO is enabled.
|
||||
|
|
|
@ -779,18 +779,13 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
|
|||
|
||||
impl CrateInfo {
|
||||
pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> CrateInfo {
|
||||
let exported_symbols = tcx
|
||||
.sess
|
||||
.crate_types()
|
||||
let crate_types = tcx.crate_types().to_vec();
|
||||
let exported_symbols = crate_types
|
||||
.iter()
|
||||
.map(|&c| (c, crate::back::linker::exported_symbols(tcx, c)))
|
||||
.collect();
|
||||
let linked_symbols = tcx
|
||||
.sess
|
||||
.crate_types()
|
||||
.iter()
|
||||
.map(|&c| (c, crate::back::linker::linked_symbols(tcx, c)))
|
||||
.collect();
|
||||
let linked_symbols =
|
||||
crate_types.iter().map(|&c| (c, crate::back::linker::linked_symbols(tcx, c))).collect();
|
||||
let local_crate_name = tcx.crate_name(LOCAL_CRATE);
|
||||
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
|
||||
let subsystem = attr::first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
|
||||
|
@ -829,6 +824,7 @@ impl CrateInfo {
|
|||
|
||||
let mut info = CrateInfo {
|
||||
target_cpu,
|
||||
crate_types,
|
||||
exported_symbols,
|
||||
linked_symbols,
|
||||
local_crate_name,
|
||||
|
@ -916,7 +912,7 @@ impl CrateInfo {
|
|||
});
|
||||
}
|
||||
|
||||
let embed_visualizers = tcx.sess.crate_types().iter().any(|&crate_type| match crate_type {
|
||||
let embed_visualizers = tcx.crate_types().iter().any(|&crate_type| match crate_type {
|
||||
CrateType::Executable | CrateType::Dylib | CrateType::Cdylib => {
|
||||
// These are crate types for which we invoke the linker and can embed
|
||||
// NatVis visualizers.
|
||||
|
@ -1013,7 +1009,7 @@ fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) -> CguR
|
|||
match compute_per_cgu_lto_type(
|
||||
&tcx.sess.lto(),
|
||||
&tcx.sess.opts,
|
||||
&tcx.sess.crate_types(),
|
||||
tcx.crate_types(),
|
||||
ModuleKind::Regular,
|
||||
) {
|
||||
ComputedLtoType::No => CguReuse::PostLto,
|
||||
|
|
|
@ -150,6 +150,7 @@ impl From<&cstore::NativeLib> for NativeLib {
|
|||
#[derive(Debug, Encodable, Decodable)]
|
||||
pub struct CrateInfo {
|
||||
pub target_cpu: String,
|
||||
pub crate_types: Vec<CrateType>,
|
||||
pub exported_symbols: FxHashMap<CrateType, Vec<String>>,
|
||||
pub linked_symbols: FxHashMap<CrateType, Vec<(String, SymbolExportKind)>>,
|
||||
pub local_crate_name: Symbol,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue