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

[macroexpand] Make macroexpand mw delegate the expansion to eval #894

Merged
merged 3 commits into from
Aug 21, 2024

Conversation

alexander-yakushev
Copy link
Member

@alexander-yakushev alexander-yakushev commented Aug 21, 2024

This PR is a quite significant do-over of macroexpansion middleware.

The current implementation of CLJ macroexpander performs the expansion in the "middleware context". Because of that, the middleware has to carefully recreate an eval-like context (bind *ns*, ensure LOADER is bound), and problems like #886 still fall through. But we already have the eval-like context set up in the interruptible-eval middleware. This approach is already used by the inspect middleware for the initial inspector start command – it is a flavor of eval message that is intercepted by inspect mw on its way out.

I propose to do the same for macroexpansion – let the eval mw perform the expansion with all the correct dynamic bindings and context, just like if the user typed (macroexpand 'form) at the REPL. Then, intercept the resulting form and perform the "middleware work" (pretty printing, tidying up symbols) in the "middleware context".


  • You've added tests to cover your change(s)
  • All tests are passing
  • Middleware documentation is up to date

@alexander-yakushev
Copy link
Member Author

alexander-yakushev commented Aug 21, 2024

Removed tools-deps-testing .This test only exists to ensure LOADER is bound during macroexpansion. By delegating the expansion to eval middleware, LOADER becomes the responsibility of nREPL which always binds it.

Besides, since there is no longer a direct function to macroexpand a form, recreating this test would require properly setting up a client-server integration test. I don't feel this is necessary anymore.

@alexander-yakushev alexander-yakushev marked this pull request as draft August 21, 2024 07:23
@bbatsov
Copy link
Member

bbatsov commented Aug 21, 2024

I like the direction of this PR - admittedly I had totally forgot how we had implemented the macroexpansion in the past, and your proposal seems better in every way. (I'm not sure how you've managed to come across this, but I'm glad you did!) A simpler test setup is welcome as well.

This test only existed to ensure LOADER is bound during macroexpansion. By
deletaging the expansion to eval middleware, LOADER becomes the responsibility
of nREPL which always ensures it is bound.
@alexander-yakushev alexander-yakushev marked this pull request as ready for review August 21, 2024 14:05
@alexander-yakushev
Copy link
Member Author

Ready for review. Testing times dropped to ~11 minutes from ~20.

@bbatsov
Copy link
Member

bbatsov commented Aug 21, 2024

Impressive speedup! Great work! 🚀

@bbatsov bbatsov merged commit 4c95c43 into master Aug 21, 2024
55 checks passed
@bbatsov bbatsov deleted the macroexpand branch August 21, 2024 19:59
@ikappaki ikappaki mentioned this pull request Sep 18, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants