Move towards Expr based interface #84

Closed
opened 2024-06-25 08:13:36 -07:00 by aniva · 1 comment
Owner

The sexp interface is good but it requires custom handlers and testing it is cumbersome. We could expose the Lean expr interface to our users directly.

In #83, we have this test

def test_eval (env: Environment): IO LSpec.TestSeq :=
  let expr := "forall (p q : Prop) (h: p), And (Or p q) (Or p q)"
  runMetaMSeq env do
    let expr ← parseSentence expr
    Meta.forallTelescope expr $ λ _ body => do
      let e ← match Parser.runParserCategory
        (env := ← MonadEnv.getEnv)
        (catName := `term)
        (input := "Or.inl h")
        (fileName := filename) with
        | .ok syn => pure syn
        | .error error => throwError "Failed to parse: {error}"
      let mut tests := LSpec.TestSeq.done
      -- Apply the tactic
      let goal ← Meta.mkFreshExprSyntheticOpaqueMVar body
      let target: Expr := mkAnd
        (mkOr (.fvar ⟨uniq 8⟩) (.fvar ⟨uniq 9⟩))
        (mkOr (.fvar ⟨uniq 8⟩) (.fvar ⟨uniq 9⟩))
      let test := LSpec.test "goals before" ((← goal.mvarId!.getType) == target)
      tests := tests ++ test
      let tactic := Tactic.evaluate `h2 e
      let test ← runTermElabMInMeta do
        let newGoals ← runTacticOnMVar tactic goal.mvarId!
        pure $ LSpec.test "goals after" ((← newGoals.head!.getType) == target)
      tests := tests ++ test
      return tests

where we test the structure of expressions without using sexp. This should be the new norm.

The `sexp` interface is good but it requires custom handlers and testing it is cumbersome. We could expose the Lean expr interface to our users directly. In https://git.leni.sh/aniva/Pantograph/pulls/83, we have this test ```lean def test_eval (env: Environment): IO LSpec.TestSeq := let expr := "forall (p q : Prop) (h: p), And (Or p q) (Or p q)" runMetaMSeq env do let expr ← parseSentence expr Meta.forallTelescope expr $ λ _ body => do let e ← match Parser.runParserCategory (env := ← MonadEnv.getEnv) (catName := `term) (input := "Or.inl h") (fileName := filename) with | .ok syn => pure syn | .error error => throwError "Failed to parse: {error}" let mut tests := LSpec.TestSeq.done -- Apply the tactic let goal ← Meta.mkFreshExprSyntheticOpaqueMVar body let target: Expr := mkAnd (mkOr (.fvar ⟨uniq 8⟩) (.fvar ⟨uniq 9⟩)) (mkOr (.fvar ⟨uniq 8⟩) (.fvar ⟨uniq 9⟩)) let test := LSpec.test "goals before" ((← goal.mvarId!.getType) == target) tests := tests ++ test let tactic := Tactic.evaluate `h2 e let test ← runTermElabMInMeta do let newGoals ← runTacticOnMVar tactic goal.mvarId! pure $ LSpec.test "goals after" ((← newGoals.head!.getType) == target) tests := tests ++ test return tests ``` where we test the structure of expressions without using sexp. This should be the new norm.
aniva added the
part/Serial
category
feature
labels 2024-06-25 08:13:36 -07:00
aniva self-assigned this 2024-06-25 08:13:39 -07:00
Author
Owner

Done #85

Done #85
aniva closed this issue 2024-08-31 19:50:54 -07:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: aniva/Pantograph#84
No description provided.