Skip to content

Commit 3f802e0

Browse files
committed
state.cppm: restore PrepareState's doc comment, fix a stale one
The comment originally attached to the PrepareState struct definition stayed behind in prepare.cppm when the struct itself moved to state.cppm (it was written above the struct's enclosing namespace, not the struct itself), leaving state.cppm's copy undocumented. Restored, updated for the current file layout. Also fixed a comment that had gone stale during the P9/P11 split: fp/stdBmiPath/scan/report and their siblings are computed inside P9 (target_side.cpp) and P11 (scan.cpp) themselves, not inside P2's resolve_target_toolchain closure as an earlier commit's comment claimed. No code change; golden fixture diff against the baseline is empty.
1 parent a203bdb commit 3f802e0

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

‎src/build/prepare/state.cppm‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,26 @@ constexpr std::size_t kMainConsumer = static_cast<std::size_t>(-1);
264264
std::string url, refKind, ref;
265265
};
266266

267+
// PrepareState carries prepare_build's working state across the phases it
268+
// decomposes into (see the layout comment at the top of prepare.cppm). Each
269+
// phase is an ordinary function taking `PrepareState&`; the state itself is
270+
// constructed once, in driver.cpp's prepare_build(), and lives for the
271+
// whole call — including across a phase that stores a closure for a LATER
272+
// phase to call (resolve_target_toolchain, defined in toolchain.cpp's P2 and
273+
// called from its own P5): such a closure captures `state` itself rather
274+
// than individual locals, so it stays valid no matter which phase's stack
275+
// frame created it.
276+
//
277+
// A member exists here because some phase after the one that computes it
278+
// still reads it, or because a stored closure needs it to remain valid past
279+
// its own phase — several members exist ONLY for that second reason and are
280+
// never read by name from another phase (bootstrap_checked, kMainConsumer's
281+
// siblings). A value read and written within a single phase stays an
282+
// ordinary local in that phase's function body; it does not move here.
283+
//
284+
// Not copied: copying this by value would copy every dependency-graph and
285+
// plan structure prepare_build ever builds, silently, at whichever call
286+
// happened to pass it by value instead of by reference.
267287
struct PrepareState {
268288
PrepareState(bool print_fingerprint_, bool includeDevDeps_,
269289
std::vector<mcpp::manifest::Target> extraTargets_,
@@ -486,8 +506,8 @@ struct PrepareState {
486506
bool targetSideResolved = false;
487507
mcpp::modgraph::UsageRequirements targetSideUsage;
488508

489-
// ── computed inside resolve_target_toolchain (P2's closure), read by P9
490-
// and P13 well after that closure returns ───────────────────────────────
509+
// ── P9/P11: the module scan, its validation, and the fingerprint they
510+
// feed; read again by P13 (the plan, resolution.json) ───────────────────
491511
mcpp::toolchain::Fingerprint fp;
492512
std::filesystem::path stdBmiPath;
493513
std::filesystem::path stdObjectPath;

0 commit comments

Comments
 (0)