-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Eagerly compute output_filenames #117584
Eagerly compute output_filenames #117584
Changes from all commits
457dbbf
eacbe65
98a6eaa
4acaa02
7ede8e2
365a580
d7e9a30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,6 @@ pub struct Queries<'tcx> { | |
hir_arena: WorkerLocal<rustc_hir::Arena<'tcx>>, | ||
|
||
parse: Query<ast::Crate>, | ||
pre_configure: Query<(ast::Crate, ast::AttrVec)>, | ||
// This just points to what's in `gcx_cell`. | ||
gcx: Query<&'tcx GlobalCtxt<'tcx>>, | ||
} | ||
|
@@ -98,7 +97,6 @@ impl<'tcx> Queries<'tcx> { | |
arena: WorkerLocal::new(|_| Arena::default()), | ||
hir_arena: WorkerLocal::new(|_| rustc_hir::Arena::default()), | ||
parse: Default::default(), | ||
pre_configure: Default::default(), | ||
gcx: Default::default(), | ||
} | ||
} | ||
|
@@ -113,12 +111,12 @@ impl<'tcx> Queries<'tcx> { | |
}) | ||
} | ||
|
||
#[deprecated = "pre_configure may be made private in the future. If you need it please open an issue with your use case."] | ||
pub fn pre_configure(&self) -> Result<QueryResult<'_, (ast::Crate, ast::AttrVec)>> { | ||
self.pre_configure.compute(|| { | ||
pub fn global_ctxt(&'tcx self) -> Result<QueryResult<'_, &'tcx GlobalCtxt<'tcx>>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
self.gcx.compute(|| { | ||
let sess = &self.compiler.sess; | ||
|
||
let mut krate = self.parse()?.steal(); | ||
|
||
let sess = &self.compiler.sess; | ||
rustc_builtin_macros::cmdline_attrs::inject( | ||
&mut krate, | ||
&sess.parse_sess, | ||
|
@@ -127,15 +125,6 @@ impl<'tcx> Queries<'tcx> { | |
|
||
let pre_configured_attrs = | ||
rustc_expand::config::pre_configure_attrs(sess, &krate.attrs); | ||
Ok((krate, pre_configured_attrs)) | ||
}) | ||
} | ||
|
||
pub fn global_ctxt(&'tcx self) -> Result<QueryResult<'_, &'tcx GlobalCtxt<'tcx>>> { | ||
self.gcx.compute(|| { | ||
let sess = &self.compiler.sess; | ||
#[allow(deprecated)] | ||
let (krate, pre_configured_attrs) = self.pre_configure()?.steal(); | ||
|
||
// parse `#[crate_name]` even if `--crate-name` was passed, to make sure it matches. | ||
let crate_name = find_crate_name(sess, &pre_configured_attrs); | ||
|
@@ -146,6 +135,7 @@ impl<'tcx> Queries<'tcx> { | |
sess.opts.cg.metadata.clone(), | ||
sess.cfg_version, | ||
); | ||
let outputs = util::build_output_filenames(&pre_configured_attrs, sess); | ||
let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id)?; | ||
|
||
let cstore = FreezeLock::new(Box::new(CStore::new( | ||
|
@@ -180,11 +170,19 @@ impl<'tcx> Queries<'tcx> { | |
crate_name, | ||
))); | ||
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs)))); | ||
feed.output_filenames(Arc::new(outputs)); | ||
}); | ||
Ok(qcx) | ||
}) | ||
} | ||
|
||
pub fn write_dep_info(&'tcx self) -> Result<()> { | ||
self.global_ctxt()?.enter(|tcx| { | ||
passes::write_dep_info(tcx); | ||
}); | ||
Ok(()) | ||
} | ||
|
||
/// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used | ||
/// to write UI tests that actually test that compilation succeeds without reporting | ||
/// an error. | ||
|
@@ -284,8 +282,13 @@ impl Linker { | |
|
||
if sess.opts.unstable_opts.no_link { | ||
let rlink_file = self.output_filenames.with_extension(config::RLINK_EXT); | ||
CodegenResults::serialize_rlink(sess, &rlink_file, &codegen_results) | ||
.map_err(|error| sess.emit_fatal(FailedWritingFile { path: &rlink_file, error }))?; | ||
CodegenResults::serialize_rlink( | ||
sess, | ||
&rlink_file, | ||
&codegen_results, | ||
&*self.output_filenames, | ||
) | ||
.map_err(|error| sess.emit_fatal(FailedWritingFile { path: &rlink_file, error }))?; | ||
return Ok(()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -580,7 +580,7 @@ pub enum ResolveDocLinks { | |
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break | ||
/// dependency tracking for command-line arguments. Also only hash keys, since tracking | ||
/// should only depend on the output types, not the paths they're written to. | ||
#[derive(Clone, Debug, Hash, HashStable_Generic)] | ||
#[derive(Clone, Debug, Hash, HashStable_Generic, Encodable, Decodable)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this cause us to leak host info into build artifacts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rlink file already contains absolute file paths. |
||
pub struct OutputTypes(BTreeMap<OutputType, Option<OutFileName>>); | ||
|
||
impl OutputTypes { | ||
|
@@ -818,7 +818,7 @@ impl Input { | |
} | ||
} | ||
|
||
#[derive(Clone, Hash, Debug, HashStable_Generic, PartialEq)] | ||
#[derive(Clone, Hash, Debug, HashStable_Generic, PartialEq, Encodable, Decodable)] | ||
pub enum OutFileName { | ||
Real(PathBuf), | ||
Stdout, | ||
|
@@ -890,7 +890,7 @@ impl OutFileName { | |
} | ||
} | ||
|
||
#[derive(Clone, Hash, Debug, HashStable_Generic)] | ||
#[derive(Clone, Hash, Debug, HashStable_Generic, Encodable, Decodable)] | ||
pub struct OutputFilenames { | ||
pub out_directory: PathBuf, | ||
/// Crate name. Never contains '-'. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use
ensure()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
resolver_for_lowering
weren'teval_always
and it is green, usingensure()
would mean that the side effects ofresolver_for_lowering
(adding the list of used files and env vars to theSession
) are not replayed as far as I understand it. Nowresolver_for_lowering
iseval_always
currently, so it shouldn't matter for now I guess. There shouldn't be any perf difference though asresolver_for_lowering
returns a reference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we maybe add a comment in the query definition explaining this, i.e. why this needs to be
eval_always
?