summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_interface/src/util.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_interface/src/util.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_interface/src/util.rs')
-rw-r--r--compiler/rustc_interface/src/util.rs112
1 files changed, 10 insertions, 102 deletions
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs
index 0634e44c5..22d127934 100644
--- a/compiler/rustc_interface/src/util.rs
+++ b/compiler/rustc_interface/src/util.rs
@@ -3,24 +3,18 @@ use info;
use libloading::Library;
use rustc_ast as ast;
use rustc_codegen_ssa::traits::CodegenBackend;
-use rustc_data_structures::fx::{FxHashMap, FxHashSet};
#[cfg(parallel_compiler)]
use rustc_data_structures::sync;
-use rustc_errors::registry::Registry;
use rustc_parse::validate_attr;
use rustc_session as session;
-use rustc_session::config::CheckCfg;
-use rustc_session::config::{self, CrateType};
-use rustc_session::config::{OutFileName, OutputFilenames, OutputTypes};
+use rustc_session::config::{self, Cfg, CrateType, OutFileName, OutputFilenames, OutputTypes};
use rustc_session::filesearch::sysroot_candidates;
use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer};
-use rustc_session::parse::CrateConfig;
use rustc_session::{filesearch, output, Session};
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::edition::Edition;
-use rustc_span::source_map::FileLoader;
use rustc_span::symbol::{sym, Symbol};
-use session::{CompilerIO, EarlyErrorHandler};
+use session::EarlyErrorHandler;
use std::env;
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
use std::mem;
@@ -37,11 +31,7 @@ pub type MakeBackendFn = fn() -> Box<dyn CodegenBackend>;
///
/// This is performed by checking whether a set of permitted features
/// is available on the target machine, by querying the codegen backend.
-pub fn add_configuration(
- cfg: &mut CrateConfig,
- sess: &mut Session,
- codegen_backend: &dyn CodegenBackend,
-) {
+pub fn add_configuration(cfg: &mut Cfg, sess: &mut Session, codegen_backend: &dyn CodegenBackend) {
let tf = sym::target_feature;
let unstable_target_features = codegen_backend.target_features(sess, true);
@@ -57,80 +47,6 @@ pub fn add_configuration(
}
}
-pub fn create_session(
- handler: &EarlyErrorHandler,
- sopts: config::Options,
- cfg: FxHashSet<(String, Option<String>)>,
- check_cfg: CheckCfg,
- locale_resources: &'static [&'static str],
- file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
- io: CompilerIO,
- lint_caps: FxHashMap<lint::LintId, lint::Level>,
- make_codegen_backend: Option<
- Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
- >,
- descriptions: Registry,
- ice_file: Option<PathBuf>,
- expanded_args: Vec<String>,
-) -> (Session, Box<dyn CodegenBackend>) {
- let codegen_backend = if let Some(make_codegen_backend) = make_codegen_backend {
- make_codegen_backend(&sopts)
- } else {
- get_codegen_backend(
- handler,
- &sopts.maybe_sysroot,
- sopts.unstable_opts.codegen_backend.as_deref(),
- )
- };
-
- // target_override is documented to be called before init(), so this is okay
- let target_override = codegen_backend.target_override(&sopts);
-
- let bundle = match rustc_errors::fluent_bundle(
- sopts.maybe_sysroot.clone(),
- sysroot_candidates().to_vec(),
- sopts.unstable_opts.translate_lang.clone(),
- sopts.unstable_opts.translate_additional_ftl.as_deref(),
- sopts.unstable_opts.translate_directionality_markers,
- ) {
- Ok(bundle) => bundle,
- Err(e) => {
- handler.early_error(format!("failed to load fluent bundle: {e}"));
- }
- };
-
- let mut locale_resources = Vec::from(locale_resources);
- locale_resources.push(codegen_backend.locale_resource());
-
- let mut sess = session::build_session(
- handler,
- sopts,
- io,
- bundle,
- descriptions,
- locale_resources,
- lint_caps,
- file_loader,
- target_override,
- rustc_version_str().unwrap_or("unknown"),
- ice_file,
- expanded_args,
- );
-
- codegen_backend.init(&sess);
-
- let mut cfg = config::build_configuration(&sess, config::to_crate_config(cfg));
- add_configuration(&mut cfg, &mut sess, &*codegen_backend);
-
- let mut check_cfg = config::to_crate_check_config(check_cfg);
- check_cfg.fill_well_known(&sess.target);
-
- sess.parse_sess.config = cfg;
- sess.parse_sess.check_config = check_cfg;
-
- (sess, codegen_backend)
-}
-
const STACK_SIZE: usize = 8 * 1024 * 1024;
fn get_stack_size() -> Option<usize> {
@@ -485,21 +401,6 @@ fn categorize_crate_type(s: Symbol) -> Option<CrateType> {
}
pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<CrateType> {
- // Unconditionally collect crate types from attributes to make them used
- let attr_types: Vec<CrateType> = attrs
- .iter()
- .filter_map(|a| {
- if a.has_name(sym::crate_type) {
- match a.value_str() {
- Some(s) => categorize_crate_type(s),
- _ => None,
- }
- } else {
- None
- }
- })
- .collect();
-
// If we're generating a test executable, then ignore all other output
// styles at all other locations
if session.opts.test {
@@ -513,6 +414,13 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<C
#[allow(rustc::bad_opt_access)]
let mut base = session.opts.crate_types.clone();
if base.is_empty() {
+ let attr_types = attrs.iter().filter_map(|a| {
+ if a.has_name(sym::crate_type) && let Some(s) = a.value_str() {
+ categorize_crate_type(s)
+ } else {
+ None
+ }
+ });
base.extend(attr_types);
if base.is_empty() {
base.push(output::default_output_for_target(session));