Rollup merge of #121764 - Zoxc:incr-sess-no-source, r=oli-obk
Make incremental sessions identity no longer depend on the crate names provided by source code This makes incremental sessions identity no longer depend on the crate names provided by source code, implementing https://github.com/rust-lang/compiler-team/issues/726. r? ````@oli-obk````
This commit is contained in:
commit
4dff106433
10 changed files with 101 additions and 99 deletions
|
@ -1,7 +1,5 @@
|
|||
use rustc_macros::Diagnostic;
|
||||
use rustc_session::config::CrateType;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_target::spec::TargetTriple;
|
||||
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
@ -90,13 +88,6 @@ pub struct FailedWritingFile<'a> {
|
|||
#[diag(interface_proc_macro_crate_panic_abort)]
|
||||
pub struct ProcMacroCratePanicAbort;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(interface_unsupported_crate_type_for_target)]
|
||||
pub struct UnsupportedCrateTypeForTarget<'a> {
|
||||
pub crate_type: CrateType,
|
||||
pub target_triple: &'a TargetTriple,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(interface_multiple_output_types_adaption)]
|
||||
pub struct MultipleOutputTypesAdaption;
|
||||
|
|
|
@ -18,7 +18,7 @@ use rustc_middle::ty::{GlobalCtxt, TyCtxt};
|
|||
use rustc_serialize::opaque::FileEncodeResult;
|
||||
use rustc_session::config::{self, CrateType, OutputFilenames, OutputType};
|
||||
use rustc_session::cstore::Untracked;
|
||||
use rustc_session::output::find_crate_name;
|
||||
use rustc_session::output::{collect_crate_types, find_crate_name};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::sym;
|
||||
use std::any::Any;
|
||||
|
@ -128,7 +128,7 @@ impl<'tcx> Queries<'tcx> {
|
|||
|
||||
// parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches.
|
||||
let crate_name = find_crate_name(sess, &pre_configured_attrs);
|
||||
let crate_types = util::collect_crate_types(sess, &pre_configured_attrs);
|
||||
let crate_types = collect_crate_types(sess, &pre_configured_attrs);
|
||||
let stable_crate_id = StableCrateId::new(
|
||||
crate_name,
|
||||
crate_types.contains(&CrateType::Executable),
|
||||
|
@ -136,7 +136,7 @@ impl<'tcx> Queries<'tcx> {
|
|||
sess.cfg_version,
|
||||
);
|
||||
let outputs = util::build_output_filenames(&pre_configured_attrs, sess);
|
||||
let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id)?;
|
||||
let dep_graph = setup_dep_graph(sess)?;
|
||||
|
||||
let cstore = FreezeLock::new(Box::new(CStore::new(
|
||||
self.compiler.codegen_backend.metadata_loader(),
|
||||
|
|
|
@ -7,14 +7,15 @@ use rustc_data_structures::sync;
|
|||
use rustc_metadata::{load_symbol_from_dylib, DylibError};
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session as session;
|
||||
use rustc_session::config::{self, Cfg, CrateType, OutFileName, OutputFilenames, OutputTypes};
|
||||
use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes};
|
||||
use rustc_session::filesearch::sysroot_candidates;
|
||||
use rustc_session::lint::{self, BuiltinLintDiag, LintBuffer};
|
||||
use rustc_session::{filesearch, output, Session};
|
||||
use rustc_session::{filesearch, Session};
|
||||
use rustc_span::edit_distance::find_best_match_for_name;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_target::spec::Target;
|
||||
use session::output::{categorize_crate_type, CRATE_TYPES};
|
||||
use session::EarlyDiagCtxt;
|
||||
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -399,67 +400,6 @@ pub(crate) fn check_attr_crate_type(
|
|||
}
|
||||
}
|
||||
|
||||
const CRATE_TYPES: &[(Symbol, CrateType)] = &[
|
||||
(sym::rlib, CrateType::Rlib),
|
||||
(sym::dylib, CrateType::Dylib),
|
||||
(sym::cdylib, CrateType::Cdylib),
|
||||
(sym::lib, config::default_lib_output()),
|
||||
(sym::staticlib, CrateType::Staticlib),
|
||||
(sym::proc_dash_macro, CrateType::ProcMacro),
|
||||
(sym::bin, CrateType::Executable),
|
||||
];
|
||||
|
||||
fn categorize_crate_type(s: Symbol) -> Option<CrateType> {
|
||||
Some(CRATE_TYPES.iter().find(|(key, _)| *key == s)?.1)
|
||||
}
|
||||
|
||||
pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<CrateType> {
|
||||
// If we're generating a test executable, then ignore all other output
|
||||
// styles at all other locations
|
||||
if session.opts.test {
|
||||
return vec![CrateType::Executable];
|
||||
}
|
||||
|
||||
// Only check command line flags if present. If no types are specified by
|
||||
// command line, then reuse the empty `base` Vec to hold the types that
|
||||
// will be found in crate attributes.
|
||||
// JUSTIFICATION: before wrapper fn is available
|
||||
#[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));
|
||||
} else {
|
||||
base.sort();
|
||||
base.dedup();
|
||||
}
|
||||
}
|
||||
|
||||
base.retain(|crate_type| {
|
||||
if output::invalid_output_for_target(session, *crate_type) {
|
||||
session.dcx().emit_warn(errors::UnsupportedCrateTypeForTarget {
|
||||
crate_type: *crate_type,
|
||||
target_triple: &session.opts.target_triple,
|
||||
});
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
|
||||
base
|
||||
}
|
||||
|
||||
fn multiple_output_types_to_stdout(
|
||||
output_types: &OutputTypes,
|
||||
single_output_file_is_stdout: bool,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue