Skip to content

Commit 0cdfeb6

Browse files
committed
Add module-level doc comments to all printer submodules
Document the purpose and responsibilities of each submodule in the printer directory: mod.rs (overview table), collect.rs (three-phase pipeline), items.rs (Item construction), link_map.rs (function resolution), mir_visitor.rs (body traversal), schema.rs (data model), ty_visitor.rs (type collection), types.rs (TypeMetadata), and util.rs (helpers).
1 parent f7bd498 commit 0cdfeb6

File tree

9 files changed

+82
-0
lines changed

9 files changed

+82
-0
lines changed

src/printer/collect.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//! Three-phase collection pipeline.
2+
//!
3+
//! - [`collect_items`]: phase 1, enumerates monomorphized items from rustc
4+
//! - [`collect_and_analyze_items`]: phase 2, walks bodies with [`BodyAnalyzer`],
5+
//! discovering transitive items through unevaluated constants
6+
//! - [`assemble_smir`]: phase 3, pure data transformation into [`SmirJson`]
7+
//!
8+
//! The phase boundary between 2 and 3 is enforced by types: `assemble_smir`
9+
//! receives [`CollectedCrate`] and [`DerivedInfo`], neither of which carries
10+
//! `Instance` or `MonoItem` handles, so it structurally cannot call `inst.body()`.
11+
112
extern crate rustc_middle;
213
extern crate rustc_smir;
314
extern crate rustc_span;

src/printer/items.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//! Construction of [`Item`] values from monomorphized compiler items.
2+
//!
3+
//! Handles the mapping from `MonoItem` (function, static, or global asm) to the
4+
//! serializable [`Item`] structure, including optional debug-level details
5+
//! (instance kind, body pretty-print, generic parameters, internal type info)
6+
//! and foreign module enumeration.
7+
18
extern crate rustc_middle;
29
extern crate rustc_smir;
310
extern crate rustc_span;

src/printer/link_map.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! Link-time function resolution map.
2+
//!
3+
//! Maintains a mapping from function types (optionally qualified by instance kind)
4+
//! to their resolved symbol names. Entries are added from three sources:
5+
//! - `ITEM`: the function appears as a monomorphized item,
6+
//! - `TERM`: the function is called in a `Call` or `Drop` terminator,
7+
//! - `FPTR`: the function is referenced via a `ReifyFnPointer` cast or a
8+
//! zero-sized FnDef constant.
9+
110
extern crate rustc_middle;
211
extern crate rustc_smir;
312
extern crate stable_mir;

src/printer/mir_visitor.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
//! MIR body traversal for collecting interned values.
2+
//!
3+
//! [`BodyAnalyzer`] implements `MirVisitor` and walks each function body exactly
4+
//! once, collecting:
5+
//! - function calls and drop glue into the link map
6+
//! - global allocations (memory, statics, vtables, function pointers) with
7+
//! provenance type resolution via [`get_prov_ty`]
8+
//! - reachable types via the type visitor
9+
//! - source spans
10+
//!
11+
//! [`get_prov_ty`] recursively resolves the type of a pointer at a given byte
12+
//! offset within a struct or tuple, walking down through nested fields until it
13+
//! reaches the actual pointer type.
14+
115
extern crate rustc_middle;
216
extern crate rustc_smir;
317
extern crate rustc_span;

src/printer/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//! Serialization of Rust's Stable MIR to JSON.
2+
//!
3+
//! This module is the core of `stable-mir-json`: it collects monomorphized items,
4+
//! type metadata, allocations, and span information from the compiler, then
5+
//! serializes them into a [`SmirJson`] structure (emitted as `*.smir.json`).
6+
//!
7+
//! # Module structure
8+
//!
9+
//! | Module | Responsibility |
10+
//! |--------|----------------|
11+
//! | [`schema`] | Data model types ([`SmirJson`], [`Item`], [`AllocInfo`], etc.) and type aliases |
12+
//! | [`collect`] | Three-phase pipeline: collect items, analyze bodies, assemble final output |
13+
//! | [`items`] | Constructing [`Item`] values and extracting debug-level details |
14+
//! | [`mir_visitor`] | `BodyAnalyzer`: single-pass MIR traversal collecting calls, allocs, types, spans |
15+
//! | [`ty_visitor`] | Type visitor that recursively collects all reachable types with layout info |
16+
//! | [`link_map`] | Function resolution map: type + instance kind to symbol name |
17+
//! | [`types`] | Type helpers and [`TypeMetadata`](schema::TypeMetadata) construction |
18+
//! | [`util`] | Name resolution, attribute queries, and small collection utilities |
19+
120
use std::io::Write;
221
use std::{fs::File, io};
322

src/printer/schema.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Data model types for the `*.smir.json` output.
2+
//!
3+
//! Contains the top-level [`SmirJson`] structure and all supporting types:
4+
//! [`Item`], [`AllocMap`], [`AllocInfo`], [`TypeMetadata`], [`LinkMapKey`],
5+
//! [`FnSymType`], and serialization helpers.
6+
17
extern crate rustc_middle;
28
extern crate serde;
39
extern crate stable_mir;

src/printer/ty_visitor.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//! Recursive type visitor for collecting reachable types with layout info.
2+
//!
3+
//! [`TyCollector`] implements `stable_mir::visitor::Visitor` and traverses
4+
//! type trees, recording each encountered type along with its `TyKind` and
5+
//! `LayoutShape`. The collected types are later transformed into
6+
//! [`TypeMetadata`](super::schema::TypeMetadata) entries in the final output.
7+
18
extern crate rustc_middle;
29
extern crate rustc_smir;
310
extern crate stable_mir;

src/printer/types.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//! Type helpers and [`TypeMetadata`] construction.
2+
//!
3+
//! Provides utilities for working with `stable_mir` types: resolving function
4+
//! instances from types, checking for unresolved generics, and constructing
5+
//! [`TypeMetadata`](super::schema::TypeMetadata) entries from `TyKind` + layout
6+
//! for the final JSON output.
7+
18
extern crate rustc_middle;
29
extern crate rustc_smir;
310
extern crate stable_mir;

src/printer/util.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Small helpers: name resolution, attribute queries, and collection utilities.
2+
13
extern crate rustc_middle;
24
extern crate rustc_smir;
35
extern crate rustc_span;

0 commit comments

Comments
 (0)