2021-01-19 13:40:16 -06:00
|
|
|
//! Support for serializing the dep-graph and reloading it.
|
|
|
|
|
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
|
|
|
#![feature(min_specialization)]
|
Use delayed error handling for `Encodable` and `Encoder` infallible.
There are two impls of the `Encoder` trait: `opaque::Encoder` and
`opaque::FileEncoder`. The former encodes into memory and is infallible, the
latter writes to file and is fallible.
Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a
bit verbose and has non-trivial cost, which is annoying given how rare failures
are (especially in the infallible `opaque::Encoder` case).
This commit changes how `Encoder` fallibility is handled. All the `emit_*`
methods are now infallible. `opaque::Encoder` requires no great changes for
this. `opaque::FileEncoder` now implements a delayed error handling strategy.
If a failure occurs, it records this via the `res` field, and all subsequent
encoding operations are skipped if `res` indicates an error has occurred. Once
encoding is complete, the new `finish` method is called, which returns a
`Result`. In other words, there is now a single `Result`-producing method
instead of many of them.
This has very little effect on how any file errors are reported if
`opaque::FileEncoder` has any failures.
Much of this commit is boring mechanical changes, removing `Result` return
values and `?` or `unwrap` from expressions. The more interesting parts are as
follows.
- serialize.rs: The `Encoder` trait gains an `Ok` associated type. The
`into_inner` method is changed into `finish`, which returns
`Result<Vec<u8>, !>`.
- opaque.rs: The `FileEncoder` adopts the delayed error handling
strategy. Its `Ok` type is a `usize`, returning the number of bytes
written, replacing previous uses of `FileEncoder::position`.
- Various methods that take an encoder now consume it, rather than being
passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-06 22:30:45 -05:00
|
|
|
#![feature(never_type)]
|
2021-06-28 14:12:01 -05:00
|
|
|
#![feature(once_cell)]
|
2021-01-19 13:40:16 -06:00
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
#![recursion_limit = "256"]
|
2022-02-23 07:06:22 -06:00
|
|
|
#![allow(rustc::potential_query_instability)]
|
2022-08-18 13:27:29 -05:00
|
|
|
#![deny(rustc::untranslatable_diagnostic)]
|
|
|
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
2021-01-19 13:40:16 -06:00
|
|
|
|
2021-06-28 14:12:01 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_macros;
|
2021-01-19 13:40:16 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_middle;
|
|
|
|
|
2022-02-07 10:03:51 -06:00
|
|
|
use rustc_data_structures::sync::AtomicU64;
|
2021-10-16 14:12:34 -05:00
|
|
|
use rustc_middle::arena::Arena;
|
2022-09-01 22:20:17 -05:00
|
|
|
use rustc_middle::dep_graph::{self, DepKindStruct};
|
2021-01-19 13:40:16 -06:00
|
|
|
use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values};
|
2021-05-30 10:24:54 -05:00
|
|
|
use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine};
|
2020-12-26 09:36:55 -06:00
|
|
|
use rustc_middle::ty::{self, TyCtxt};
|
2022-03-28 12:53:01 -05:00
|
|
|
use rustc_span::def_id::{LocalDefId, LOCAL_CRATE};
|
2020-11-02 13:05:10 -06:00
|
|
|
use rustc_span::Span;
|
2021-01-19 13:40:16 -06:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
mod plumbing;
|
|
|
|
pub use plumbing::QueryCtxt;
|
|
|
|
use rustc_query_system::query::*;
|
2022-06-28 21:02:30 -05:00
|
|
|
#[cfg(parallel_compiler)]
|
|
|
|
pub use rustc_query_system::query::{deadlock, QueryContext};
|
2021-01-19 13:40:16 -06:00
|
|
|
|
|
|
|
mod keys;
|
|
|
|
use keys::Key;
|
|
|
|
|
|
|
|
pub use rustc_query_system::query::QueryConfig;
|
2022-07-19 18:57:44 -05:00
|
|
|
pub(crate) use rustc_query_system::query::{QueryDescription, QueryVTable};
|
2021-01-19 13:40:16 -06:00
|
|
|
|
2021-06-28 14:12:01 -05:00
|
|
|
mod on_disk_cache;
|
|
|
|
pub use on_disk_cache::OnDiskCache;
|
2021-01-19 13:40:16 -06:00
|
|
|
|
|
|
|
mod profiling_support;
|
|
|
|
pub use self::profiling_support::alloc_self_profile_query_strings;
|
|
|
|
|
2021-10-17 10:37:20 -05:00
|
|
|
fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
|
|
|
|
if def_id.is_top_level_module() {
|
|
|
|
"top-level module".to_string()
|
|
|
|
} else {
|
|
|
|
format!("module `{}`", tcx.def_path_str(def_id.to_def_id()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 00:02:37 -05:00
|
|
|
rustc_query_append! { define_queries! }
|
2021-01-19 13:40:16 -06:00
|
|
|
|
|
|
|
impl<'tcx> Queries<'tcx> {
|
|
|
|
// Force codegen in the dyn-trait transformation in this crate.
|
|
|
|
pub fn as_dyn(&'tcx self) -> &'tcx dyn QueryEngine<'tcx> {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|