Documentation

Lean.Elab.Tactic.Basic

def Lean.Elab.admitGoal (mvarId : MVarId) (synthetic : Bool := true) :

Assign mvarId := sorry

Instances For
    • elaborator : Name

      Declaration name of the executing elaborator, used by mkTacticInfo to persist it in the info tree

    • recover : Bool

      If true, enable "error recovery" in some tactics. For example, cases tactic admits unsolved alternatives when recover == true. The combinator withoutRecover <tac> disables "error recovery" while executing <tac>. This is useful for tactics such as first | ... | ....

    Instances For
      @[reducible, inline]

      The tactic monad, which extends the term elaboration monad TermElabM with state that contains the current goals (Lean.Elab.Tactic.State, accessible via MonadStateOf) and local information about the current tactic's name and whether error recovery is enabled (Lean.Elab.Tactic.Context, accessible via MonadReaderOf).

      Instances For
        @[reducible, inline]

        A tactic is a function from syntax to an action in the tactic monad.

        A given tactic syntax kind may have multiple Tactics associated with it, all of which will be attempted until one succeeds.

        Instances For
          @[implicit_reducible, always_inline]
          @[implicit_reducible]

          Returns the list of goals. Goals may or may not already be assigned.

          Instances For
            Instances For
              Instances For
                @[specialize #[]]

                Like Meta.withRestoreOrSaveFull for TermElabM, but also takes a tacSnap? that

                • when running act, is set as Context.tacSnap?
                • otherwise (i.e. on restore) is used to update the new snapshot promise to the old task's value. This extra restore step is necessary because while reusableResult? can be used to replay any effects on State, Context.tacSnap? is not part of it but changed via an IO side effect, so it needs to be replayed separately.

                We use an explicit parameter instead of accessing Context.tacSnap? directly because this prevents withRestoreOrSaveFull and withReader from being used in the wrong order.

                Instances For

                  Registers a tactic elaborator for the given syntax node kind.

                  A tactic elaborator should have type Lean.Elab.Tactic.Tactic (which is Lean.SyntaxLean.Elab.Tactic.TacticM Unit), i.e. should take syntax of the given syntax node kind as a parameter and alter the tactic state.

                  The elab_rules and elab commands should usually be preferred over using this attribute directly.

                  def Lean.Elab.Tactic.mkTacticInfo (mctxBefore : MetavarContext) (goalsBefore : List MVarId) (stx : Syntax) :
                  Instances For
                    @[inline]
                    Instances For

                      Important: we must define evalTactic before we define the instance MonadExcept for TacticM since it backtracks the state including error messages, and this is bad when rethrowing the exception at the catch block in these methods. We marked these places with a (*) in these methods.

                      Auxiliary datastructure for capturing exceptions at evalTactic.

                      Instances For
                        def Lean.Elab.Tactic.focus {α : Type} (x : TacticM α) :

                        Runs x with only the first unsolved goal as the goal. Fails if there are no goal to be solved.

                        Instances For
                          def Lean.Elab.Tactic.focusAndDone {α : Type} (tactic : TacticM α) :

                          Runs tactic with only the first unsolved goal as the goal, and expects it leave no goals. Fails if there are no goal to be solved.

                          Instances For

                            Close the main goal using the given tactic. If it fails, log the error and admit

                            Instances For
                              @[inline]
                              def Lean.Elab.Tactic.tryCatch {α : Type} (x : TacticM α) (h : ExceptionTacticM α) :

                              Non-backtracking try/catch.

                              Instances For
                                @[inline]

                                Backtracking try/catch. This is used for the MonadExcept instance for TacticM.

                                Instances For

                                  Execute x with error recovery disabled

                                  Instances For
                                    def Lean.Elab.Tactic.withRecover {α : Type} (recover : Bool) (x : TacticM α) :

                                    Execute x with error recovery disabled

                                    Instances For

                                      Message log utilities #

                                      Execute an action while suppressing any new messages it generates. Restores the original message log after the action completes. Useful for trying tactics without polluting the message log with errors from failed attempts.

                                      Instances For

                                        Execute an action and return any new messages it generates. Restores the original message log afterward. Useful for inspecting messages produced by a tactic without committing them.

                                        Instances For

                                          Check if any messages in the list are errors.

                                          Instances For

                                            Like throwErrorAt, but, if recovery is enabled, logs the error instead.

                                            Instances For

                                              Like throwError, but, if recovery is enabled, logs the error instead.

                                              Instances For
                                                @[inline]
                                                def Lean.Elab.Tactic.orElse {α : Type} (x : TacticM α) (y : UnitTacticM α) :
                                                Instances For
                                                  @[implicit_reducible]

                                                  Save the current tactic state for a token stx. This method is a no-op if stx has no position information. We use this method to save the tactic state at punctuation such as ;

                                                  Instances For
                                                    @[inline]
                                                    def Lean.Elab.Tactic.withMacroExpansion {α : Type} (beforeStx afterStx : Syntax) (x : TacticM α) :

                                                    Elaborate x with stx on the macro stack

                                                    Instances For

                                                      Adapt a syntax transformation to a regular tactic evaluator.

                                                      Instances For

                                                        Add the given goal to the front of the current list of goals.

                                                        Instances For

                                                          Add the given goals to the front of the current list of goals.

                                                          Instances For

                                                            Add the given goals at the end of the current list of goals.

                                                            Instances For

                                                              Discard the first goal and replace it by the given list of goals, keeping the other goals. This is used in conjunction with getMainGoal.

                                                              Contract: between getMainGoal and replaceMainGoal, nothing manipulates the goal list.

                                                              See also Lean.Elab.Tactic.popMainGoal and Lean.Elab.Tactic.pushGoal/Lean.Elab.Tactic.pushGoal for another interface.

                                                              Instances For

                                                                Return the first goal.

                                                                Instances For

                                                                  Return the first goal, and remove it from the goal list.

                                                                  See also: Lean.Elab.Tactic.pushGoal and Lean.Elab.Tactic.pushGoals.

                                                                  Instances For

                                                                    Return the main goal metavariable declaration.

                                                                    Instances For

                                                                      Return the main goal tag.

                                                                      Instances For

                                                                        Return expected type for the main goal.

                                                                        Instances For

                                                                          Execute x using the main goal local context and instances

                                                                          Instances For

                                                                            Evaluate tac at mvarId, and return the list of resulting subgoals.

                                                                            Instances For

                                                                              Like evalTacticAt, but without restoring the goal list or pruning solved goals. Useful when these tasks are already being done in an outer loop.

                                                                              Instances For
                                                                                def Lean.Elab.Tactic.closeMainGoal (tacName : Name) (val : Expr) (checkUnassigned : Bool := true) :

                                                                                Closes main goal using the given expression. If checkUnassigned == true, then val must not contain unassigned metavariables. Returns true if val was successfully used to close the goal.

                                                                                Instances For
                                                                                  @[inline]
                                                                                  Instances For
                                                                                    @[inline]
                                                                                    Instances For
                                                                                      @[inline]

                                                                                      Get the mvarid of the main goal, run the given tactic, then set the new goals to be the resulting goal list.

                                                                                      Instances For
                                                                                        @[inline]
                                                                                        Instances For
                                                                                          @[inline]

                                                                                          Analogue of liftMetaTactic for tactics that do not return any goals.

                                                                                          Instances For
                                                                                            def Lean.Elab.Tactic.tryTactic? {α : Type} (tactic : TacticM α) :
                                                                                            Instances For
                                                                                              Instances For
                                                                                                def Lean.Elab.Tactic.tagUntaggedGoals (parentTag newSuffix : Name) (newGoals : List MVarId) :

                                                                                                Use parentTag to tag untagged goals at newGoals. If there are multiple new untagged goals, they are named using <parentTag>.<newSuffix>_<idx> where idx > 0. If there is only one new untagged goal, then we just use parentTag

                                                                                                Instances For
                                                                                                  def Lean.Elab.Tactic.withCaseRef {m : TypeType} {α : Type} [Monad m] [MonadRef m] (arrow body : Syntax) (x : m α) :
                                                                                                  m α

                                                                                                  Use position of => $body for error messages. If there is a line break before body, the message will be displayed on => only, but the "full range" for the info view will still include body.

                                                                                                  Instances For