Skip to content

[Merged by Bors] - chore: automatically replace erw with rw that work as well#17615

Closed
Vierkantor wants to merge 3 commits intomasterfrom
erw-to-rw
Closed

[Merged by Bors] - chore: automatically replace erw with rw that work as well#17615
Vierkantor wants to merge 3 commits intomasterfrom
erw-to-rw

Conversation

@Vierkantor
Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor commented Oct 10, 2024

This is an automatically generated PR, replacing 259 erw calls with rw for free. I'm working on a follow-up that manually deals with the context around these erws: deleting now-useless comments about erw and merging adjacent rw calls into one. Keeping the automatically generated changes apart from the manual ones should help with reviewing.

How to reproduce this PR

Check out the branch erw-to-rw-setup. Run the command

lake build | grep '^info:' | awk -F ":" '{ print "-i ‘.bak’ -e "$3"s/erw/rw/ "$2; }' | xargs -L 1 sed

and git diff should show you exactly the same modifications as in this PR.

Technical details

In Mathlib.Tactic.Core I added the following rule to erw:

import Mathlib.Tactic.TryThis

/-- if we call `erw`, first try running regular `rw` and warn if that succeds. -/
macro_rules 
  | `(tactic| erw $s $(loc)?) =>
    `(tactic| try_this rw $(.none)? $s $(loc)?)

This makes erw display a "Try this:" message if rw would have succeeded as well. Beware that this does not mean that the file compiles just as well after doing the replacement, since a rw could succeed by rewriting a different term, so subsequent tactics fail. This is important for running the script!

With that edit in place, it's possible to run the script. This will parse the lake build output, looking for the lines produced by the macro rule, and replace erw with rw on the lines that it indicates. Note that it assumes there is at most one erw on one line; that was true at least when I ran the script.


Open in Gitpod

@Vierkantor Vierkantor added the tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip label Oct 10, 2024
@Vierkantor Vierkantor requested a review from jcommelin October 10, 2024 13:36
@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 10, 2024

PR summary c989268a7e

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

No declarations were harmed in the making of this PR! 🐙

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.

@Vierkantor
Copy link
Copy Markdown
Contributor Author

Here's the lake build output I used to generate this PR: erw-build-log.txt.

@jcommelin
Copy link
Copy Markdown
Member

Thanks 🎉

If CI passes, please remove the label awaiting-CI and merge this yourself, by adding a comment bors r+.

bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Oct 10, 2024

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

@github-actions github-actions bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Oct 10, 2024
Vierkantor added a commit that referenced this pull request Oct 10, 2024
This PR goes through the diff of #17615, which automatically replaced `erw` with `rw`) to clean up as follows:
 * delete obsolote comments
 * merge adjacent `rw` calls
 * restore old code that broke at some point but now works again
@Vierkantor
Copy link
Copy Markdown
Contributor Author

It builds now, so:

bors r+

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Oct 10, 2024
mathlib-bors bot pushed a commit that referenced this pull request Oct 10, 2024
This is an automatically generated PR, replacing 259 `erw` calls with `rw` for free. I'm working on a follow-up that manually deals with the context around these `erw`s: deleting now-useless comments about `erw` and merging adjacent `rw` calls into one. Keeping the automatically generated changes apart from the manual ones should help with reviewing.

# How to reproduce this PR

Check out the branch `erw-to-rw-setup`. Run the command
```bash
lake build | grep '^info:' | awk -F ":" '{ print "-i ‘.bak’ -e "$3"s/erw/rw/ "$2; }' | xargs -L 1 sed
```
and `git diff` should show you exactly the same modifications as in this PR.

# Technical details

In `Mathlib.Tactic.Core` I added the following rule to `erw`:
```lean
import Mathlib.Tactic.TryThis

/-- if we call `erw`, first try running regular `rw` and warn if that succeds. -/
macro_rules 
  | `(tactic| erw $s $(loc)?) =>
    `(tactic| try_this rw $(.none)? $s $(loc)?)
```
This makes `erw` display a "Try this:" message if `rw` would have succeeded as well. Beware that this does not mean that the file compiles just as well after doing the replacement, since a `rw` could succeed by rewriting a different term, so subsequent tactics fail. This is important for running the script!

With that edit in place, it's possible to run the script. This will parse the `lake build` output, looking for the lines produced by the macro rule, and replace `erw` with `rw` on the lines that it indicates. Note that it assumes there is at most one `erw` on one line; that was true at least when I ran the script.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Oct 10, 2024

This PR was included in a batch that successfully built, but then failed to merge into master (it was a non-fast-forward update). It will be automatically retried.

mathlib-bors bot pushed a commit that referenced this pull request Oct 10, 2024
This is an automatically generated PR, replacing 259 `erw` calls with `rw` for free. I'm working on a follow-up that manually deals with the context around these `erw`s: deleting now-useless comments about `erw` and merging adjacent `rw` calls into one. Keeping the automatically generated changes apart from the manual ones should help with reviewing.

# How to reproduce this PR

Check out the branch `erw-to-rw-setup`. Run the command
```bash
lake build | grep '^info:' | awk -F ":" '{ print "-i ‘.bak’ -e "$3"s/erw/rw/ "$2; }' | xargs -L 1 sed
```
and `git diff` should show you exactly the same modifications as in this PR.

# Technical details

In `Mathlib.Tactic.Core` I added the following rule to `erw`:
```lean
import Mathlib.Tactic.TryThis

/-- if we call `erw`, first try running regular `rw` and warn if that succeds. -/
macro_rules 
  | `(tactic| erw $s $(loc)?) =>
    `(tactic| try_this rw $(.none)? $s $(loc)?)
```
This makes `erw` display a "Try this:" message if `rw` would have succeeded as well. Beware that this does not mean that the file compiles just as well after doing the replacement, since a `rw` could succeed by rewriting a different term, so subsequent tactics fail. This is important for running the script!

With that edit in place, it's possible to run the script. This will parse the `lake build` output, looking for the lines produced by the macro rule, and replace `erw` with `rw` on the lines that it indicates. Note that it assumes there is at most one `erw` on one line; that was true at least when I ran the script.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Oct 10, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title chore: automatically replace erw with rw that work as well [Merged by Bors] - chore: automatically replace erw with rw that work as well Oct 10, 2024
@mathlib-bors mathlib-bors bot closed this Oct 10, 2024
@mathlib-bors mathlib-bors bot deleted the erw-to-rw branch October 10, 2024 15:08
Vierkantor added a commit that referenced this pull request Oct 10, 2024
This PR goes through the diff of #17615, which automatically replaced `erw` with `rw`) to clean up as follows:
 * delete obsolote comments
 * merge adjacent `rw` calls
 * restore old code that broke at some point but now works again
mathlib-bors bot pushed a commit that referenced this pull request Oct 11, 2024
This PR goes through the diff of #17615, which automatically replaced `erw` with `rw`, to clean up as follows:
 * delete obsolote comments
 * merge adjacent `rw` calls
 * restore old code that was commented out when it broke at some point but now works again



Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). ready-to-merge This PR has been sent to bors. tech debt Tracking cross-cutting technical debt, see e.g. the "Technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants