Skip to content

throwNestedTacticEx silences runtime errors #7811

@eric-wieser

Description

@eric-wieser

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

Recursion depth errors are silenced inconsistently by tactics, and as a result are sometimes caught by try and sometimes not.

Context

Non-erroring tactic behavior should not depend on resource constraints such as heartbeats or recursion depth limits, as these are implementation details that can change between systems and in tactic refactoring.

As the decision has already been made for try to not to catch such errors, other tactics should certainly not do so when catching and rethrowing errors.

Steps to Reproduce

Run

import Lean

set_option maxRecDepth 200 -- low to make this fast

example : 1 = sorry := by
  -- recursion depth error is silenced (bad)
  try simp [← Nat.add_zero 1]
  -- recursion depth error is not silenced (good)
  try repeat rw [← Nat.add_zero 1]
  sorry

Expected behavior: Both trys should result in non-silenced recursion depth errors

Actual behavior: Only the second one is

Versions

Lean 4.19.0-rc2
Target: x86_64-unknown-linux-gnu

Additional Information

The cause of this is the following lines, which discard the top-level .tagged `runtime.* part of the message

tryCatchRuntimeEx
(simp e)
fun ex => do
reportDiag (← get).diag
if ex.isRuntime then
throwNestedTacticEx `simp ex
else
throw ex

which are read by

lean4/src/Lean/CoreM.lean

Lines 514 to 519 in fafd381

/--
Return true if `ex` was generated by `throwMaxHeartbeat`.
This function is a bit hackish. The heartbeat exception should probably be an internal exception.
We used a similar hack at `Exception.isMaxRecDepth` -/
def Exception.isMaxHeartbeat (ex : Exception) : Bool :=
ex matches Exception.error _ (.tagged `runtime.maxHeartbeats _)

See also leanprover-community/aesop#211

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-mediumWe may work on this issue if we find the timebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions