Skip to content

Commit bcc8b05

Browse files
committed
Make output_filenames a real query
1 parent abee613 commit bcc8b05

File tree

13 files changed

+92
-28
lines changed

13 files changed

+92
-28
lines changed

compiler/rustc_driver/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ fn run_compiler(
333333
return early_exit();
334334
}
335335

336+
queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
337+
336338
if sess.opts.output_types.contains_key(&OutputType::DepInfo)
337339
&& sess.opts.output_types.len() == 1
338340
{

compiler/rustc_interface/src/passes.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_data_structures::parallel;
1616
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
1717
use rustc_errors::{ErrorGuaranteed, PResult};
1818
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
19-
use rustc_hir::def_id::StableCrateId;
19+
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
2020
use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore};
2121
use rustc_metadata::creader::CStore;
2222
use rustc_middle::arena::Arena;
@@ -47,7 +47,7 @@ use std::marker::PhantomPinned;
4747
use std::path::{Path, PathBuf};
4848
use std::pin::Pin;
4949
use std::rc::Rc;
50-
use std::sync::LazyLock;
50+
use std::sync::{Arc, LazyLock};
5151
use std::{env, fs, iter};
5252

5353
pub fn parse<'a>(sess: &'a Session) -> PResult<'a, ast::Crate> {
@@ -660,13 +660,11 @@ fn write_out_deps(
660660
}
661661
}
662662

663-
pub fn prepare_outputs(
664-
sess: &Session,
665-
krate: &ast::Crate,
666-
cstore: &CrateStoreDyn,
667-
crate_name: Symbol,
668-
) -> Result<OutputFilenames> {
663+
fn output_filenames(tcx: TyCtxt<'_>, (): ()) -> Arc<OutputFilenames> {
664+
let sess = tcx.sess;
669665
let _timer = sess.timer("prepare_outputs");
666+
let (_, krate) = &*tcx.resolver_for_lowering(()).borrow();
667+
let crate_name = tcx.crate_name(LOCAL_CRATE);
670668

671669
// FIXME: rustdoc passes &[] instead of &krate.attrs here
672670
let outputs = util::build_output_filenames(&krate.attrs, sess);
@@ -678,45 +676,41 @@ pub fn prepare_outputs(
678676
if let Some(ref input_path) = sess.io.input.opt_path() {
679677
if sess.opts.will_create_output_file() {
680678
if output_contains_path(&output_paths, input_path) {
681-
let reported = sess.emit_err(InputFileWouldBeOverWritten { path: input_path });
682-
return Err(reported);
679+
sess.emit_fatal(InputFileWouldBeOverWritten { path: input_path });
683680
}
684681
if let Some(ref dir_path) = output_conflicts_with_dir(&output_paths) {
685-
let reported =
686-
sess.emit_err(GeneratedFileConflictsWithDirectory { input_path, dir_path });
687-
return Err(reported);
682+
sess.emit_fatal(GeneratedFileConflictsWithDirectory { input_path, dir_path });
688683
}
689684
}
690685
}
691686

692687
if let Some(ref dir) = sess.io.temps_dir {
693688
if fs::create_dir_all(dir).is_err() {
694-
let reported = sess.emit_err(TempsDirError);
695-
return Err(reported);
689+
sess.emit_fatal(TempsDirError);
696690
}
697691
}
698692

699-
write_out_deps(sess, cstore, &outputs, &output_paths);
693+
write_out_deps(sess, tcx.cstore_untracked(), &outputs, &output_paths);
700694

701695
let only_dep_info = sess.opts.output_types.contains_key(&OutputType::DepInfo)
702696
&& sess.opts.output_types.len() == 1;
703697

704698
if !only_dep_info {
705699
if let Some(ref dir) = sess.io.output_dir {
706700
if fs::create_dir_all(dir).is_err() {
707-
let reported = sess.emit_err(OutDirError);
708-
return Err(reported);
701+
sess.emit_fatal(OutDirError);
709702
}
710703
}
711704
}
712705

713-
Ok(outputs)
706+
outputs.into()
714707
}
715708

716709
pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
717710
let providers = &mut Providers::default();
718711
providers.analysis = analysis;
719712
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
713+
providers.output_filenames = output_filenames;
720714
proc_macro_decls::provide(providers);
721715
rustc_const_eval::provide(providers);
722716
rustc_middle::hir::provide(providers);

compiler/rustc_interface/src/queries.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,6 @@ impl<'tcx> Queries<'tcx> {
235235
tcx.arena.alloc(Steal::new((untracked_resolver_for_lowering, krate))),
236236
);
237237
feed.resolutions(tcx.arena.alloc(untracked_resolutions));
238-
239-
let outputs = passes::prepare_outputs(
240-
self.session(),
241-
&krate,
242-
&*untracked.cstore,
243-
crate_name,
244-
)?;
245-
feed.output_filenames(tcx.arena.alloc(std::sync::Arc::new(outputs)));
246238
feed.features_query(tcx.sess.features_untracked());
247239
let feed = tcx.feed_local_crate();
248240
feed.crate_name(crate_name);

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1862,9 +1862,10 @@ rustc_queries! {
18621862
///
18631863
/// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
18641864
/// has been destroyed.
1865-
query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1865+
query output_filenames(_: ()) -> Arc<OutputFilenames> {
18661866
feedable
18671867
desc { "getting output filenames" }
1868+
arena_cache
18681869
}
18691870

18701871
/// Do not call this query directly: invoke `normalize` instead.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
include ../../run-make-fulldeps/tools.mk
2+
3+
all:
4+
$(RUSTC) main.rs -o main.rs 2> $(TMPDIR)/file.stderr || echo "failed successfully"
5+
$(RUSTC) main.rs -o . 2> $(TMPDIR)/folder.stderr || echo "failed successfully"
6+
7+
ifdef RUSTC_BLESS_TEST
8+
cp "$(TMPDIR)"/file.stderr file.stderr
9+
cp "$(TMPDIR)"/folder.stderr folder.stderr
10+
else
11+
$(DIFF) file.stderr "$(TMPDIR)"/file.stderr
12+
$(DIFF) folder.stderr "$(TMPDIR)"/folder.stderr
13+
endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: ignoring --out-dir flag due to -o flag
2+
3+
error: the input file "main.rs" would be overwritten by the generated executable
4+
5+
error: aborting due to previous error; 1 warning emitted
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: ignoring --out-dir flag due to -o flag
2+
3+
error: the generated executable for the input file "main.rs" conflicts with the existing directory "."
4+
5+
error: aborting due to previous error; 1 warning emitted
6+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: ignoring --out-dir flag due to -o flag
2+
3+
error: the input file "main.rs" would be overwritten by the generated executable
4+
5+
error: aborting due to previous error; 1 warning emitted
6+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Issue #66530: We would ICE if someone compiled with `-o /dev/null`,
2+
// because we would try to generate auxiliary files in `/dev/` (which
3+
// at least the OS X file system rejects).
4+
//
5+
// An attempt to `-o` into a directory we cannot write into should indeed
6+
// be an error; but not an ICE.
7+
//
8+
// However, some folks run tests as root, which can write `/dev/` and end
9+
// up clobbering `/dev/null`. Instead we'll use a non-existent path, which
10+
// also used to ICE, but even root can't magically write there.
11+
12+
// compile-flags: -Z temps-dir=/does-not-exist/output
13+
14+
// The error-pattern check occurs *before* normalization, and the error patterns
15+
// are wildly different between build environments. So this is a cop-out (and we
16+
// rely on the checking of the normalized stderr output as our actual
17+
// "verification" of the diagnostic).
18+
19+
// error-pattern: error
20+
21+
// On Mac OS X, we get an error like the below
22+
// normalize-stderr-test "failed to write bytecode to /does-not-exist/output.non_ice_error_on_worker_io_fail.*" -> "io error modifying /does-not-exist/"
23+
24+
// On Linux, we get an error like the below
25+
// normalize-stderr-test "couldn't create a temp dir.*" -> "io error modifying /does-not-exist/"
26+
27+
// ignore-windows - this is a unix-specific test
28+
// ignore-emscripten - the file-system issues do not replicate here
29+
// ignore-wasm - the file-system issues do not replicate here
30+
// ignore-arm - the file-system issues do not replicate here, at least on armhf-gnu
31+
32+
#![crate_type = "lib"]
33+
#![cfg_attr(not(feature = "std"), no_std)]
34+
pub mod task {
35+
pub mod __internal {
36+
use crate::task::Waker;
37+
}
38+
pub use core::task::Waker;
39+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: failed to find or create the directory specified by `--temps-dir`
2+
3+
error: aborting due to previous error
4+

0 commit comments

Comments
 (0)