Zulip Chat Archive

Stream: lean4

Topic: How to get the imports for a given module?


Yuri de Wit (Nov 10 2022 at 18:16):

From the Environment, I can get the names of all modules, but how can I get the direct imports for a given module?

Mario Carneiro (Nov 10 2022 at 18:35):

I don't think this information is stored in the environment. You can call Lean.Elab.parseImports given a lean file to get the list of imports

Yuri de Wit (Nov 10 2022 at 18:43):

It turns out I had overlooked ModuleData from the EnvironmentHeader:

  for modName in env.allImportedModuleNames do
    let .some modIdx := env.getModuleIdx? modName | panic! s!"Unknown module {modName}"
    let modData := env.header.moduleData.get! modIdx
    for imp in modData.imports do
      dbg_trace s!"{modName} -> {imp}"

Last updated: Dec 20 2023 at 11:08 UTC