rust/compiler/rustc_query_impl/src/lib.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
2.1 KiB
Rust
Raw Normal View History

//! Support for serializing the dep-graph and reloading it.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
// this shouldn't be necessary, but the check for `&mut _` is too naive and denies returning a function pointer that takes a mut ref
#![feature(const_mut_refs)]
#![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)]
#![feature(rustc_attrs)]
#![recursion_limit = "256"]
2022-02-23 07:06:22 -06:00
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
#[macro_use]
extern crate rustc_middle;
2023-03-25 03:46:19 -05:00
use crate::plumbing::{encode_all_query_results, try_mark_green};
2021-10-16 14:12:34 -05:00
use rustc_middle::arena::Arena;
2023-02-07 01:32:30 -06:00
use rustc_middle::dep_graph::{self, DepKind, DepKindStruct};
use rustc_middle::query::erase::{erase, restore, Erase};
2023-03-13 17:11:07 -05:00
use rustc_middle::query::AsLocalKey;
use rustc_middle::ty::query::{
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
};
2023-03-25 03:46:19 -05:00
use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine, QuerySystemFns};
use rustc_middle::ty::TyCtxt;
2023-02-07 01:32:30 -06:00
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
use rustc_query_system::Value;
2020-11-02 13:05:10 -06:00
use rustc_span::Span;
#[macro_use]
mod plumbing;
2023-03-25 03:46:19 -05:00
pub use crate::plumbing::QueryCtxt;
pub use rustc_query_system::query::QueryConfig;
2023-03-25 03:46:19 -05:00
use rustc_query_system::query::*;
mod profiling_support;
pub use self::profiling_support::alloc_self_profile_query_strings;
2023-03-26 05:24:44 -05:00
/// This is implemented per query and restoring query values from their erased state.
trait QueryConfigRestored<'tcx>: QueryConfig<QueryCtxt<'tcx>> + Default {
type RestoredValue;
2023-02-07 01:32:30 -06:00
2023-03-26 05:24:44 -05:00
fn restore(value: <Self as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue;
2023-02-07 01:32:30 -06:00
}
rustc_query_append! { define_queries! }
2023-03-25 03:46:19 -05:00
pub fn query_system_fns<'tcx>(
local_providers: Providers,
extern_providers: ExternProviders,
) -> QuerySystemFns<'tcx> {
QuerySystemFns {
engine: engine(),
local_providers,
extern_providers,
query_structs: make_dep_kind_array!(query_structs).to_vec(),
encode_query_results: encode_all_query_results,
try_mark_green: try_mark_green,
}
}