open Lean in #eval show CoreM Unit from do let env ← getEnv let mods := env.header.moduleNames let proj (m : Name) : Bool := m.getRoot == `NavierStokes || m.getRoot == `Euler let h ← IO.FS.Handle.mk "/out/decls.jsonl" IO.FS.Mode.write let mut n := 0 for (c, ci) in env.constants.map₁.toList do let some idx := env.getModuleIdxFor? c | continue let m := mods[idx.toNat]! unless proj m do continue let used := ci.getUsedConstantsAsSet.toList.filter fun u => match env.getModuleIdxFor? u with | some i => proj mods[i.toNat]! | none => false let rng ← findDeclarationRanges? c let r := match rng with | some r => "[" ++ toString r.range.pos.line ++ "," ++ toString r.range.endPos.line ++ "]" | none => "null" let kind := match ci with | .thmInfo _ => "theorem" | .defnInfo _ => "def" | .axiomInfo _ => "axiom" | .opaqueInfo _ => "opaque" | .inductInfo _ => "inductive" | .ctorInfo _ => "ctor" | .recInfo _ => "rec" | .quotInfo _ => "quot" let doc := (← findDocString? env c).getD "" h.putStrLn ("{\"n\":" ++ (toJson c.toString).compress ++ ",\"m\":" ++ (toJson m.toString).compress ++ ",\"k\":\"" ++ kind ++ "\",\"r\":" ++ r ++ ",\"d\":" ++ (toJson (doc.take 240)).compress ++ ",\"u\":" ++ (toJson (used.map (·.toString))).compress ++ "}") n := n + 1 IO.println s!"{n} constants written"