fix(generate): skip leading copyright block in import prelude#467
Draft
BoltonBailey wants to merge 1 commit into
Draft
fix(generate): skip leading copyright block in import prelude#467BoltonBailey wants to merge 1 commit into
BoltonBailey wants to merge 1 commit into
Conversation
`importPreludeLength` only consumed leading `import` and blank lines, so for source files using Mathlib's copyright-then-import layout it returned 0. `renderChallengeDepsCore` then sliced the body from offset 0 and — on the kept-declarations path, which (unlike the local-imports path) never calls `stripProblemMarkers` — copied the copyright block and `import EvalTools.Markers` into the generated `ChallengeDeps.lean`. The standalone (Mathlib-only) workspace then failed to build with `unknown module prefix 'EvalTools'`. Skip a leading block comment that precedes the first `import` line (nesting-aware), so the copyright header is treated as part of the prelude. Comments after an import are left untouched, so the existing import-first files generate identically (verified: `generate --check` reports no changes on the committed problems; regenerating a copyright- first problem now produces a clean `ChallengeDeps.lean`). Co-Authored-By: Claude Opus 4.8 <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.
Disclaimer: Claude identified this as an issue as I was asking it to assemble another PR, which included files with both copyright headers and definitional dependencies to the main theorem. I asked Claude to write and PR this fix - it wrote it itself but I have checked it over and it looks OK to me.
Claude's description of the problem below:
Problem
generateproduces a standalone, Mathlib-only workspace per problem. When a problem has a same-module helper declaration (a non-hole dependency), the helper is factored intoChallengeDeps.lean. That file must not importEvalTools.Markers(which doesn't exist in the standalone workspace).For source files that use Mathlib's copyright-block-then-imports layout, the generated
ChallengeDeps.leaninstead retained the copyright block andimport EvalTools.Markers, so the workspace failed to build:Root cause
importPreludeLengthonly consumed leadingimport/blank lines, so a leading/- … -/copyright block made it return0.renderChallengeDepsCorethen sliced the body from offset0, and on the kept-declarations path (which, unlike the local-imports path, never callsstripProblemMarkers) the copyright block andimport EvalTools.Markerswere copied verbatim into the output.This only bites problems that are both copyright-first and have a non-hole same-module dependency (so a
ChallengeDeps.leanis generated at all). Import-first problems are unaffected, which is why it went unnoticed.Fix
Teach
importPreludeLengthto skip a leading block comment that precedes the firstimport(nesting-aware), treating the copyright header as part of the prelude. Comments appearing after an import are left untouched, so import-first files generate byte-identically.Verification
lake exe lean-eval generate --checkreports no changes to the committed (import-first) problems → no regression.anderson_theorem) now yields a cleanChallengeDeps.leanstarting withimport Mathlib/namespace AndersonTheorem, with noEvalToolsimport.🤖 Generated with Claude Code