Skip to content

Commit 1d726a2

Browse files
committed
Auto merge of #118472 - nnethercote:rustc_session, r=bjorn3
`rustc_session` cleanups r? `@bjorn3`
2 parents f45631b + 275b793 commit 1d726a2

File tree

16 files changed

+87
-118
lines changed

16 files changed

+87
-118
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use object::{
1212

1313
use rustc_data_structures::memmap::Mmap;
1414
use rustc_data_structures::owned_slice::{try_slice_owned, OwnedSlice};
15+
use rustc_metadata::creader::MetadataLoader;
1516
use rustc_metadata::fs::METADATA_FILENAME;
1617
use rustc_metadata::EncodedMetadata;
17-
use rustc_session::cstore::MetadataLoader;
1818
use rustc_session::Session;
1919
use rustc_span::sym;
2020
use rustc_target::abi::Endian;

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use rustc_ast::expand::allocator::AllocatorKind;
99
use rustc_data_structures::fx::FxIndexMap;
1010
use rustc_data_structures::sync::{DynSend, DynSync};
1111
use rustc_errors::ErrorGuaranteed;
12+
use rustc_metadata::creader::MetadataLoaderDyn;
1213
use rustc_metadata::EncodedMetadata;
1314
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
1415
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf, TyAndLayout};
1516
use rustc_middle::ty::{Ty, TyCtxt};
1617
use rustc_middle::util::Providers;
1718
use rustc_session::{
1819
config::{self, OutputFilenames, PrintRequest},
19-
cstore::MetadataLoaderDyn,
2020
Session,
2121
};
2222
use rustc_span::symbol::Symbol;

compiler/rustc_driver_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ use rustc_feature::find_gated_cfg;
3333
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
3434
use rustc_interface::{interface, Queries};
3535
use rustc_lint::unerased_lint_store;
36+
use rustc_metadata::creader::MetadataLoader;
3637
use rustc_metadata::locator;
3738
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
3839
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
39-
use rustc_session::cstore::MetadataLoader;
4040
use rustc_session::getopts::{self, Matches};
4141
use rustc_session::lint::{Lint, LintId};
4242
use rustc_session::{config, EarlyErrorHandler, Session};

compiler/rustc_incremental/src/persist/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub(crate) fn prepare_session_directory(
262262
directory."
263263
);
264264

265-
sess.init_incr_comp_session(session_dir, directory_lock, false);
265+
sess.init_incr_comp_session(session_dir, directory_lock);
266266
return Ok(());
267267
};
268268

@@ -276,7 +276,7 @@ pub(crate) fn prepare_session_directory(
276276
sess.emit_warning(errors::HardLinkFailed { path: &session_dir });
277277
}
278278

279-
sess.init_incr_comp_session(session_dir, directory_lock, true);
279+
sess.init_incr_comp_session(session_dir, directory_lock);
280280
return Ok(());
281281
} else {
282282
debug!("copying failed - trying next directory");

compiler/rustc_metadata/src/creader.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,24 @@ use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob
77
use rustc_ast::expand::allocator::{alloc_error_handler_name, global_fn_name, AllocatorKind};
88
use rustc_ast::{self as ast, *};
99
use rustc_data_structures::fx::FxHashSet;
10+
use rustc_data_structures::owned_slice::OwnedSlice;
1011
use rustc_data_structures::svh::Svh;
11-
use rustc_data_structures::sync::{FreezeReadGuard, FreezeWriteGuard};
12+
use rustc_data_structures::sync::{self, FreezeReadGuard, FreezeWriteGuard};
1213
use rustc_expand::base::SyntaxExtension;
1314
use rustc_fs_util::try_canonicalize;
1415
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE};
1516
use rustc_hir::definitions::Definitions;
1617
use rustc_index::IndexVec;
1718
use rustc_middle::ty::TyCtxt;
1819
use rustc_session::config::{self, CrateType, ExternLocation};
19-
use rustc_session::cstore::{
20-
CrateDepKind, CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn,
21-
};
20+
use rustc_session::cstore::{CrateDepKind, CrateSource, ExternCrate, ExternCrateSource};
2221
use rustc_session::lint;
2322
use rustc_session::output::validate_crate_name;
2423
use rustc_session::search_paths::PathKind;
2524
use rustc_span::edition::Edition;
2625
use rustc_span::symbol::{sym, Symbol};
2726
use rustc_span::{Span, DUMMY_SP};
28-
use rustc_target::spec::{PanicStrategy, TargetTriple};
27+
use rustc_target::spec::{PanicStrategy, Target, TargetTriple};
2928

3029
use proc_macro::bridge::client::ProcMacro;
3130
use std::error::Error;
@@ -34,6 +33,17 @@ use std::path::Path;
3433
use std::time::Duration;
3534
use std::{cmp, iter};
3635

36+
/// The backend's way to give the crate store access to the metadata in a library.
37+
/// Note that it returns the raw metadata bytes stored in the library file, whether
38+
/// it is compressed, uncompressed, some weird mix, etc.
39+
/// rmeta files are backend independent and not handled here.
40+
pub trait MetadataLoader {
41+
fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
42+
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
43+
}
44+
45+
pub type MetadataLoaderDyn = dyn MetadataLoader + Send + Sync + sync::DynSend + sync::DynSync;
46+
3747
pub struct CStore {
3848
metadata_loader: Box<MetadataLoaderDyn>,
3949

compiler/rustc_metadata/src/locator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
//! no means all of the necessary details. Take a look at the rest of
213213
//! metadata::locator or metadata::creader for all the juicy details!
214214
215-
use crate::creader::Library;
215+
use crate::creader::{Library, MetadataLoader};
216216
use crate::errors;
217217
use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER};
218218

@@ -223,7 +223,7 @@ use rustc_data_structures::svh::Svh;
223223
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
224224
use rustc_fs_util::try_canonicalize;
225225
use rustc_session::config;
226-
use rustc_session::cstore::{CrateSource, MetadataLoader};
226+
use rustc_session::cstore::CrateSource;
227227
use rustc_session::filesearch::FileSearch;
228228
use rustc_session::search_paths::PathKind;
229229
use rustc_session::utils::CanonicalizedPath;

compiler/rustc_session/src/config.rs

+52-46
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@ use crate::search_paths::SearchPath;
88
use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
99
use crate::{lint, HashStableContext};
1010
use crate::{EarlyErrorHandler, Session};
11-
1211
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
1312
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
14-
use rustc_target::abi::Align;
15-
use rustc_target::spec::LinkSelfContainedComponents;
16-
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, SplitDebuginfo};
17-
use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS};
18-
13+
use rustc_errors::emitter::HumanReadableErrorType;
14+
use rustc_errors::{ColorConfig, DiagnosticArgValue, HandlerFlags, IntoDiagnosticArg};
1915
use rustc_feature::UnstableFeatures;
2016
use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION};
2117
use rustc_span::source_map::FilePathMapping;
2218
use rustc_span::symbol::{sym, Symbol};
2319
use rustc_span::{FileName, FileNameDisplayPreference, RealFileName, SourceFileHashAlgorithm};
24-
25-
use rustc_errors::emitter::HumanReadableErrorType;
26-
use rustc_errors::{ColorConfig, DiagnosticArgValue, HandlerFlags, IntoDiagnosticArg};
27-
20+
use rustc_target::abi::Align;
21+
use rustc_target::spec::LinkSelfContainedComponents;
22+
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, SplitDebuginfo};
23+
use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS};
2824
use std::collections::btree_map::{
2925
Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter,
3026
};
@@ -1250,7 +1246,7 @@ fn default_configuration(sess: &Session) -> Cfg {
12501246
// NOTE: This should be kept in sync with `CheckCfg::fill_well_known` below.
12511247
let end = &sess.target.endian;
12521248
let arch = &sess.target.arch;
1253-
let wordsz = sess.target.pointer_width.to_string();
1249+
let wordsz = sess.target.pointer_width as u64;
12541250
let os = &sess.target.os;
12551251
let env = &sess.target.env;
12561252
let abi = &sess.target.abi;
@@ -1277,7 +1273,7 @@ fn default_configuration(sess: &Session) -> Cfg {
12771273
}
12781274
ret.insert((sym::target_arch, Some(Symbol::intern(arch))));
12791275
ret.insert((sym::target_endian, Some(Symbol::intern(end.as_str()))));
1280-
ret.insert((sym::target_pointer_width, Some(Symbol::intern(&wordsz))));
1276+
ret.insert((sym::target_pointer_width, Some(sym::integer(wordsz))));
12811277
ret.insert((sym::target_env, Some(Symbol::intern(env))));
12821278
ret.insert((sym::target_abi, Some(Symbol::intern(abi))));
12831279
if sess.is_nightly_build() {
@@ -1297,19 +1293,18 @@ fn default_configuration(sess: &Session) -> Cfg {
12971293
] {
12981294
if i >= min_atomic_width && i <= max_atomic_width {
12991295
has_atomic = true;
1300-
let mut insert_atomic = |s, align: Align| {
1301-
ret.insert((sym::target_has_atomic_load_store, Some(Symbol::intern(s))));
1296+
let mut insert_atomic = |sym, align: Align| {
1297+
ret.insert((sym::target_has_atomic_load_store, Some(sym)));
13021298
if atomic_cas {
1303-
ret.insert((sym::target_has_atomic, Some(Symbol::intern(s))));
1299+
ret.insert((sym::target_has_atomic, Some(sym)));
13041300
}
13051301
if align.bits() == i {
1306-
ret.insert((sym::target_has_atomic_equal_alignment, Some(Symbol::intern(s))));
1302+
ret.insert((sym::target_has_atomic_equal_alignment, Some(sym)));
13071303
}
13081304
};
1309-
let s = i.to_string();
1310-
insert_atomic(&s, align);
1311-
if s == wordsz {
1312-
insert_atomic("ptr", layout.pointer_align.abi);
1305+
insert_atomic(sym::integer(i), align);
1306+
if wordsz == i {
1307+
insert_atomic(sym::ptr, layout.pointer_align.abi);
13131308
}
13141309
}
13151310
}
@@ -2150,25 +2145,27 @@ fn collect_print_requests(
21502145
}
21512146

21522147
const PRINT_KINDS: &[(&str, PrintKind)] = &[
2148+
// tidy-alphabetical-start
2149+
("all-target-specs-json", PrintKind::AllTargetSpecs),
2150+
("calling-conventions", PrintKind::CallingConventions),
2151+
("cfg", PrintKind::Cfg),
2152+
("code-models", PrintKind::CodeModels),
21532153
("crate-name", PrintKind::CrateName),
2154+
("deployment-target", PrintKind::DeploymentTarget),
21542155
("file-names", PrintKind::FileNames),
2156+
("link-args", PrintKind::LinkArgs),
2157+
("native-static-libs", PrintKind::NativeStaticLibs),
2158+
("relocation-models", PrintKind::RelocationModels),
2159+
("split-debuginfo", PrintKind::SplitDebuginfo),
2160+
("stack-protector-strategies", PrintKind::StackProtectorStrategies),
21552161
("sysroot", PrintKind::Sysroot),
2156-
("target-libdir", PrintKind::TargetLibdir),
2157-
("cfg", PrintKind::Cfg),
2158-
("calling-conventions", PrintKind::CallingConventions),
2159-
("target-list", PrintKind::TargetList),
21602162
("target-cpus", PrintKind::TargetCPUs),
21612163
("target-features", PrintKind::TargetFeatures),
2162-
("relocation-models", PrintKind::RelocationModels),
2163-
("code-models", PrintKind::CodeModels),
2164-
("tls-models", PrintKind::TlsModels),
2165-
("native-static-libs", PrintKind::NativeStaticLibs),
2166-
("stack-protector-strategies", PrintKind::StackProtectorStrategies),
2164+
("target-libdir", PrintKind::TargetLibdir),
2165+
("target-list", PrintKind::TargetList),
21672166
("target-spec-json", PrintKind::TargetSpec),
2168-
("all-target-specs-json", PrintKind::AllTargetSpecs),
2169-
("link-args", PrintKind::LinkArgs),
2170-
("split-debuginfo", PrintKind::SplitDebuginfo),
2171-
("deployment-target", PrintKind::DeploymentTarget),
2167+
("tls-models", PrintKind::TlsModels),
2168+
// tidy-alphabetical-end
21722169
];
21732170

21742171
// We disallow reusing the same path in multiple prints, such as `--print
@@ -2297,14 +2294,7 @@ fn select_debuginfo(matches: &getopts::Matches, cg: &CodegenOptions) -> DebugInf
22972294
if max_g > max_c { DebugInfo::Full } else { cg.debuginfo }
22982295
}
22992296

2300-
fn select_debuginfo_compression(
2301-
_handler: &EarlyErrorHandler,
2302-
unstable_opts: &UnstableOptions,
2303-
) -> DebugInfoCompression {
2304-
unstable_opts.debuginfo_compression
2305-
}
2306-
2307-
pub(crate) fn parse_assert_incr_state(
2297+
fn parse_assert_incr_state(
23082298
handler: &EarlyErrorHandler,
23092299
opt_assertion: &Option<String>,
23102300
) -> Option<IncrementalStateAssertion> {
@@ -2460,6 +2450,17 @@ pub fn parse_externs(
24602450
matches: &getopts::Matches,
24612451
unstable_opts: &UnstableOptions,
24622452
) -> Externs {
2453+
fn is_ascii_ident(string: &str) -> bool {
2454+
let mut chars = string.chars();
2455+
if let Some(start) = chars.next()
2456+
&& (start.is_ascii_alphabetic() || start == '_')
2457+
{
2458+
chars.all(|char| char.is_ascii_alphanumeric() || char == '_')
2459+
} else {
2460+
false
2461+
}
2462+
}
2463+
24632464
let is_unstable_enabled = unstable_opts.unstable_options;
24642465
let mut externs: BTreeMap<String, ExternEntry> = BTreeMap::new();
24652466
for arg in matches.opt_strs("extern") {
@@ -2472,12 +2473,12 @@ pub fn parse_externs(
24722473
Some((opts, name)) => (Some(opts), name.to_string()),
24732474
};
24742475

2475-
if !crate::utils::is_ascii_ident(&name) {
2476+
if !is_ascii_ident(&name) {
24762477
let mut error = handler.early_struct_error(format!(
24772478
"crate name `{name}` passed to `--extern` is not a valid ASCII identifier"
24782479
));
24792480
let adjusted_name = name.replace('-', "_");
2480-
if crate::utils::is_ascii_ident(&adjusted_name) {
2481+
if is_ascii_ident(&adjusted_name) {
24812482
error.help(format!(
24822483
"consider replacing the dashes with underscores: `{adjusted_name}`"
24832484
));
@@ -2791,8 +2792,7 @@ pub fn build_session_options(
27912792
// for more details.
27922793
let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No);
27932794
let debuginfo = select_debuginfo(matches, &cg);
2794-
let debuginfo_compression: DebugInfoCompression =
2795-
select_debuginfo_compression(handler, &unstable_opts);
2795+
let debuginfo_compression = unstable_opts.debuginfo_compression;
27962796

27972797
let mut search_paths = vec![];
27982798
for s in &matches.opt_strs("L") {
@@ -3143,6 +3143,12 @@ impl PpMode {
31433143
}
31443144
}
31453145

3146+
#[derive(Clone, Hash, PartialEq, Eq, Debug)]
3147+
pub enum WasiExecModel {
3148+
Command,
3149+
Reactor,
3150+
}
3151+
31463152
/// Command-line arguments passed to the compiler have to be incorporated with
31473153
/// the dependency tracking system for incremental compilation. This module
31483154
/// provides some utilities to make this more convenient.
@@ -3168,9 +3174,9 @@ pub(crate) mod dep_tracking {
31683174
LinkerPluginLto, LocationDetail, LtoCli, OomStrategy, OptLevel, OutFileName, OutputType,
31693175
OutputTypes, Polonius, RemapPathScopeComponents, ResolveDocLinks, SourceFileHashAlgorithm,
31703176
SplitDwarfKind, SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
3177+
WasiExecModel,
31713178
};
31723179
use crate::lint;
3173-
use crate::options::WasiExecModel;
31743180
use crate::utils::NativeLib;
31753181
use rustc_data_structures::stable_hasher::Hash64;
31763182
use rustc_errors::LanguageIdentifier;

compiler/rustc_session/src/cstore.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ use crate::search_paths::PathKind;
66
use crate::utils::NativeLibKind;
77
use crate::Session;
88
use rustc_ast as ast;
9-
use rustc_data_structures::owned_slice::OwnedSlice;
109
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
1110
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, StableCrateId, LOCAL_CRATE};
1211
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash, Definitions};
1312
use rustc_span::hygiene::{ExpnHash, ExpnId};
1413
use rustc_span::symbol::Symbol;
1514
use rustc_span::Span;
1615
use rustc_target::spec::abi::Abi;
17-
use rustc_target::spec::Target;
1816

1917
use std::any::Any;
20-
use std::path::{Path, PathBuf};
18+
use std::path::PathBuf;
2119

2220
// lonely orphan structs and enums looking for a better home
2321

@@ -197,21 +195,6 @@ pub enum ExternCrateSource {
197195
Path,
198196
}
199197

200-
/// The backend's way to give the crate store access to the metadata in a library.
201-
/// Note that it returns the raw metadata bytes stored in the library file, whether
202-
/// it is compressed, uncompressed, some weird mix, etc.
203-
/// rmeta files are backend independent and not handled here.
204-
///
205-
/// At the time of this writing, there is only one backend and one way to store
206-
/// metadata in library -- this trait just serves to decouple rustc_metadata from
207-
/// the archive reader, which depends on LLVM.
208-
pub trait MetadataLoader: std::fmt::Debug {
209-
fn get_rlib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
210-
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<OwnedSlice, String>;
211-
}
212-
213-
pub type MetadataLoaderDyn = dyn MetadataLoader + Send + Sync + sync::DynSend + sync::DynSync;
214-
215198
/// A store of Rust crates, through which their metadata can be accessed.
216199
///
217200
/// Note that this trait should probably not be expanding today. All new

compiler/rustc_session/src/filesearch.rs

-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ use std::path::{Path, PathBuf};
99
use crate::search_paths::{PathKind, SearchPath};
1010
use rustc_fs_util::fix_windows_verbatim_for_gcc;
1111

12-
#[derive(Copy, Clone)]
13-
pub enum FileMatch {
14-
FileMatches,
15-
FileDoesntMatch,
16-
}
17-
1812
#[derive(Clone)]
1913
pub struct FileSearch<'a> {
2014
sysroot: &'a Path,

compiler/rustc_session/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#![feature(if_let_guard)]
21
#![feature(let_chains)]
3-
#![feature(min_specialization)]
42
#![feature(never_type)]
53
#![feature(lazy_cell)]
64
#![feature(option_get_or_insert_default)]

compiler/rustc_session/src/options.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1985,9 +1985,3 @@ written to standard error output)"),
19851985
// - compiler/rustc_interface/src/tests.rs
19861986
// - src/doc/unstable-book/src/compiler-flags
19871987
}
1988-
1989-
#[derive(Clone, Hash, PartialEq, Eq, Debug)]
1990-
pub enum WasiExecModel {
1991-
Command,
1992-
Reactor,
1993-
}

compiler/rustc_session/src/output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Related to out filenames of compilation (e.g. save analysis, binaries).
1+
//! Related to out filenames of compilation (e.g. binaries).
22
use crate::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
33
use crate::errors::{
44
CrateNameDoesNotMatch, CrateNameEmpty, CrateNameInvalid, FileIsNotWriteable,

0 commit comments

Comments
 (0)