fix: revert state on compilation failure (new compiler) (#8691)

This PR ensures that the state is reverted when compilation using the
new compiler fails. This is especially important for noncomputable
sections where the compiler might generate half-compiled functions which
may then be erroneously used while compiling other functions.
This commit is contained in:
Rob23oba 2025-07-02 05:42:00 +02:00 committed by GitHub
parent 4a539715c8
commit e6954b7837
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -718,9 +718,14 @@ where doCompile := do
return
let opts ← getOptions
if compiler.enableNew.get opts then
withoutExporting
try compileDeclsNew decls catch e =>
if logErrors then throw e else return ()
withoutExporting do
let state ← Core.saveState
try
compileDeclsNew decls
catch e =>
state.restore
if logErrors then
throw e
else
let res ← withTraceNode `compiler (fun _ => return m!"compiling old: {decls}") do
return compileDeclsOld (← getEnv) opts decls