Skip to content

Commit a87636c

Browse files
authored
Add missing docs for the rest of the code base (merge after #1026) (#1028)
This is the last PR for adding missing docs, and it closes #309. All the public items should be documented properly now, and `#![deny(missing_docs)]` is used so any new public item that does not have rustdoc will cause the build to fail.
1 parent b066199 commit a87636c

File tree

30 files changed

+149
-52
lines changed

30 files changed

+149
-52
lines changed

.github/scripts/ci-doc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# If the output path is changed in this script, we need to update rustdoc.yml as well.
55

66
# deny warnings for rustdoc
7-
export RUSTDOCFLAGS="-D warnings"
7+
export RUSTDOCFLAGS="-D warnings -D missing_docs"
88

99
# Check cargo doc
1010
# We document public and private items for MMTk developers (GC implementers).

docs/userguide/src/tutorial/code/mygc_semispace/global.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ pub struct MyGC<VM: VMBinding> {
4444
// ANCHOR: constraints
4545
pub const MYGC_CONSTRAINTS: PlanConstraints = PlanConstraints {
4646
moves_objects: true,
47-
gc_header_bits: 2,
48-
gc_header_words: 0,
49-
num_specialized_scans: 1,
5047
..PlanConstraints::default()
5148
};
5249
// ANCHOR_END: constraints

docs/userguide/src/tutorial/code/mygc_semispace/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// This module's code is unused When we compile this module with MMTk core. Allow it.
22
#![allow(dead_code)]
3+
// Allow missing docs for public items in this module.
4+
#![allow(missing_docs)]
35

46
mod gc_work; // Add
57
mod global;

docs/userguide/src/tutorial/mygc/ss/alloc.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ We will make the following changes:
1818

1919
1. Initialize `gc_header_bits` to 2. We reserve 2 bits in the header for GC use.
2020
1. Initialize `moves_objects` to `true`.
21-
1. Initialize `num_specialized_scans` to 1.
2221

2322
Finished code (step 1-3):
2423
```

src/build_info.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Some information for the current MMTk build.
2+
13
mod raw {
24
// This includes a full list of the constants in built.rs generated by the 'built' crate.
35
// https://docs.rs/built/latest/built/index.html

src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// TODO: We should fix missing docs for public items and turn this on (Issue #309).
2-
// #![deny(missing_docs)]
3-
41
// Allow this for now. Clippy suggests we should use Sft, Mmtk, rather than SFT and MMTK.
52
// According to its documentation (https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms),
63
// with upper-case-acronyms-aggressive turned on, it should also warn us about SFTMap, VMBinding, GCWorker.
@@ -69,4 +66,3 @@ pub mod vm;
6966
pub use crate::plan::{
7067
AllocationSemantics, BarrierSelector, Mutator, MutatorContext, ObjectQueue, Plan,
7168
};
72-
pub use crate::policy::copy_context::PolicyCopyContext;

src/memory_manager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ pub fn free_with_size<VM: VMBinding>(mmtk: &MMTK<VM>, addr: Address, old_size: u
434434
crate::util::malloc::free_with_size(mmtk, addr, old_size)
435435
}
436436

437+
/// Get the current active malloc'd bytes. Here MMTk only accounts for bytes that are done through those 'counted malloc' functions.
437438
#[cfg(feature = "malloc_counted_size")]
438439
pub fn get_malloc_bytes<VM: VMBinding>(mmtk: &MMTK<VM>) -> usize {
439440
mmtk.state.malloc_bytes.load(Ordering::SeqCst)

src/mmtk.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use crate::util::rust_util::InitializeOnce;
5050
// A global space function table that allows efficient dispatch space specific code for addresses in our heap.
5151
pub static SFT_MAP: InitializeOnce<Box<dyn SFTMap>> = InitializeOnce::new();
5252

53-
// MMTk builder. This is used to set options before actually creating an MMTk instance.
53+
/// MMTk builder. This is used to set options and other settings before actually creating an MMTk instance.
5454
pub struct MMTKBuilder {
5555
/// The options for this instance.
5656
pub options: Options,
@@ -131,7 +131,8 @@ unsafe impl<VM: VMBinding> Sync for MMTK<VM> {}
131131
unsafe impl<VM: VMBinding> Send for MMTK<VM> {}
132132

133133
impl<VM: VMBinding> MMTK<VM> {
134-
pub fn new(options: Arc<Options>) -> Self {
134+
/// Create an MMTK instance. This is not public. Bindings should use [`MMTKBuilder::build`].
135+
pub(crate) fn new(options: Arc<Options>) -> Self {
135136
// Initialize SFT first in case we need to use this in the constructor.
136137
// The first call will initialize SFT map. Other calls will be blocked until SFT map is initialized.
137138
crate::policy::sft_map::SFTRefStorage::pre_use_check();
@@ -219,6 +220,9 @@ impl<VM: VMBinding> MMTK<VM> {
219220
}
220221
}
221222

223+
/// Generic hook to allow benchmarks to be harnessed. MMTk will trigger a GC
224+
/// to clear any residual garbage and start collecting statistics for the benchmark.
225+
/// This is usually called by the benchmark harness as its last step before the actual benchmark.
222226
pub fn harness_begin(&self, tls: VMMutatorThread) {
223227
probe!(mmtk, harness_begin);
224228
self.handle_user_collection_request(tls, true, true);
@@ -227,6 +231,9 @@ impl<VM: VMBinding> MMTK<VM> {
227231
self.scheduler.enable_stat();
228232
}
229233

234+
/// Generic hook to allow benchmarks to be harnessed. MMTk will stop collecting
235+
/// statistics, and print out the collected statistics in a defined format.
236+
/// This is usually called by the benchmark harness right after the actual benchmark.
230237
pub fn harness_end(&'static self) {
231238
self.stats.stop_all(self);
232239
self.inside_harness.store(false, Ordering::SeqCst);
@@ -264,10 +271,12 @@ impl<VM: VMBinding> MMTK<VM> {
264271
}
265272
}
266273

274+
/// Return true if a collection is in progress.
267275
pub fn gc_in_progress(&self) -> bool {
268276
*self.state.gc_status.lock().unwrap() != GcStatus::NotInGC
269277
}
270278

279+
/// Return true if a collection is in progress and past the preparatory stage.
271280
pub fn gc_in_progress_proper(&self) -> bool {
272281
*self.state.gc_status.lock().unwrap() == GcStatus::GcProper
273282
}
@@ -338,6 +347,7 @@ impl<VM: VMBinding> MMTK<VM> {
338347
self.gc_requester.request();
339348
}
340349

350+
/// Get a reference to the plan.
341351
pub fn get_plan(&self) -> &dyn Plan<VM = VM> {
342352
unsafe { &**(self.plan.get()) }
343353
}
@@ -352,6 +362,7 @@ impl<VM: VMBinding> MMTK<VM> {
352362
&mut **(self.plan.get())
353363
}
354364

365+
/// Get the run time options.
355366
pub fn get_options(&self) -> &Options {
356367
&self.options
357368
}

src/plan/barriers.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ use downcast_rs::Downcast;
1717
/// VM bindings may also use this to enable the correct fast-path, if the fast-path is implemented in the binding.
1818
#[derive(Copy, Clone, Debug, PartialEq)]
1919
pub enum BarrierSelector {
20+
/// No barrier is used.
2021
NoBarrier,
22+
/// Object remembering barrier is used.
2123
ObjectBarrier,
2224
}
2325

2426
impl BarrierSelector {
27+
/// A const function to check if two barrier selectors are the same.
2528
pub const fn equals(&self, other: BarrierSelector) -> bool {
2629
// cast enum to u8 then compare. Otherwise, we cannot do it in a const fn.
2730
*self as u8 == other as u8

src/plan/generational/copying/global.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct GenCopy<VM: VMBinding> {
4040
pub copyspace1: CopySpace<VM>,
4141
}
4242

43+
/// The plan constraints for the generational copying plan.
4344
pub const GENCOPY_CONSTRAINTS: PlanConstraints = crate::plan::generational::GEN_CONSTRAINTS;
4445

4546
impl<VM: VMBinding> Plan for GenCopy<VM> {

0 commit comments

Comments
 (0)