@@ -1078,12 +1078,15 @@ pub struct CookingMaterials {
10781078 pub path: PathBuf,
10791079 /// The summary key the rendered reading is filed under.
10801080 pub key: SummaryKey,
1081- /// **What the file's closure defines**, as the renderer's starting state.
1082- ///
1083- /// Composed from the index (`configuration_from_environment_and`) rather than taken from a translation unit, so a
1084- /// file no timeline holds — a header, which is most of them — can still be cooked. It used to be an
1085- /// `Arc<TranslationUnit>` and this field is why the change was worth making: see [`Session::render_a_cooked`].
1086- pub configuration: crate::preprocess::cooked::Configuration,
1081+ /// **The timeline whose view answers positionally**, when one covers the file — `FileMacros` over its
1082+ /// definitions, which is what the reading has always used where a unit exists.
1083+ pub unit: Option<std::sync::Arc<crate::TranslationUnit>>,
1084+ /// **The composed starting state**, for a file no timeline covers: `Over(configuration, seed)`.
1085+ ///
1086+ /// Two fields rather than one because they are not equivalent: a `MacroView` is a **position** in a walk,
1087+ /// so it answers `#define`s that arrive mid-file and directives that split a declaration; a materialised
1088+ /// `Configuration` is the state a file *starts* with. The walk stays preferred wherever it exists.
1089+ pub configuration: Option<crate::preprocess::cooked::Configuration>,
10871090 /// The file's own text.
10881091 pub text: String,
10891092 /// **The hash of that text**, which is what the commit compares the file's text against — see
@@ -6280,24 +6283,13 @@ impl<F: FileProvider + Clone> Session<F> {
62806283 } else {
62816284 None
62826285 };
6283- let configuration = match (&held, &walked) {
6284- (Some(unit), _) => {
6285- let view = unit.environment_of(&path)?;
6286- crate::preprocess::cooked::configuration_from_environment_and(
6287- &view,
6288- true,
6289- &mut parsed,
6290- )
6291- }
6292- (None, Some(unit)) => {
6293- let view = unit.environment_of(&path)?;
6294- crate::preprocess::cooked::configuration_from_environment_and(
6295- &view,
6296- true,
6297- &mut parsed,
6298- )
6299- }
6300- (None, None) => composed()?,
6286+ // **A timeline answers positionally and stays preferred**; the composed configuration is the fallback for a
6287+ // file no walk covers. Converting both to a `Configuration` was tried and is *not* equivalent: the two
6288+ // `semantic.rs` tests about a directive-split return type failed with it, because a materialised table is the
6289+ // state a file starts with rather than the state at each line.
6290+ let (unit, configuration) = match held.or(walked) {
6291+ Some(unit) => (Some(unit), None),
6292+ None => (None, Some(composed()?)),
63016293 };
63026294 drop(parsed);
63036295
@@ -6308,6 +6300,7 @@ impl<F: FileProvider + Clone> Session<F> {
63086300 Some(CookingMaterials {
63096301 path,
63106302 key,
6303+ unit,
63116304 configuration,
63126305 text,
63136306 text_hash,
@@ -6327,6 +6320,7 @@ impl<F: FileProvider + Clone> Session<F> {
63276320 let CookingMaterials {
63286321 path,
63296322 key,
6323+ unit,
63306324 configuration,
63316325 text,
63326326 text_hash,
@@ -6335,17 +6329,37 @@ impl<F: FileProvider + Clone> Session<F> {
63356329 } = materials;
63366330
63376331 let (tokens, _) = { cpp_parser::lex(text, &cpp_parser::LexerConfig::default()) };
6338- // **Two layers: what the file's closure defines, over what the compilation predefines.** `Over` is the
6339- // closure path's own answer to that question — see its note — and it is what makes a cook possible for a file
6340- // **no timeline holds**: the configuration is composed from the index (`configuration_from_environment_and`),
6341- // so a header is rendered in its includers' environment rather than not at all.
6332+ // **Two ways to start a rendering, and the walk's is the accurate one.**
6333+ //
6334+ // A `MacroView` is a *position* in a walk, so it answers a `#define` that arrives mid-file and a directive that
6335+ // splits a declaration — which is what a compiler sees, and what every reading this session built before this
6336+ // change used. It requires a **held translation unit**, and after phase 2 stopped building units for the pass no
6337+ // header had one: `include/techniques.h` came out `NOT COOKED` and the C++ corpus went 51/52 → 41/52 type
6338+ // answers. A capability that depends on a *cache* holding another file's timeline is not a capability, so when
6339+ // no walk covers the file its environment is **composed from the index**
6340+ // (`configuration_from_environment_and`, over the run's shared `ParsedDefinitions`) and rendered as
6341+ // `Over(configuration, seed)`.
63426342 //
6343- // It used to be `FileMacros::new(unit.environment_of(path)?, …)`, which required a **held translation unit** —
6344- // and after phase 2 stopped building units for the pass, cooking a header depended on some *other* file's
6345- // timeline happening to sit in the cache. Measured on the C++ corpus: the header came out `NOT COOKED`, and the
6346- // corpus went 51/52 → 41/52 type answers. Correctness must not depend on cache residency.
6347- let start = crate::preprocess::cooked::Over::new(&configuration.table, seed);
6348- let rendered = { crate::preprocess::cooked::cook_with(text, &tokens, &start).render() };
6343+ // **The fallback is not a substitute**, and the difference is measured: converting *both* to a `Configuration`
6344+ // failed the two `tests/semantic.rs` tests about a directive-split return type, because a materialised table is
6345+ // the state a file *starts* with rather than the state at each line.
6346+ let rendered = match (unit, configuration) {
6347+ (Some(unit), _) => {
6348+ let definitions = unit.definitions();
6349+ let macros = crate::preprocess::cooked::FileMacros::new(
6350+ unit.environment_of(path)?,
6351+ &definitions,
6352+ Some(seed),
6353+ true,
6354+ );
6355+ crate::preprocess::cooked::cook_with(text, &tokens, ¯os).render()
6356+ }
6357+ (None, Some(configuration)) => {
6358+ let start = crate::preprocess::cooked::Over::new(&configuration.table, seed);
6359+ crate::preprocess::cooked::cook_with(text, &tokens, &start).render()
6360+ }
6361+ (None, None) => return None,
6362+ };
63496363 let indexer = FileIndexer::new(&self.files, &self.config);
63506364 let indexed = indexer.index_rendering(path, &rendered, *key);
63516365 let reading = CookedReading {
0 commit comments