Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #117228

Merged
merged 29 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e68edb8
refactor(compiler/resolve): simplify some code
Fenex Oct 18, 2023
855444e
mv tests
estebank Oct 24, 2023
2dec1bc
Avoid unbounded O(n^2) when parsing nested type args
estebank Oct 24, 2023
e4c41b0
Add arg_count field to Body in Stable MIR
klinvill Oct 23, 2023
93d1b3e
Replace arg_count in public API with return/arg getters
klinvill Oct 25, 2023
f4d80a5
Add public API to retrieve internal locals
klinvill Oct 25, 2023
372c533
Make locals field private
klinvill Oct 25, 2023
39b293f
Add a public API to get all body locals
klinvill Oct 25, 2023
72e8690
Remove unused `never_type` feature.
nnethercote Oct 24, 2023
ca29c27
Reduce exposure of three functions used only within `rustc_incremental`.
nnethercote Oct 24, 2023
8da1b33
Move a `use` to a more sensible spot.
nnethercote Oct 24, 2023
3cf2a74
Tiny comment fixes.
nnethercote Oct 25, 2023
e0c990e
Reduce some function exposure.
nnethercote Oct 25, 2023
fe4dfb8
Rename internal_locals to inner_locals
klinvill Oct 25, 2023
4b23bd4
Update Place and Operand to take slices
klinvill Oct 25, 2023
bac7d5b
Add test for smir locals
klinvill Oct 25, 2023
9f5fc02
The value of `-Cinstrument-coverage=` doesn't need to be `Option`
Zalathar Oct 25, 2023
ab7f64c
Revert "Remove TaKO8Ki from reviewers"
TaKO8Ki Oct 26, 2023
d55487d
Use two slice expressions to save on an offset repetition
oli-obk Oct 26, 2023
d572729
Quietly fail if an error has already occurred
oli-obk Oct 26, 2023
b1b1458
Replace type flag HAS_TY_GENERATOR with HAS_TY_COROUTINE
fmease Oct 26, 2023
17fb2f4
Rollup merge of #116905 - Fenex:refactor/compiler/resolve, r=petroche…
matthiaskrgr Oct 26, 2023
b66c6e7
Rollup merge of #117095 - klinvill:smir-fn-arg-count, r=oli-obk
matthiaskrgr Oct 26, 2023
7eb0548
Rollup merge of #117143 - estebank:issue-117080, r=wesleywiser
matthiaskrgr Oct 26, 2023
577026c
Rollup merge of #117194 - nnethercote:rustc_incremental, r=cjgillot
matthiaskrgr Oct 26, 2023
36b794e
Rollup merge of #117202 - TaKO8Ki:revert-remove-TaKO8Ki-from-reviewer…
matthiaskrgr Oct 26, 2023
24bdc37
Rollup merge of #117207 - Zalathar:no-option, r=compiler-errors
matthiaskrgr Oct 26, 2023
70a4678
Rollup merge of #117214 - oli-obk:error_shenanigans, r=compiler-errors
matthiaskrgr Oct 26, 2023
a461de7
Rollup merge of #117221 - fmease:TypeFlags-HAS_TY_GENERATOR-to-COROUT…
matthiaskrgr Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt;
use rustc_middle::mir::ConstraintCategory;
use rustc_middle::traits::query::OutlivesBound;
use rustc_middle::ty::{self, RegionVid, Ty};
use rustc_span::{Span, DUMMY_SP};
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
use std::rc::Rc;
use type_op::TypeOpOutput;
Expand Down Expand Up @@ -318,7 +318,8 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
.param_env
.and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })
.fully_perform(self.infcx, DUMMY_SP)
.unwrap_or_else(|_| bug!("failed to compute implied bounds {:?}", ty));
.map_err(|_: ErrorGuaranteed| debug!("failed to compute implied bounds {:?}", ty))
.ok()?;
debug!(?bounds, ?constraints);
self.add_outlives_bounds(bounds);
constraints
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_incremental/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(never_type)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
Expand All @@ -19,15 +18,11 @@ mod assert_dep_graph;
mod errors;
mod persist;

use assert_dep_graph::assert_dep_graph;
pub use persist::copy_cgu_workproduct_to_incr_comp_cache_dir;
pub use persist::delete_workproduct_files;
pub use persist::finalize_session_directory;
pub use persist::garbage_collect_session_directories;
pub use persist::in_incr_comp_dir;
pub use persist::in_incr_comp_dir_sess;
pub use persist::load_query_result_cache;
pub use persist::prepare_session_directory;
pub use persist::save_dep_graph;
pub use persist::save_work_product_index;
pub use persist::setup_dep_graph;
Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_incremental/src/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
//! ## Synchronization
//!
//! There is some synchronization needed in order for the compiler to be able to
//! determine whether a given private session directory is not in used any more.
//! determine whether a given private session directory is not in use any more.
//! This is done by creating a lock file for each session directory and
//! locking it while the directory is still being used. Since file locks have
//! operating system support, we can rely on the lock being released if the
Expand Down Expand Up @@ -136,26 +136,29 @@ const QUERY_CACHE_FILENAME: &str = "query-cache.bin";
const INT_ENCODE_BASE: usize = base_n::CASE_INSENSITIVE;

/// Returns the path to a session's dependency graph.
pub fn dep_graph_path(sess: &Session) -> PathBuf {
pub(crate) fn dep_graph_path(sess: &Session) -> PathBuf {
in_incr_comp_dir_sess(sess, DEP_GRAPH_FILENAME)
}

/// Returns the path to a session's staging dependency graph.
///
/// On the difference between dep-graph and staging dep-graph,
/// see `build_dep_graph`.
pub fn staging_dep_graph_path(sess: &Session) -> PathBuf {
pub(crate) fn staging_dep_graph_path(sess: &Session) -> PathBuf {
in_incr_comp_dir_sess(sess, STAGING_DEP_GRAPH_FILENAME)
}
pub fn work_products_path(sess: &Session) -> PathBuf {

pub(crate) fn work_products_path(sess: &Session) -> PathBuf {
in_incr_comp_dir_sess(sess, WORK_PRODUCTS_FILENAME)
}

/// Returns the path to a session's query cache.
pub fn query_cache_path(sess: &Session) -> PathBuf {
in_incr_comp_dir_sess(sess, QUERY_CACHE_FILENAME)
}

/// Locks a given session directory.
pub fn lock_file_path(session_dir: &Path) -> PathBuf {
fn lock_file_path(session_dir: &Path) -> PathBuf {
let crate_dir = session_dir.parent().unwrap();

let directory_name = session_dir.file_name().unwrap().to_string_lossy();
Expand Down Expand Up @@ -202,7 +205,7 @@ pub fn in_incr_comp_dir(incr_comp_session_dir: &Path, file_name: &str) -> PathBu
/// The garbage collection will take care of it.
///
/// [`rustc_interface::queries::dep_graph`]: ../../rustc_interface/struct.Queries.html#structfield.dep_graph
pub fn prepare_session_directory(
pub(crate) fn prepare_session_directory(
sess: &Session,
crate_name: Symbol,
stable_crate_id: StableCrateId,
Expand Down Expand Up @@ -373,7 +376,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
let _ = garbage_collect_session_directories(sess);
}

pub fn delete_all_session_dir_contents(sess: &Session) -> io::Result<()> {
pub(crate) fn delete_all_session_dir_contents(sess: &Session) -> io::Result<()> {
let sess_dir_iterator = sess.incr_comp_session_dir().read_dir()?;
for entry in sess_dir_iterator {
let entry = entry?;
Expand Down Expand Up @@ -621,7 +624,7 @@ fn is_old_enough_to_be_collected(timestamp: SystemTime) -> bool {
}

/// Runs garbage collection for the current session.
pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
pub(crate) fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
debug!("garbage_collect_session_directories() - begin");

let session_directory = sess.incr_comp_session_dir();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Code to save/load the dep-graph from files.
//! Code to load the dep-graph from files.

use crate::errors;
use rustc_data_structures::memmap::Mmap;
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_incremental/src/persist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ mod save;
mod work_product;

pub use fs::finalize_session_directory;
pub use fs::garbage_collect_session_directories;
pub use fs::in_incr_comp_dir;
pub use fs::in_incr_comp_dir_sess;
pub use fs::prepare_session_directory;
pub use load::load_query_result_cache;
pub use load::setup_dep_graph;
pub use load::LoadResult;
pub use save::save_dep_graph;
pub use save::save_work_product_index;
pub use work_product::copy_cgu_workproduct_to_incr_comp_cache_dir;
pub use work_product::delete_workproduct_files;
3 changes: 2 additions & 1 deletion compiler/rustc_incremental/src/persist/save.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::assert_dep_graph::assert_dep_graph;
use crate::errors;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::join;
Expand Down Expand Up @@ -39,7 +40,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
let dep_graph_path = dep_graph_path(sess);
let staging_dep_graph_path = staging_dep_graph_path(sess);

sess.time("assert_dep_graph", || crate::assert_dep_graph(tcx));
sess.time("assert_dep_graph", || assert_dep_graph(tcx));
sess.time("check_dirty_clean", || dirty_clean::check_dirty_clean_annotations(tcx));

if sess.opts.unstable_opts.incremental_info {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_incremental/src/persist/work_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use rustc_session::Session;
use std::fs as std_fs;
use std::path::Path;

/// Copies a CGU work product to the incremental compilation directory, so next compilation can find and reuse it.
/// Copies a CGU work product to the incremental compilation directory, so next compilation can
/// find and reuse it.
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
sess: &Session,
cgu_name: &str,
Expand Down Expand Up @@ -45,7 +46,7 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
}

/// Removes files for a given work product.
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
pub(crate) fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
for (_, path) in work_product.saved_files.items().into_sorted_stable_ord() {
let path = in_incr_comp_dir_sess(sess, path);
if let Err(err) = std_fs::remove_file(&path) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ fn test_codegen_options_tracking_hash() {
tracked!(force_frame_pointers, Some(false));
tracked!(force_unwind_tables, Some(true));
tracked!(inline_threshold, Some(0xf007ba11));
tracked!(instrument_coverage, Some(InstrumentCoverage::All));
tracked!(instrument_coverage, InstrumentCoverage::All);
tracked!(link_dead_code, Some(true));
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
tracked!(llvm_args, vec![String::from("1"), String::from("2")]);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl FlagComputation {
if should_remove_further_specializable {
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
}
self.add_flags(TypeFlags::HAS_TY_GENERATOR);
self.add_flags(TypeFlags::HAS_TY_COROUTINE);
}

&ty::Closure(_, args) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
self.has_type_flags(TypeFlags::HAS_TY_OPAQUE)
}
fn has_coroutines(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_GENERATOR)
self.has_type_flags(TypeFlags::HAS_TY_COROUTINE)
}
fn references_error(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_ERROR)
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ pub struct Parser<'a> {
/// appropriately.
///
/// See the comments in the `parse_path_segment` function for more details.
unmatched_angle_bracket_count: u32,
max_angle_bracket_count: u32,
unmatched_angle_bracket_count: u16,
max_angle_bracket_count: u16,
angle_bracket_nesting: u16,

last_unexpected_token_span: Option<Span>,
/// If present, this `Parser` is not parsing Rust code but rather a macro call.
Expand Down Expand Up @@ -394,6 +395,7 @@ impl<'a> Parser<'a> {
break_last_token: false,
unmatched_angle_bracket_count: 0,
max_angle_bracket_count: 0,
angle_bracket_nesting: 0,
last_unexpected_token_span: None,
subparser_name,
capture_state: CaptureState {
Expand Down
25 changes: 21 additions & 4 deletions compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,24 @@ impl<'a> Parser<'a> {
// Take a snapshot before attempting to parse - we can restore this later.
let snapshot = is_first_invocation.then(|| self.clone());

self.angle_bracket_nesting += 1;
debug!("parse_generic_args_with_leading_angle_bracket_recovery: (snapshotting)");
match self.parse_angle_args(ty_generics) {
Ok(args) => Ok(args),
Ok(args) => {
self.angle_bracket_nesting -= 1;
Ok(args)
}
Err(mut e) if self.angle_bracket_nesting > 10 => {
self.angle_bracket_nesting -= 1;
// When encountering severely malformed code where there are several levels of
// nested unclosed angle args (`f::<f::<f::<f::<...`), we avoid severe O(n^2)
// behavior by bailing out earlier (#117080).
e.emit();
rustc_errors::FatalError.raise();
}
Err(e) if is_first_invocation && self.unmatched_angle_bracket_count > 0 => {
self.angle_bracket_nesting -= 1;

// Swap `self` with our backup of the parser state before attempting to parse
// generic arguments.
let snapshot = mem::replace(self, snapshot.unwrap());
Expand Down Expand Up @@ -520,8 +534,8 @@ impl<'a> Parser<'a> {
// Make a span over ${unmatched angle bracket count} characters.
// This is safe because `all_angle_brackets` ensures that there are only `<`s,
// i.e. no multibyte characters, in this range.
let span =
lo.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count));
let span = lo
.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count.into()));
self.sess.emit_err(errors::UnmatchedAngle {
span,
plural: snapshot.unmatched_angle_bracket_count > 1,
Expand All @@ -531,7 +545,10 @@ impl<'a> Parser<'a> {
self.parse_angle_args(ty_generics)
}
}
Err(e) => Err(e),
Err(e) => {
self.angle_bracket_nesting -= 1;
Err(e)
}
}
}

Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl Resolver<'_, '_> {

for unused in visitor.unused_imports.values() {
let mut fixes = Vec::new();
let mut spans = match calc_unused_spans(unused, unused.use_tree, unused.use_tree_id) {
let spans = match calc_unused_spans(unused, unused.use_tree, unused.use_tree_id) {
UnusedSpanResult::Used => continue,
UnusedSpanResult::FlatUnused(span, remove) => {
fixes.push((remove, String::new()));
Expand All @@ -353,20 +353,19 @@ impl Resolver<'_, '_> {
}
};

let len = spans.len();
spans.sort();
let ms = MultiSpan::from_spans(spans.clone());
let mut span_snippets = spans
let ms = MultiSpan::from_spans(spans);

let mut span_snippets = ms
.primary_spans()
.iter()
.filter_map(|s| match tcx.sess.source_map().span_to_snippet(*s) {
Ok(s) => Some(format!("`{s}`")),
_ => None,
})
.filter_map(|span| tcx.sess.source_map().span_to_snippet(*span).ok())
.map(|s| format!("`{s}`"))
.collect::<Vec<String>>();
span_snippets.sort();

let msg = format!(
"unused import{}{}",
pluralize!(len),
pluralize!(ms.primary_spans().len()),
if !span_snippets.is_empty() {
format!(": {}", span_snippets.join(", "))
} else {
Expand All @@ -376,7 +375,7 @@ impl Resolver<'_, '_> {

let fix_msg = if fixes.len() == 1 && fixes[0].0 == unused.item_span {
"remove the whole `use` item"
} else if spans.len() > 1 {
} else if ms.primary_spans().len() > 1 {
"remove the unused imports"
} else {
"remove the unused import"
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2743,13 +2743,11 @@ pub fn build_session_options(
// This is what prevents them from being used on stable compilers.
match cg.instrument_coverage {
// Stable values:
Some(InstrumentCoverage::All | InstrumentCoverage::Off) | None => {}
InstrumentCoverage::All | InstrumentCoverage::Off => {}
// Unstable values:
Some(
InstrumentCoverage::Branch
| InstrumentCoverage::ExceptUnusedFunctions
| InstrumentCoverage::ExceptUnusedGenerics,
) => {
InstrumentCoverage::Branch
| InstrumentCoverage::ExceptUnusedFunctions
| InstrumentCoverage::ExceptUnusedGenerics => {
if !unstable_opts.unstable_options {
handler.early_error(
"`-C instrument-coverage=branch` and `-C instrument-coverage=except-*` \
Expand All @@ -2759,7 +2757,7 @@ pub fn build_session_options(
}
}

if cg.instrument_coverage.is_some() && cg.instrument_coverage != Some(InstrumentCoverage::Off) {
if cg.instrument_coverage != InstrumentCoverage::Off {
if cg.profile_generate.enabled() || cg.profile_use.is_some() {
handler.early_error(
"option `-C instrument-coverage` is not compatible with either `-C profile-use` \
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl CodegenOptions {
// JUSTIFICATION: defn of the suggested wrapper fn
#[allow(rustc::bad_opt_access)]
pub fn instrument_coverage(&self) -> InstrumentCoverage {
self.instrument_coverage.unwrap_or(InstrumentCoverage::Off)
self.instrument_coverage
}
}

Expand Down Expand Up @@ -913,23 +913,23 @@ mod parse {
}

pub(crate) fn parse_instrument_coverage(
slot: &mut Option<InstrumentCoverage>,
slot: &mut InstrumentCoverage,
v: Option<&str>,
) -> bool {
if v.is_some() {
let mut bool_arg = None;
if parse_opt_bool(&mut bool_arg, v) {
*slot = bool_arg.unwrap().then_some(InstrumentCoverage::All);
let mut bool_arg = false;
if parse_bool(&mut bool_arg, v) {
*slot = if bool_arg { InstrumentCoverage::All } else { InstrumentCoverage::Off };
return true;
}
}

let Some(v) = v else {
*slot = Some(InstrumentCoverage::All);
*slot = InstrumentCoverage::All;
return true;
};

*slot = Some(match v {
*slot = match v {
"all" => InstrumentCoverage::All,
"branch" => InstrumentCoverage::Branch,
"except-unused-generics" | "except_unused_generics" => {
Expand All @@ -940,7 +940,7 @@ mod parse {
}
"off" | "no" | "n" | "false" | "0" => InstrumentCoverage::Off,
_ => return false,
});
};
true
}

Expand Down Expand Up @@ -1352,7 +1352,7 @@ options! {
inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
"set the threshold for inlining a function"),
#[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
instrument_coverage: Option<InstrumentCoverage> = (None, parse_instrument_coverage, [TRACKED],
instrument_coverage: InstrumentCoverage = (InstrumentCoverage::Off, parse_instrument_coverage, [TRACKED],
"instrument the generated code to support LLVM source-based code coverage \
reports (note, the compiler build config must include `profiler = true`); \
implies `-C symbol-mangling-version=v0`. Optional values are:
Expand Down
Loading
Loading