Zulip Chat Archive

Stream: general

Topic: modifyEnv and environment extensions in v4.19.0


Joseph Tooby-Smith (May 06 2025 at 14:01):

As part of PhysLean we have TODO items which are collected using an enviroment extension set up with the following code:

Set up enviroment extension

An example of a TODO item in PhysLean is:

TODO "6VZJH" "For the classical harmonic oscillator find the velocity when it passes through
  zero."

There are many such items.

An example bit of code for collecting the TODO items is:

Collection code

The problem is that this no longer works. In particular let todoInfo := (todoExtension.getState env) returns an array of zero size. I believe this all worked fine on v4.18.0, in particular let todoInfo := (todoExtension.getState env) returned a non-zero array, and the code has not been modified since then.

Does anyone know the cause/ a possible solution?

Joseph Tooby-Smith (May 06 2025 at 14:25):

(suspect this is something related to #general > v4.19.0-rc2 @ 💬 )

David Renshaw (May 06 2025 at 14:33):

Try using Lean.importModules with loadExts := true. https://leanprover-community.github.io/mathlib4_docs/Lean/Environment.html#Lean.importModules

David Renshaw (May 06 2025 at 14:34):

... instead of withImortModules.

Joseph Tooby-Smith (May 06 2025 at 14:52):

Ok, thanks David, the following seems to work:

I changed:

unsafe def main (args : List String) : IO UInt32 := do
  initSearchPath ( findSysroot)
  println! "Checking for duplicate tags."
  let _  CoreM.withImportModules #[`PhysLean] (tagDuplicateTest).run'
  println! "Finish duplicate tag check."
  pure 0

to

open Core
unsafe def main (args : List String) : IO UInt32 := do
  initSearchPath ( findSysroot)
  println! "Checking for duplicate tags."
  let env  importModules (loadExts := true) #[`PhysLean] {} 0
  let fileName := ""
  let options : Options := {}
  let ctx : Core.Context := {fileName, options, fileMap := default }
  let state := {env}
  let _  (Lean.Core.CoreM.toIO · ctx state) do (tagDuplicateTest).run'
  println! "Finish duplicate tag check."
  pure 0

in my last code block. Not sure this is the cleanest way of doing things within the context of my overall code though, but this is ok.

(For my reference the PR which breaks this is this)


Last updated: Dec 20 2025 at 21:32 UTC