Skip to content

Commit 1c9837d

Browse files
committed
Auto merge of #135947 - matthiaskrgr:rollup-k9jpfls, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #135073 (Implement `ByteStr` and `ByteString` types) - #135492 (Add missing check for async body when suggesting await on futures.) - #135766 (handle global trait bounds defining assoc types) - #135880 (Get rid of RunCompiler) - #135908 (rustc_codegen_llvm: remove outdated asm-to-obj codegen note) - #135911 (Allow `arena_cache` queries to return `Option<&'tcx T>`) - #135920 (simplify parse_format::Parser::ws by using next_if) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 22a220a + 7d26006 commit 1c9837d

File tree

42 files changed

+1609
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1609
-251
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4260,7 +4260,6 @@ dependencies = [
42604260
"rustc_serialize",
42614261
"rustc_type_ir",
42624262
"rustc_type_ir_macros",
4263-
"smallvec",
42644263
"tracing",
42654264
]
42664265

compiler/rustc_codegen_llvm/src/back/write.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,9 @@ pub(crate) unsafe fn codegen(
769769
}
770770
}
771771

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

779776
let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
780777
let bc_summary_out =

compiler/rustc_driver_impl/src/lib.rs

+11-100
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use std::io::{self, IsTerminal, Read, Write};
2828
use std::panic::{self, PanicHookInfo, catch_unwind};
2929
use std::path::{Path, PathBuf};
3030
use std::process::{self, Command, Stdio};
31+
use std::sync::OnceLock;
3132
use std::sync::atomic::{AtomicBool, Ordering};
32-
use std::sync::{Arc, OnceLock};
3333
use std::time::{Instant, SystemTime};
3434
use std::{env, str};
3535

@@ -60,7 +60,6 @@ use rustc_session::lint::{Lint, LintId};
6060
use rustc_session::output::collect_crate_types;
6161
use rustc_session::{EarlyDiagCtxt, Session, config, filesearch};
6262
use rustc_span::FileName;
63-
use rustc_span::source_map::FileLoader;
6463
use rustc_target::json::ToJson;
6564
use rustc_target::spec::{Target, TargetTuple};
6665
use time::OffsetDateTime;
@@ -208,84 +207,7 @@ pub fn diagnostics_registry() -> Registry {
208207
}
209208

210209
/// This is the primary entry point for rustc.
211-
pub struct RunCompiler<'a> {
212-
at_args: &'a [String],
213-
callbacks: &'a mut (dyn Callbacks + Send),
214-
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
215-
make_codegen_backend:
216-
Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
217-
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
218-
}
219-
220-
impl<'a> RunCompiler<'a> {
221-
pub fn new(at_args: &'a [String], callbacks: &'a mut (dyn Callbacks + Send)) -> Self {
222-
Self {
223-
at_args,
224-
callbacks,
225-
file_loader: None,
226-
make_codegen_backend: None,
227-
using_internal_features: Arc::default(),
228-
}
229-
}
230-
231-
/// Set a custom codegen backend.
232-
///
233-
/// Has no uses within this repository, but is used by bjorn3 for "the
234-
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
235-
/// custom driver where the custom codegen backend has arbitrary data."
236-
/// (See #102759.)
237-
pub fn set_make_codegen_backend(
238-
&mut self,
239-
make_codegen_backend: Option<
240-
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
241-
>,
242-
) -> &mut Self {
243-
self.make_codegen_backend = make_codegen_backend;
244-
self
245-
}
246-
247-
/// Load files from sources other than the file system.
248-
///
249-
/// Has no uses within this repository, but may be used in the future by
250-
/// bjorn3 for "hooking rust-analyzer's VFS into rustc at some point for
251-
/// running rustc without having to save". (See #102759.)
252-
pub fn set_file_loader(
253-
&mut self,
254-
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
255-
) -> &mut Self {
256-
self.file_loader = file_loader;
257-
self
258-
}
259-
260-
/// Set the session-global flag that checks whether internal features have been used,
261-
/// suppressing the message about submitting an issue in ICEs when enabled.
262-
#[must_use]
263-
pub fn set_using_internal_features(mut self, using_internal_features: Arc<AtomicBool>) -> Self {
264-
self.using_internal_features = using_internal_features;
265-
self
266-
}
267-
268-
/// Parse args and run the compiler.
269-
pub fn run(self) {
270-
run_compiler(
271-
self.at_args,
272-
self.callbacks,
273-
self.file_loader,
274-
self.make_codegen_backend,
275-
self.using_internal_features,
276-
);
277-
}
278-
}
279-
280-
fn run_compiler(
281-
at_args: &[String],
282-
callbacks: &mut (dyn Callbacks + Send),
283-
file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
284-
make_codegen_backend: Option<
285-
Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
286-
>,
287-
using_internal_features: Arc<std::sync::atomic::AtomicBool>,
288-
) {
210+
pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send)) {
289211
let mut default_early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
290212

291213
// Throw away the first argument, the name of the binary.
@@ -322,16 +244,16 @@ fn run_compiler(
322244
output_file: ofile,
323245
output_dir: odir,
324246
ice_file,
325-
file_loader,
247+
file_loader: None,
326248
locale_resources: DEFAULT_LOCALE_RESOURCES.to_vec(),
327249
lint_caps: Default::default(),
328250
psess_created: None,
329251
hash_untracked_state: None,
330252
register_lints: None,
331253
override_queries: None,
332-
make_codegen_backend,
254+
make_codegen_backend: None,
333255
registry: diagnostics_registry(),
334-
using_internal_features,
256+
using_internal_features: &USING_INTERNAL_FEATURES,
335257
expanded_args: args,
336258
};
337259

@@ -1350,6 +1272,8 @@ fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<Pat
13501272
})
13511273
}
13521274

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

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

14401355
// Print the ICE message
1441-
report_ice(info, bug_report_url, extra_info, &using_internal_features_hook);
1356+
report_ice(info, bug_report_url, extra_info, &USING_INTERNAL_FEATURES);
14421357
},
14431358
));
1444-
1445-
using_internal_features
14461359
}
14471360

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

15891502
let exit_code = catch_with_exit_code(|| {
1590-
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks)
1591-
.set_using_internal_features(using_internal_features)
1592-
.run();
1503+
run_compiler(&args::raw_args(&early_dcx)?, &mut callbacks);
15931504
Ok(())
15941505
});
15951506

compiler/rustc_interface/src/interface.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::path::PathBuf;
22
use std::result;
3-
use std::sync::Arc;
43

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

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

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

352360
/// All commandline args used to invoke the compiler, with @file args fully expanded.
353361
/// This will only be used within debug info, e.g. in the pdb file on windows

compiler/rustc_interface/src/tests.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::collections::{BTreeMap, BTreeSet};
33
use std::num::NonZero;
44
use std::path::{Path, PathBuf};
5-
use std::sync::Arc;
5+
use std::sync::atomic::AtomicBool;
66

77
use rustc_data_structures::profiling::TimePassesFormat;
88
use rustc_errors::emitter::HumanReadableErrorType;
@@ -62,6 +62,8 @@ where
6262
temps_dir,
6363
};
6464

65+
static USING_INTERNAL_FEATURES: AtomicBool = AtomicBool::new(false);
66+
6567
let sess = build_session(
6668
early_dcx,
6769
sessopts,
@@ -74,7 +76,7 @@ where
7476
sysroot,
7577
"",
7678
None,
77-
Arc::default(),
79+
&USING_INTERNAL_FEATURES,
7880
Default::default(),
7981
);
8082
let cfg = parse_cfg(sess.dcx(), matches.opt_strs("cfg"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// Helper trait that allows `arena_cache` queries to return `Option<&T>`
2+
/// instead of `&Option<T>`, and avoid allocating `None` in the arena.
3+
///
4+
/// An arena-cached query must be declared to return a type that implements
5+
/// this trait, i.e. either `&'tcx T` or `Option<&'tcx T>`. This trait then
6+
/// determines the types returned by the provider and stored in the arena,
7+
/// and provides a function to bridge between the three types.
8+
pub trait ArenaCached<'tcx>: Sized {
9+
/// Type that is returned by the query provider.
10+
type Provided;
11+
/// Type that is stored in the arena.
12+
type Allocated: 'tcx;
13+
14+
/// Takes a provided value, and allocates it in the arena (if appropriate)
15+
/// with the help of the given `arena_alloc` closure.
16+
fn alloc_in_arena(
17+
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated,
18+
value: Self::Provided,
19+
) -> Self;
20+
}
21+
22+
impl<'tcx, T> ArenaCached<'tcx> for &'tcx T {
23+
type Provided = T;
24+
type Allocated = T;
25+
26+
fn alloc_in_arena(
27+
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated,
28+
value: Self::Provided,
29+
) -> Self {
30+
// Just allocate in the arena normally.
31+
arena_alloc(value)
32+
}
33+
}
34+
35+
impl<'tcx, T> ArenaCached<'tcx> for Option<&'tcx T> {
36+
type Provided = Option<T>;
37+
/// The provide value is `Option<T>`, but we only store `T` in the arena.
38+
type Allocated = T;
39+
40+
fn alloc_in_arena(
41+
arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated,
42+
value: Self::Provided,
43+
) -> Self {
44+
// Don't store None in the arena, and wrap the allocated reference in Some.
45+
value.map(arena_alloc)
46+
}
47+
}

compiler/rustc_middle/src/query/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![allow(unused_parens)]
88

99
use std::mem;
10-
use std::ops::Deref;
1110
use std::path::PathBuf;
1211
use std::sync::Arc;
1312

@@ -85,6 +84,7 @@ use crate::ty::{
8584
};
8685
use crate::{dep_graph, mir, thir};
8786

87+
mod arena_cached;
8888
pub mod erase;
8989
mod keys;
9090
pub use keys::{AsLocalKey, Key, LocalCrate};
@@ -586,7 +586,7 @@ rustc_queries! {
586586
separate_provide_extern
587587
}
588588

589-
query mir_coroutine_witnesses(key: DefId) -> &'tcx Option<mir::CoroutineLayout<'tcx>> {
589+
query mir_coroutine_witnesses(key: DefId) -> Option<&'tcx mir::CoroutineLayout<'tcx>> {
590590
arena_cache
591591
desc { |tcx| "coroutine witness types for `{}`", tcx.def_path_str(key) }
592592
cache_on_disk_if { key.is_local() }
@@ -2415,7 +2415,7 @@ rustc_queries! {
24152415
/// because the `ty::Ty`-based wfcheck is always run.
24162416
query diagnostic_hir_wf_check(
24172417
key: (ty::Predicate<'tcx>, WellFormedLoc)
2418-
) -> &'tcx Option<ObligationCause<'tcx>> {
2418+
) -> Option<&'tcx ObligationCause<'tcx>> {
24192419
arena_cache
24202420
eval_always
24212421
no_hash

0 commit comments

Comments
 (0)