Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat: add an eval% elaborator for interpolating the output of #eval #10742

Closed
wants to merge 13 commits into from

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Feb 20, 2024

This is taken from my zulip message here.

As an example:

example : 2^10 = eval% 2^10 := by
  -- goal is `2^10 = 1024`
  sorry

Open in Gitpod

@eric-wieser eric-wieser added awaiting-review t-meta Tactics, attributes or user commands awaiting-CI labels Feb 20, 2024
@eric-wieser eric-wieser requested a review from kmill February 20, 2024 07:14
Comment on lines 29 to 39
/-- `Finset α` can be converted to an expr only if there is some way to find `DeciableEq α`. -/
unsafe nonrec instance Finset.toExpr
{α : Type u} [ToLevel.{u}] [ToExpr α] [HasInstance (DecidableEq α)] : ToExpr (Finset α) :=
have u' : Level := ToLevel.toLevel.{u}
have α' : Q(Type u') := Lean.ToExpr.toTypeExpr α
letI : Q(DecidableEq $α') := HasInstance.expr (DecidableEq α)
{ toTypeExpr := q(Finset $α')
toExpr := fun x => show Q(Finset $α') from
match show List Q($α') from x.val.unquot.reverse.map toExpr with
| [] => q(∅)
| x0 :: xs => List.foldl (fun s x => q(insert $x $s)) q({$x0}) xs }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a lot cleaner with #5952, but that PR is not ready to merge yet, and this is just a test file anyway.

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Feb 27, 2024
@eric-wieser eric-wieser removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Feb 27, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Feb 27, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Mar 1, 2024
@ericrbg-harmonic
Copy link

ericrbg-harmonic commented Mar 7, 2024

Is this expected to work with let-bound vars? e.g.

example : True := let a := 2; let b := eval% a * 2

At the moment we get some horrible fvar error: (kernel) declaration has free variables '[email protected]._hyg.174'

@eric-wieser
Copy link
Member Author

That's not expected to work; though it could certainly give a better message. You could always put the let inside the eval%

@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Mar 13, 2024

✌️ eric-wieser can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@kmill
Copy link
Contributor

kmill commented Mar 13, 2024

For a future version, it would be nice if it could capture local let values.

One way to implement this: figure out which variables would need to be reverted, throw an error if any of them are not lets, and then use mkLetFVars before passing it to eval.

@eric-wieser
Copy link
Member Author

bors merge

Perhaps worth noting that this won't handle universe variables correctly until leanprover/lean4#3090 lands.

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review labels Mar 13, 2024
mathlib-bors bot pushed a commit that referenced this pull request Mar 13, 2024
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Mar 13, 2024

Build failed:

  • Build

@eric-wieser
Copy link
Member Author

bors merge

mathlib-bors bot pushed a commit that referenced this pull request Mar 13, 2024
@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Mar 13, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat: add an eval% elaborator for interpolating the output of #eval [Merged by Bors] - feat: add an eval% elaborator for interpolating the output of #eval Mar 13, 2024
@mathlib-bors mathlib-bors bot closed this Mar 13, 2024
@mathlib-bors mathlib-bors bot deleted the eric-wieser/eval% branch March 13, 2024 20:28
dagurtomas pushed a commit that referenced this pull request Mar 22, 2024
utensil pushed a commit that referenced this pull request Mar 26, 2024
Louddy pushed a commit that referenced this pull request Apr 15, 2024
uniwuni pushed a commit that referenced this pull request Apr 19, 2024
callesonne pushed a commit that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has been sent to bors. t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants