Skip to content

Commit 41f7692

Browse files
pierwillwooster0cjgillot
committed
Document all public items in rustc_incremental
Also: - Review and edit current docs - Enforce documentation for crate Co-authored-by: r00ster <r00ster91@protonmail.com> Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
1 parent bc9326d commit 41f7692

File tree

7 files changed

+63
-13
lines changed

7 files changed

+63
-13
lines changed

compiler/rustc_incremental/src/assert_dep_graph.rs

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use std::env;
5252
use std::fs::{self, File};
5353
use std::io::{BufWriter, Write};
5454

55+
#[allow(missing_docs)]
5556
pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
5657
tcx.dep_graph.with_ignore(|| {
5758
if tcx.sess.opts.debugging_opts.dump_dep_graph {
@@ -262,6 +263,7 @@ fn dump_graph(query: &DepGraphQuery) {
262263
}
263264
}
264265

266+
#[allow(missing_docs)]
265267
pub struct GraphvizDepGraph<'q>(FxHashSet<&'q DepNode>, Vec<(&'q DepNode, &'q DepNode)>);
266268

267269
impl<'a, 'q> dot::GraphWalk<'a> for GraphvizDepGraph<'q> {

compiler/rustc_incremental/src/assert_module_sources.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_session::cgu_reuse_tracker::*;
2929
use rustc_span::symbol::{sym, Symbol};
3030
use std::collections::BTreeSet;
3131

32+
#[allow(missing_docs)]
3233
pub fn assert_module_sources(tcx: TyCtxt<'_>) {
3334
tcx.dep_graph.with_ignore(|| {
3435
if tcx.sess.opts.incremental.is_none() {

compiler/rustc_incremental/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Support for serializing the dep-graph and reloading it.
22
3+
#![deny(missing_docs)]
34
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
45
#![feature(in_band_lifetimes)]
56
#![feature(let_else)]

compiler/rustc_incremental/src/persist/fs.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,26 @@ const QUERY_CACHE_FILENAME: &str = "query-cache.bin";
133133
// case-sensitive (as opposed to base64, for example).
134134
const INT_ENCODE_BASE: usize = base_n::CASE_INSENSITIVE;
135135

136+
/// Returns the path to a session's dependency graph.
136137
pub fn dep_graph_path(sess: &Session) -> PathBuf {
137138
in_incr_comp_dir_sess(sess, DEP_GRAPH_FILENAME)
138139
}
140+
/// Returns the path to a session's staging dependency graph.
141+
///
142+
/// On the difference between dep-graph and staging dep-graph,
143+
/// see `build_dep_graph`.
139144
pub fn staging_dep_graph_path(sess: &Session) -> PathBuf {
140145
in_incr_comp_dir_sess(sess, STAGING_DEP_GRAPH_FILENAME)
141146
}
142-
143147
pub fn work_products_path(sess: &Session) -> PathBuf {
144148
in_incr_comp_dir_sess(sess, WORK_PRODUCTS_FILENAME)
145149
}
146-
150+
/// Returns the path to a session's query cache.
147151
pub fn query_cache_path(sess: &Session) -> PathBuf {
148152
in_incr_comp_dir_sess(sess, QUERY_CACHE_FILENAME)
149153
}
150154

155+
/// Locks a given session directory.
151156
pub fn lock_file_path(session_dir: &Path) -> PathBuf {
152157
let crate_dir = session_dir.parent().unwrap();
153158

@@ -166,23 +171,35 @@ pub fn lock_file_path(session_dir: &Path) -> PathBuf {
166171
crate_dir.join(&directory_name[0..dash_indices[2]]).with_extension(&LOCK_FILE_EXT[1..])
167172
}
168173

174+
/// Returns the path for a given filename within the incremental compilation directory
175+
/// in the current session.
169176
pub fn in_incr_comp_dir_sess(sess: &Session, file_name: &str) -> PathBuf {
170177
in_incr_comp_dir(&sess.incr_comp_session_dir(), file_name)
171178
}
172179

180+
/// Returns the path for a given filename within the incremental compilation directory,
181+
/// not necessarily from the current session.
182+
///
183+
/// To ensure the file is part of the current session, use [`in_incr_comp_dir_sess`].
173184
pub fn in_incr_comp_dir(incr_comp_session_dir: &Path, file_name: &str) -> PathBuf {
174185
incr_comp_session_dir.join(file_name)
175186
}
176187

177-
/// Allocates the private session directory. The boolean in the Ok() result
178-
/// indicates whether we should try loading a dep graph from the successfully
179-
/// initialized directory, or not.
180-
/// The post-condition of this fn is that we have a valid incremental
181-
/// compilation session directory, if the result is `Ok`. A valid session
188+
/// Allocates the private session directory.
189+
///
190+
/// If the result of this function is `Ok`, we have a valid incremental
191+
/// compilation session directory. A valid session
182192
/// directory is one that contains a locked lock file. It may or may not contain
183193
/// a dep-graph and work products from a previous session.
184-
/// If the call fails, the fn may leave behind an invalid session directory.
194+
///
195+
/// This always attempts to load a dep-graph from the directory.
196+
/// If loading fails for some reason, we fallback to a disabled `DepGraph`.
197+
/// See [`rustc_interface::queries::dep_graph`].
198+
///
199+
/// If this function returns an error, it may leave behind an invalid session directory.
185200
/// The garbage collection will take care of it.
201+
///
202+
/// [`rustc_interface::queries::dep_graph`]: ../../rustc_interface/struct.Queries.html#structfield.dep_graph
186203
pub fn prepare_session_directory(
187204
sess: &Session,
188205
crate_name: &str,
@@ -661,6 +678,7 @@ fn is_old_enough_to_be_collected(timestamp: SystemTime) -> bool {
661678
timestamp < SystemTime::now() - Duration::from_secs(10)
662679
}
663680

681+
/// Runs garbage collection for the current session.
664682
pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
665683
debug!("garbage_collect_session_directories() - begin");
666684

compiler/rustc_incremental/src/persist/load.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@ use super::work_product;
1818
type WorkProductMap = FxHashMap<WorkProductId, WorkProduct>;
1919

2020
#[derive(Debug)]
21+
/// Represents the result of an attempt to load incremental compilation data.
2122
pub enum LoadResult<T> {
22-
Ok { data: T },
23+
/// Loading was successful.
24+
Ok {
25+
#[allow(missing_docs)]
26+
data: T,
27+
},
28+
/// The file either didn't exist or was produced by an incompatible compiler version.
2329
DataOutOfDate,
24-
Error { message: String },
30+
/// An error occured.
31+
Error {
32+
#[allow(missing_docs)]
33+
message: String,
34+
},
2535
}
2636

2737
impl<T: Default> LoadResult<T> {
38+
/// Accesses the data returned in [`LoadResult::Ok`].
2839
pub fn open(self, sess: &Session) -> T {
2940
// Check for errors when using `-Zassert-incremental-state`
3041
match (sess.opts.assert_incr_state, &self) {
@@ -99,6 +110,7 @@ pub enum MaybeAsync<T> {
99110
}
100111

101112
impl<T> MaybeAsync<LoadResult<T>> {
113+
/// Accesses the data returned in [`LoadResult::Ok`] in an asynchronous way if possible.
102114
pub fn open(self) -> LoadResult<T> {
103115
match self {
104116
MaybeAsync::Sync(result) => result,
@@ -109,6 +121,7 @@ impl<T> MaybeAsync<LoadResult<T>> {
109121
}
110122
}
111123

124+
/// An asynchronous type for computing the dependency graph.
112125
pub type DepGraphFuture = MaybeAsync<LoadResult<(SerializedDepGraph, WorkProductMap)>>;
113126

114127
/// Launch a thread and load the dependency graph in the background.

compiler/rustc_incremental/src/persist/save.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ use super::file_format;
1313
use super::fs::*;
1414
use super::work_product;
1515

16-
/// Save and dump the DepGraph.
16+
/// Saves and writes the [`DepGraph`] to the file system.
1717
///
18-
/// No query must be invoked after this function.
18+
/// This function saves both the dep-graph and the query result cache,
19+
/// and drops the result cache.
20+
///
21+
/// This function should only run after all queries have completed.
22+
/// Trying to execute a query afterwards would attempt to read the result cache we just dropped.
1923
pub fn save_dep_graph(tcx: TyCtxt<'_>) {
2024
debug!("save_dep_graph()");
2125
tcx.dep_graph.with_ignore(|| {
@@ -75,6 +79,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
7579
})
7680
}
7781

82+
/// Saves the work product index.
7883
pub fn save_work_product_index(
7984
sess: &Session,
8085
dep_graph: &DepGraph,
@@ -139,6 +144,12 @@ fn encode_query_cache(tcx: TyCtxt<'_>, encoder: &mut FileEncoder) -> FileEncodeR
139144
tcx.sess.time("incr_comp_serialize_result_cache", || tcx.serialize_query_result_cache(encoder))
140145
}
141146

147+
/// Builds the dependency graph.
148+
///
149+
/// This function breates the *staging dep-graph*. When the dep-graph is modified by a query
150+
/// execution, the new dependency information is not kept in memory but directly
151+
/// output to this file. `save_dep_graph` then finalizes the staging dep-graph
152+
/// and moves it to the permanent dep-graph path
142153
pub fn build_dep_graph(
143154
sess: &Session,
144155
prev_graph: SerializedDepGraph,

compiler/rustc_incremental/src/persist/work_product.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! This module contains files for saving intermediate work-products.
1+
//! Functions for saving and removing intermediate [work products].
2+
//!
3+
//! [work products]: WorkProduct
24
35
use crate::persist::fs::*;
46
use rustc_fs_util::link_or_copy;
@@ -7,6 +9,7 @@ use rustc_session::Session;
79
use std::fs as std_fs;
810
use std::path::PathBuf;
911

12+
/// Copies a CGU work product to the incremental compilation directory, so next compilation can find and reuse it.
1013
pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
1114
sess: &Session,
1215
cgu_name: &str,
@@ -40,6 +43,7 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
4043
Some((work_product_id, work_product))
4144
}
4245

46+
/// Removes files for a given work product.
4347
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
4448
if let Some(ref file_name) = work_product.saved_file {
4549
let path = in_incr_comp_dir_sess(sess, file_name);

0 commit comments

Comments
 (0)