@@ -50,13 +50,19 @@ It returns just the imports of `fileContent`, including trailing comments if `ke
5050-/
5151def getHeader (fname fileContent : String) (keepTrailing : Bool) : IO String := do
5252 let (stx, _) ← Parser.parseHeader (Parser.mkInputContext fileContent fname)
53+ -- The first argument is a module token (if any).
54+ let isModule := !(stx.raw.getArg 0 ).getArgs.isEmpty
5355 let imports := stx.raw.getArg 2 -- extract just the imports list
5456 let imports := if keepTrailing then imports else imports.unsetTrailing
5557 -- Use `withLeading := false` to exclude leading comments (e.g. copyright header) that the
5658 -- parser now attaches to the first token (see leanprover/lean4#12662).
5759 let some substring := imports.getSubstring? (withLeading := false ) |
5860 throw <| .userError "No substring: we have a problem!"
59- return substring.toString
61+ -- This implementation is geared for to create a deprecated module:
62+ -- since imports there are unused by definition, we need to tell shake to keep them.
63+ -- For a general-purpose implementation, whether to add the `--keep-all` flag
64+ -- should be made configurable.
65+ return (if isModule then "module -- shake: keep-all\n\n " else "" ) ++ substring.toString
6066
6167/--
6268`getHeaderFromFileName fname keepTrailing` is similar to `getHeader`, except that it assumes that
@@ -161,6 +167,8 @@ def mkRenamesDict (percent : Nat := 100) : IO (Std.HashMap String String) := do
161167 and a similarity percentage.\n Full git line: '{ git} '"
162168 continue
163169 let some pctNat := (pct.drop 1 ).toNat? | continue
170+ -- We skip renames of files in `MathlibTest`.
171+ if oldName.startsWith "MathlibTest/" then continue
164172 -- This looks like a rename with a similarity index at least as big as our threshold:
165173 -- we add the rename to our dictionary.
166174 if percent ≤ pctNat then
@@ -233,10 +241,11 @@ def deprecateFilePath (fname : String) (rename comment : Option String) :
233241 -- Retrieve the final version of the file, before it was deleted.
234242 let file ← runCmd s! "git show { modifiedHash} :{ fname} "
235243 -- Generate a module deprecation for the file `fname`.
244+ -- As mathlib uses the module system, it is fine to always generate a module.
236245 let fileHeader ← match rename with
237246 | some rename => do
238247 let modName := mkModName rename
239- pure s! "import { modName} "
248+ pure s! "module -- shake: keep-all \n\n public import { modName} "
240249 | none => getHeader fname file false
241250 let deprecatedFile := s! "{ fileHeader.trimAsciiEnd} \n\n { deprecation.pretty.trimAsciiEnd} \n "
242251 msgs := msgs.push <| .trace {cls := `Deprecation} m! "{ fname} " #[m! "\n { deprecatedFile} " ]
0 commit comments