sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.59k stars 2.12k forks source link

Draft: Environment.file_to_rebuild: pickle to sorted `list` instead of `set` #12870

Closed jayaddison closed 1 month ago

jayaddison commented 2 months ago

Feature or Bugfix

Purpose

Detail

Relates

cc @bmwiedemann

bmwiedemann commented 2 months ago

I tried this patch on top of 8.0.2 and still got similar diffs: when comparing builds on 1-core-VM and 4-core-VM: https://rb.zq1.de/other/kernel-docs/kernel-source-compare.out

bmwiedemann commented 2 months ago

also note, that in the diff, not just the order changes, but whole blocks go missing.

jayaddison commented 2 months ago

Ok, thank you. I'd suggest we focus on one of the ToC entries that is entirely absent during one of the builds, and try to determine where that inclusion/exclusion originates. One opportunity for that is the Core API Documentation entry, I think.

jayaddison commented 2 months ago

My working theory in this branch was that the .doctree could be a causal link in the nondeterminism of the ToC trees; for the record there were three sources of nondeterminism in .doctree writing:

jayaddison commented 2 months ago

Ok, thank you. I'd suggest we focus on one of the ToC entries that is entirely absent during one of the builds, and try to determine where that inclusion/exclusion originates. One opportunity for that is the Core API Documentation entry, I think.

The findings at https://github.com/sphinx-doc/sphinx/issues/6714#issuecomment-2344865013 uncover more about what was happening there: basically, some elements in the HTML navigational menu are included/omitted based on build-time non-determinism.

On further inspection I note that env.numbered_toctrees also appears to be a factor in the traversal order of the toctree nodes. Perhaps it too may require item-order stabilization? (currently it appears to be stored in a Python set). Note that this is not necessarily the same as sorted / lexicographic order; sometimes there are reasons to retain a different ordering.

jayaddison commented 2 months ago

Ok, thank you. I'd suggest we focus on one of the ToC entries that is entirely absent during one of the builds, and try to determine where that inclusion/exclusion originates. One opportunity for that is the Core API Documentation entry, I think.

The findings at #6714 (comment) uncover more about what was happening there: basically, some elements in the HTML navigational menu are included/omitted based on build-time non-determinism.

On further inspection I note that env.numbered_toctrees also appears to be a factor in the traversal order of the toctree nodes. Perhaps it too may require item-order stabilization? (currently it appears to be stored in a Python set). Note that this is not necessarily the same as sorted / lexicographic order; sometimes there are reasons to retain a different ordering.

Nope; seems more likely to be env.glob_toctrees that's relevant here, now that I think about it; at least in the case of these navigation menu elements.

jayaddison commented 1 month ago

Closing; this changeset doesn't resolve the linked issue as-is, and I'm not currently aware of a pressing need to make the (intermediate output) .doctree files deterministic.