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 7 pull requests #135947

Merged
merged 25 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2808977
Implement `ByteStr` and `ByteString` types
joshtriplett Jan 2, 2025
dcc352f
Bless new test output (new trait impls in lists of suggestions)
joshtriplett Jan 4, 2025
fc34bea
Add `#[cfg(not(test))]` to some impls to work around https://github.c…
joshtriplett Jan 4, 2025
049217b
Add bstr files to linkchecker since they have a Deref to slice
joshtriplett Jan 5, 2025
76780fa
Support `no_rc`, `no_sync`, and `no_global_oom_handling`
joshtriplett Jan 6, 2025
22a4ec3
Omit some more `From` impls to avoid inference failures
joshtriplett Jan 12, 2025
ab2c8ff
Add missing check for async body when suggesting await on futures.
metamuffin Jan 14, 2025
7171fee
remove unnecessary collection
lcnr Jan 20, 2025
09b784f
handle global trait bounds defining assoc type
lcnr Jan 20, 2025
022e7c0
Add doc aliases for BStr and BString
joshtriplett Jan 22, 2025
865471f
Implement `CloneToUninit` for `ByteStr`
joshtriplett Jan 22, 2025
44e8c43
rustc_codegen_llvm: remove outdated asm-to-obj codegen note
ken-matsui Jan 22, 2025
4c448d5
Allow `arena_cache` queries to return `Option<&'tcx T>`
Zalathar Jan 22, 2025
cceb968
simplify parse_format::Parser::ws by using next_if
hkBst Jan 23, 2025
4f9b9a4
Remove the need to manually call set_using_internal_features
bjorn3 Jan 22, 2025
974db1a
Remove set_make_codegen_backend and set_file_loader
bjorn3 Jan 22, 2025
a77776c
Remove RunCompiler
bjorn3 Jan 22, 2025
241f824
Remove outdated sentence
bjorn3 Jan 22, 2025
08d5b23
Rollup merge of #135073 - joshtriplett:bstr, r=BurntSushi
matthiaskrgr Jan 23, 2025
4496f23
Rollup merge of #135492 - metamuffin:bug-invalid-await-suggest, r=com…
matthiaskrgr Jan 23, 2025
dafc861
Rollup merge of #135766 - lcnr:candidate-assembly-3, r=compiler-errors
matthiaskrgr Jan 23, 2025
7d31ae7
Rollup merge of #135880 - bjorn3:misc_driver_refactors, r=oli-obk
matthiaskrgr Jan 23, 2025
36da4ec
Rollup merge of #135908 - ken-matsui:remove-asm-to-obj-comment, r=com…
matthiaskrgr Jan 23, 2025
ce2a316
Rollup merge of #135911 - Zalathar:arena-cache-option, r=compiler-errors
matthiaskrgr Jan 23, 2025
7d26006
Rollup merge of #135920 - hkBst:patch-16, r=SparrowLii
matthiaskrgr Jan 23, 2025
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4260,7 +4260,6 @@ dependencies = [
"rustc_serialize",
"rustc_type_ir",
"rustc_type_ir_macros",
"smallvec",
"tracing",
]

Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,9 @@ pub(crate) unsafe fn codegen(
}
}

// Two things to note:
// - If object files are just LLVM bitcode we write bitcode, copy it to
// the .o file, and delete the bitcode if it wasn't otherwise
// requested.
// - If we don't have the integrated assembler then we need to emit
// asm from LLVM and use `gcc` to create the object file.
// Note that if object files are just LLVM bitcode we write bitcode,
// copy it to the .o file, and delete the bitcode if it wasn't
// otherwise requested.

let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
let bc_summary_out =
Expand Down
111 changes: 11 additions & 100 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use std::io::{self, IsTerminal, Read, Write};
use std::panic::{self, PanicHookInfo, catch_unwind};
use std::path::{Path, PathBuf};
use std::process::{self, Command, Stdio};
use std::sync::OnceLock;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, OnceLock};
use std::time::{Instant, SystemTime};
use std::{env, str};

Expand Down Expand Up @@ -60,7 +60,6 @@ use rustc_session::lint::{Lint, LintId};
use rustc_session::output::collect_crate_types;
use rustc_session::{EarlyDiagCtxt, Session, config, filesearch};
use rustc_span::FileName;
use rustc_span::source_map::FileLoader;
use rustc_target::json::ToJson;
use rustc_target::spec::{Target, TargetTuple};
use time::OffsetDateTime;
Expand Down Expand Up @@ -208,84 +207,7 @@ pub fn diagnostics_registry() -> Registry {
}

/// This is the primary entry point for rustc.
pub struct RunCompiler<'a> {
at_args: &'a [String],
callbacks: &'a mut (dyn Callbacks + Send),
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
make_codegen_backend:
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
}

impl<'a> RunCompiler<'a> {
pub fn new(at_args: &'a [String], callbacks: &'a mut (dyn Callbacks + Send)) -> Self {
Self {
at_args,
callbacks,
file_loader: None,
make_codegen_backend: None,
using_internal_features: Arc::default(),
}
}

/// Set a custom codegen backend.
///
/// Has no uses within this repository, but is used by bjorn3 for "the
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
/// custom driver where the custom codegen backend has arbitrary data."
/// (See #102759.)
pub fn set_make_codegen_backend(
&mut self,
make_codegen_backend: Option<
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
>,
) -> &mut Self {
self.make_codegen_backend = make_codegen_backend;
self
}

/// Load files from sources other than the file system.
///
/// Has no uses within this repository, but may be used in the future by
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
/// running rustc without having to save". (See #102759.)
pub fn set_file_loader(
&mut self,
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
) -> &mut Self {
self.file_loader = file_loader;
self
}

/// Set the session-global flag that checks whether internal features have been used,
/// suppressing the message about submitting an issue in ICEs when enabled.
#[must_use]
pub fn set_using_internal_features(mut self, using_internal_features: Arc<AtomicBool>) -> Self {
self.using_internal_features = using_internal_features;
self
}

/// Parse args and run the compiler.
pub fn run(self) {
run_compiler(
self.at_args,
self.callbacks,
self.file_loader,
self.make_codegen_backend,
self.using_internal_features,
);
}
}

fn run_compiler(
at_args: &[String],
callbacks: &mut (dyn Callbacks + Send),
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
make_codegen_backend: Option<
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
>,
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
) {
pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send)) {
let mut default_early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());

// Throw away the first argument, the name of the binary.
Expand Down Expand Up @@ -322,16 +244,16 @@ fn run_compiler(
output_file: ofile,
output_dir: odir,
ice_file,
file_loader,
file_loader: None,
locale_resources: DEFAULT_LOCALE_RESOURCES.to_vec(),
lint_caps: Default::default(),
psess_created: None,
hash_untracked_state: None,
register_lints: None,
override_queries: None,
make_codegen_backend,
make_codegen_backend: None,
registry: diagnostics_registry(),
using_internal_features,
using_internal_features: &USING_INTERNAL_FEATURES,
expanded_args: args,
};

Expand Down Expand Up @@ -1350,6 +1272,8 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
})
}

pub static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);

/// Installs a panic hook that will print the ICE message on unexpected panics.
///
/// The hook is intended to be useable even by external tools. You can pass a custom
Expand All @@ -1360,15 +1284,8 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
/// If you have no extra info to report, pass the empty closure `|_| ()` as the argument to
/// extra_info.
///
/// Returns a flag that can be set to disable the note for submitting a bug. This can be passed to
/// [`RunCompiler::set_using_internal_features`] to let macro expansion set it when encountering
/// internal features.
///
/// A custom rustc driver can skip calling this to set up a custom ICE hook.
pub fn install_ice_hook(
bug_report_url: &'static str,
extra_info: fn(&DiagCtxt),
) -> Arc<AtomicBool> {
pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&DiagCtxt)) {
// If the user has not explicitly overridden "RUST_BACKTRACE", then produce
// full backtraces. When a compiler ICE happens, we want to gather
// as much information as possible to present in the issue opened
Expand All @@ -1385,8 +1302,6 @@ pub fn install_ice_hook(
}
}

let using_internal_features = Arc::new(std::sync::atomic::AtomicBool::default());
let using_internal_features_hook = Arc::clone(&using_internal_features);
panic::update_hook(Box::new(
move |default_hook: &(dyn Fn(&PanicHookInfo<'_>) + Send + Sync + 'static),
info: &PanicHookInfo<'_>| {
Expand Down Expand Up @@ -1438,11 +1353,9 @@ pub fn install_ice_hook(
}

// Print the ICE message
report_ice(info, bug_report_url, extra_info, &using_internal_features_hook);
report_ice(info, bug_report_url, extra_info, &USING_INTERNAL_FEATURES);
},
));

using_internal_features
}

/// Prints the ICE message, including query stack, but without backtrace.
Expand Down Expand Up @@ -1583,13 +1496,11 @@ pub fn main() -> ! {
init_rustc_env_logger(&early_dcx);
signal_handler::install();
let mut callbacks = TimePassesCallbacks::default();
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
install_ctrlc_handler();

let exit_code = catch_with_exit_code(|| {
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks)
.set_using_internal_features(using_internal_features)
.run();
run_compiler(&args::raw_args(&early_dcx)?, &mut callbacks);
Ok(())
});

Expand Down
14 changes: 11 additions & 3 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::PathBuf;
use std::result;
use std::sync::Arc;

use rustc_ast::{LitKind, MetaItemKind, token};
use rustc_codegen_ssa::traits::CodegenBackend;
Expand Down Expand Up @@ -309,6 +308,11 @@ pub struct Config {
pub output_dir: Option<PathBuf>,
pub output_file: Option<OutFileName>,
pub ice_file: Option<PathBuf>,
/// Load files from sources other than the file system.
///
/// Has no uses within this repository, but may be used in the future by
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
/// running rustc without having to save". (See #102759.)
pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
/// The list of fluent resources, used for lints declared with
/// [`Diagnostic`](rustc_errors::Diagnostic) and [`LintDiagnostic`](rustc_errors::LintDiagnostic).
Expand Down Expand Up @@ -337,6 +341,11 @@ pub struct Config {
pub override_queries: Option<fn(&Session, &mut Providers)>,

/// This is a callback from the driver that is called to create a codegen backend.
///
/// Has no uses within this repository, but is used by bjorn3 for "the
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
/// custom driver where the custom codegen backend has arbitrary data."
/// (See #102759.)
pub make_codegen_backend:
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,

Expand All @@ -346,8 +355,7 @@ pub struct Config {
/// The inner atomic value is set to true when a feature marked as `internal` is
/// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
/// internal features are wontfix, and they are usually the cause of the ICEs.
/// None signifies that this is not tracked.
pub using_internal_features: Arc<std::sync::atomic::AtomicBool>,
pub using_internal_features: &'static std::sync::atomic::AtomicBool,

/// All commandline args used to invoke the compiler, with @file args fully expanded.
/// This will only be used within debug info, e.g. in the pdb file on windows
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::collections::{BTreeMap, BTreeSet};
use std::num::NonZero;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::atomic::AtomicBool;

use rustc_data_structures::profiling::TimePassesFormat;
use rustc_errors::emitter::HumanReadableErrorType;
Expand Down Expand Up @@ -62,6 +62,8 @@ where
temps_dir,
};

static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);

let sess = build_session(
early_dcx,
sessopts,
Expand All @@ -74,7 +76,7 @@ where
sysroot,
"",
None,
Arc::default(),
&USING_INTERNAL_FEATURES,
Default::default(),
);
let cfg = parse_cfg(sess.dcx(), matches.opt_strs("cfg"));
Expand Down
47 changes: 47 additions & 0 deletions compiler/rustc_middle/src/query/arena_cached.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// Helper trait that allows `arena_cache` queries to return `Option<&T>`
/// instead of `&Option<T>`, and avoid allocating `None` in the arena.
///
/// An arena-cached query must be declared to return a type that implements
/// this trait, i.e. either `&'tcx T` or `Option<&'tcx T>`. This trait then
/// determines the types returned by the provider and stored in the arena,
/// and provides a function to bridge between the three types.
pub trait ArenaCached<'tcx>: Sized {
/// Type that is returned by the query provider.
type Provided;
/// Type that is stored in the arena.
type Allocated: 'tcx;

/// Takes a provided value, and allocates it in the arena (if appropriate)
/// with the help of the given `arena_alloc` closure.
fn alloc_in_arena(
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated,
value: Self::Provided,
) -> Self;
}

impl<'tcx, T> ArenaCached<'tcx> for &'tcx T {
type Provided = T;
type Allocated = T;

fn alloc_in_arena(
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated,
value: Self::Provided,
) -> Self {
// Just allocate in the arena normally.
arena_alloc(value)
}
}

impl<'tcx, T> ArenaCached<'tcx> for Option<&'tcx T> {
type Provided = Option<T>;
/// The provide value is `Option<T>`, but we only store `T` in the arena.
type Allocated = T;

fn alloc_in_arena(
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated,
value: Self::Provided,
) -> Self {
// Don't store None in the arena, and wrap the allocated reference in Some.
value.map(arena_alloc)
}
}
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#![allow(unused_parens)]

use std::mem;
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::Arc;

Expand Down Expand Up @@ -85,6 +84,7 @@ use crate::ty::{
};
use crate::{dep_graph, mir, thir};

mod arena_cached;
pub mod erase;
mod keys;
pub use keys::{AsLocalKey, Key, LocalCrate};
Expand Down Expand Up @@ -586,7 +586,7 @@ rustc_queries! {
separate_provide_extern
}

query mir_coroutine_witnesses(key: DefId) -> &'tcx Option<mir::CoroutineLayout<'tcx>> {
query mir_coroutine_witnesses(key: DefId) -> Option<&'tcx mir::CoroutineLayout<'tcx>> {
arena_cache
desc { |tcx| "coroutine witness types for `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
Expand Down Expand Up @@ -2415,7 +2415,7 @@ rustc_queries! {
/// because the `ty::Ty`-based wfcheck is always run.
query diagnostic_hir_wf_check(
key: (ty::Predicate<'tcx>, WellFormedLoc)
) -> &'tcx Option<ObligationCause<'tcx>> {
) -> Option<&'tcx ObligationCause<'tcx>> {
arena_cache
eval_always
no_hash
Expand Down
Loading
Loading