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 5 pull requests #117481

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
91405ab
Clean up unchecked_math, separate out unchecked_shifts
clarfonthey Sep 7, 2023
62fe807
FileCheck asm_unwind
rmehri01 Oct 20, 2023
2d0a34b
FileCheck caller_with_trivial_bound
rmehri01 Oct 20, 2023
2f9aa7d
FileCheck cycle
rmehri01 Oct 20, 2023
9b3f5e1
FileCheck dont_ice_on_generic_rust_call
rmehri01 Oct 20, 2023
76faae9
FileCheck dyn_trait
rmehri01 Oct 20, 2023
f005d23
FileCheck exponential_runtime
rmehri01 Oct 20, 2023
22679cd
FileCheck inline_any_operand
rmehri01 Oct 20, 2023
de56d2d
FileCheck inline_box_fn
rmehri01 Oct 20, 2023
9d61e6a
FileCheck inline_closure_borrows_arg
rmehri01 Oct 20, 2023
5caee41
FileCheck inline_closure_captures
rmehri01 Oct 20, 2023
7ee05d2
FileCheck inline_closure
rmehri01 Oct 20, 2023
d8f33ef
FileCheck inline_diverging
rmehri01 Oct 21, 2023
20e7caa
FileCheck inline_coroutine
rmehri01 Oct 21, 2023
19c36a9
FileCheck inline_instruction_set
rmehri01 Oct 21, 2023
de82551
FileCheck inline_into_box_place
rmehri01 Oct 21, 2023
3202d4e
FileCheck inline_options
rmehri01 Oct 21, 2023
21a4c39
FileCheck inline_retag
rmehri01 Oct 21, 2023
2532566
FileCheck inline_specialization
rmehri01 Oct 21, 2023
f7acf17
FileCheck inline_trait_method_2
rmehri01 Oct 21, 2023
1b9cb5d
FileCheck inline_trait_method
rmehri01 Oct 21, 2023
773dc62
FileCheck inline_as_ref_as_mut
rmehri01 Oct 21, 2023
bb69597
FileCheck inline_scopes_parenting
rmehri01 Oct 21, 2023
5cf65eb
FileCheck issue_78442
rmehri01 Oct 21, 2023
6e047c0
FileCheck unchecked_shifts
rmehri01 Oct 21, 2023
3faf05b
FileCheck unsized_argument
rmehri01 Oct 21, 2023
6ab66c3
FileCheck unwrap_unchecked
rmehri01 Oct 21, 2023
1ec10ec
address review comments
rmehri01 Oct 22, 2023
8076414
Don't emit delayed good-path bugs on panic
compiler-errors Oct 30, 2023
147c4a5
Refactor: move suggestion functions from demand to suggestions
chenyukang Oct 30, 2023
2fcb4d9
change inline_retag to after.mir
rmehri01 Oct 31, 2023
587af91
Inline and remove `create_session`.
nnethercote Oct 30, 2023
c0ed667
Rollup merge of #115626 - clarfonthey:unchecked-math, r=thomcc
matthiaskrgr Nov 1, 2023
765ac22
Rollup merge of #117029 - rmehri01:mir_opt_filecheck_inline_tests, r=…
matthiaskrgr Nov 1, 2023
d65fffc
Rollup merge of #117397 - compiler-errors:dont-emit-good-path-on-pani…
matthiaskrgr Nov 1, 2023
63249fb
Rollup merge of #117401 - chenyukang:yukang-cleanup-hir-typeck-sugges…
matthiaskrgr Nov 1, 2023
d46dcdf
Rollup merge of #117475 - nnethercote:rm-create_session, r=oli-obk
matthiaskrgr Nov 1, 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
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ impl Drop for HandlerInner {
// instead of "require some error happened". Sadly that isn't ideal, as
// lints can be `#[allow]`'d, potentially leading to this triggering.
// Also, "good path" should be replaced with a better naming.
if !self.has_any_message() && !self.suppressed_expected_diag {
if !self.has_any_message() && !self.suppressed_expected_diag && !std::thread::panicking() {
let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new());
self.flush_delayed(
bugs,
Expand Down
1,276 changes: 3 additions & 1,273 deletions compiler/rustc_hir_typeck/src/demand.rs

Large diffs are not rendered by default.

1,269 changes: 1,269 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Large diffs are not rendered by default.

64 changes: 51 additions & 13 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ use rustc_query_system::query::print_query_stack;
use rustc_session::config::{
self, Cfg, CheckCfg, ExpectedValues, Input, OutFileName, OutputFilenames,
};
use rustc_session::filesearch::sysroot_candidates;
use rustc_session::parse::ParseSess;
use rustc_session::CompilerIO;
use rustc_session::Session;
use rustc_session::{lint, EarlyErrorHandler};
use rustc_session::{lint, CompilerIO, EarlyErrorHandler, Session};
use rustc_span::source_map::{FileLoader, FileName};
use rustc_span::symbol::sym;
use std::path::PathBuf;
Expand Down Expand Up @@ -398,32 +397,71 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|| {
crate::callbacks::setup_callbacks();

let registry = &config.registry;

let handler = EarlyErrorHandler::new(config.opts.error_format);

let codegen_backend = if let Some(make_codegen_backend) = config.make_codegen_backend {
make_codegen_backend(&config.opts)
} else {
util::get_codegen_backend(
&handler,
&config.opts.maybe_sysroot,
config.opts.unstable_opts.codegen_backend.as_deref(),
)
};

let temps_dir = config.opts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
let (mut sess, codegen_backend) = util::create_session(

let bundle = match rustc_errors::fluent_bundle(
config.opts.maybe_sysroot.clone(),
sysroot_candidates().to_vec(),
config.opts.unstable_opts.translate_lang.clone(),
config.opts.unstable_opts.translate_additional_ftl.as_deref(),
config.opts.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(config.locale_resources);
locale_resources.push(codegen_backend.locale_resource());

// target_override is documented to be called before init(), so this is okay
let target_override = codegen_backend.target_override(&config.opts);

let mut sess = rustc_session::build_session(
&handler,
config.opts,
parse_cfg(&handler, config.crate_cfg),
parse_check_cfg(&handler, config.crate_check_cfg),
config.locale_resources,
config.file_loader,
CompilerIO {
input: config.input,
output_dir: config.output_dir,
output_file: config.output_file,
temps_dir,
},
bundle,
config.registry.clone(),
locale_resources,
config.lint_caps,
config.make_codegen_backend,
registry.clone(),
config.file_loader,
target_override,
util::rustc_version_str().unwrap_or("unknown"),
config.ice_file,
config.using_internal_features,
config.expanded_args,
);

codegen_backend.init(&sess);

let cfg = parse_cfg(&handler, config.crate_cfg);
let mut cfg = config::build_configuration(&sess, cfg);
util::add_configuration(&mut cfg, &mut sess, &*codegen_backend);
sess.parse_sess.config = cfg;

let mut check_cfg = parse_check_cfg(&handler, config.crate_check_cfg);
check_cfg.fill_well_known(&sess.target);
sess.parse_sess.check_config = check_cfg;

if let Some(parse_sess_created) = config.parse_sess_created {
parse_sess_created(&mut sess.parse_sess);
}
Expand All @@ -444,7 +482,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
rustc_span::set_source_map(compiler.sess.parse_sess.clone_source_map(), move || {
let r = {
let _sess_abort_error = defer(|| {
compiler.sess.finish_diagnostics(registry);
compiler.sess.finish_diagnostics(&config.registry);
});

f(&compiler)
Expand Down
87 changes: 3 additions & 84 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,24 @@ use info;
use libloading::Library;
use rustc_ast as ast;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::fx::FxHashMap;
#[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::{
self, Cfg, CheckCfg, CrateType, 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::{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;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, OnceLock};
use std::sync::OnceLock;
use std::thread;

/// Function pointer type that constructs a new CodegenBackend.
Expand All @@ -52,82 +47,6 @@ pub fn add_configuration(cfg: &mut Cfg, sess: &mut Session, codegen_backend: &dy
}
}

pub fn create_session(
handler: &EarlyErrorHandler,
sopts: config::Options,
cfg: Cfg,
mut 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>,
using_internal_features: Arc<AtomicBool>,
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,
using_internal_features,
expanded_args,
);

codegen_backend.init(&sess);

let mut cfg = config::build_configuration(&sess, cfg);
add_configuration(&mut cfg, &mut sess, &*codegen_backend);

check_cfg.fill_well_known(&sess.target);

// These configs use symbols, rather than strings.
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> {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
#![feature(const_hash)]
#![feature(const_heap)]
#![feature(const_index_range_slice_index)]
#![feature(const_inherent_unchecked_arith)]
#![feature(const_int_unchecked_arith)]
#![feature(const_intrinsic_forget)]
#![feature(const_ipv4)]
Expand Down Expand Up @@ -188,6 +187,8 @@
#![feature(str_split_inclusive_remainder)]
#![feature(str_split_remainder)]
#![feature(strict_provenance)]
#![feature(unchecked_math)]
#![feature(unchecked_shifts)]
#![feature(utf16_extra)]
#![feature(utf16_extra_const)]
#![feature(variant_count)]
Expand Down
43 changes: 34 additions & 9 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ macro_rules! int_impl {
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[rustc_const_unstable(feature = "unchecked_math", issue = "85122")]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
Expand Down Expand Up @@ -539,7 +539,7 @@ macro_rules! int_impl {
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[rustc_const_unstable(feature = "unchecked_math", issue = "85122")]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
Expand Down Expand Up @@ -607,7 +607,7 @@ macro_rules! int_impl {
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[rustc_const_unstable(feature = "unchecked_math", issue = "85122")]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
Expand Down Expand Up @@ -740,6 +740,31 @@ macro_rules! int_impl {
if unlikely!(b) {None} else {Some(a)}
}

/// Unchecked negation. Computes `-self`, assuming overflow cannot occur.
///
/// # Safety
///
/// This results in undefined behavior when
#[doc = concat!("`self == ", stringify!($SelfT), "::MIN`,")]
/// i.e. when [`checked_neg`] would return `None`.
///
#[doc = concat!("[`checked_neg`]: ", stringify!($SelfT), "::checked_neg")]
#[unstable(
feature = "unchecked_neg",
reason = "niche optimization path",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "unchecked_neg", issue = "85122")]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_neg(self) -> Self {
// SAFETY: the caller must uphold the safety contract for
// `unchecked_neg`.
unsafe { intrinsics::unchecked_sub(0, self) }
}

/// Checked shift left. Computes `self << rhs`, returning `None` if `rhs` is larger
/// than or equal to the number of bits in `self`.
///
Expand Down Expand Up @@ -772,13 +797,13 @@ macro_rules! int_impl {
///
#[doc = concat!("[`checked_shl`]: ", stringify!($SelfT), "::checked_shl")]
#[unstable(
feature = "unchecked_math",
feature = "unchecked_shifts",
reason = "niche optimization path",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
Expand Down Expand Up @@ -820,13 +845,13 @@ macro_rules! int_impl {
///
#[doc = concat!("[`checked_shr`]: ", stringify!($SelfT), "::checked_shr")]
#[unstable(
feature = "unchecked_math",
feature = "unchecked_shifts",
reason = "niche optimization path",
issue = "85122",
)]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
#[rustc_const_unstable(feature = "unchecked_shifts", issue = "85122")]
#[inline(always)]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
Expand Down Expand Up @@ -1404,7 +1429,7 @@ macro_rules! int_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[rustc_allow_const_fn_unstable(const_inherent_unchecked_arith)]
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
// out of bounds
Expand Down Expand Up @@ -1434,7 +1459,7 @@ macro_rules! int_impl {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
#[rustc_allow_const_fn_unstable(const_inherent_unchecked_arith)]
#[rustc_allow_const_fn_unstable(unchecked_shifts)]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
// SAFETY: the masking by the bitsize of the type ensures that we do not shift
// out of bounds
Expand Down
Loading