Drop the scaffolding an extracted file has no use for - #1
Merged
Merged
Conversation
Extracting one declaration out of a module replays that module's context commands, and until now a `section`/`namespace` block survived whenever it held a `set_option` — so every per-section option preamble in the source came through, declarations or not. The namespace stubs were worse: they were collected from every `namespace`/`open` in the contributing modules *before filtering*, so a target keeping a handful of declarations still asked for a stub for every namespace the module enters. On a project that puts a whole development in one file this dominates the output. `MetricCodes.Spherical.HigherHierarchy.main_general` in ten-proofs extracted to 3237 lines for one theorem: 780 lines of namespace stubs and 440 `noncomputable section`/`set_option`/`end` blocks with nothing inside them. It is now 163 lines, and the corpus as a whole goes from 18.2M lines to 1.10M. Three changes: * `set_option` and `universe` join `variable`/`open` as `soft`. All four are scoped to their block, so a block holding nothing else has nothing left to act on and is dropped with them. * Output chunks become `OutChunk`, carrying the namespaces each chunk needs. `stripEmptyScopes` returns the surviving chunks and the stub list is read off those, so a namespace no surviving line mentions is not stubbed. `open … in <decl>` prefixes now contribute a stub too, which they did not before. * `dropRedundantOptions` removes `set_option` lines with no observable effect: re-setting a value already in effect (tracked on a stack that pops with each `end`, as Lean scopes it), and a setting immediately superseded by another of the same option. Also fixes the root module's banner rendering as `-- ═══ ═══`. Measured against the three corpora in KNOWN-ISSUES.md, comparing each changed file before and after: brownian-motion 632 files differ, 632/632 compile both ways; LML 291 differ, 707/709 both ways; alpha-rar 28 differ, 28/28 both ways. No file grew except one in brownian-motion, which gains the two-line stub the new `open … in` handling supplies. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracting one declaration out of a module replays that module's context commands, and until now a
section/namespaceblock survived whenever it held aset_option— so every per-section option preamble in the source came through, declarations or not. The namespace stubs were worse: they were collected from everynamespace/openin the contributing modules before filtering, so a target keeping a handful of declarations still asked for a stub for every namespace the module enters.On a project that puts a whole development in one file this dominates the output.
MetricCodes.Spherical.HigherHierarchy.main_generalin ten-proofs extracted to 3237 lines for one theorem: 780 lines of namespace stubs and 440noncomputable section/set_option/endblocks with nothing inside them. It is now 163 lines, and the corpus as a whole goes from 18.2M lines to 1.10M.Three changes:
set_optionanduniversejoinvariable/openassoft. All four are scoped to their block, so a block holding nothing else has nothing left to act on and is dropped with them.Output chunks become
OutChunk, carrying the namespaces each chunk needs.stripEmptyScopesreturns the surviving chunks and the stub list is read off those, so a namespace no surviving line mentions is not stubbed.open … in <decl>prefixes now contribute a stub too, which they did not before.dropRedundantOptionsremovesset_optionlines with no observable effect: re-setting a value already in effect (tracked on a stack that pops with eachend, as Lean scopes it), and a setting immediately superseded by another of the same option.Also fixes the root module's banner rendering as
-- ═══ ═══.Measured against the three corpora in KNOWN-ISSUES.md, comparing each changed file before and after: brownian-motion 632 files differ, 632/632 compile both ways; LML 291 differ, 707/709 both ways; alpha-rar 28 differ, 28/28 both ways. No file grew except one in brownian-motion, which gains the two-line stub the new
open … inhandling supplies.