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

Replace java reflection with a macro-based solution #4280

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Sep 17, 2024

Necessary for cross compilation with Scala Native, since it does not offer any reflection functionalities.
Instead of the previous method, we create a mapping between strings (pointed out by the dialectOverride in scalafmt.conf) and methods that allow us to replace dialect values.
With that we still have the previous dialectOverride functionality that we do not have to manually maintain/expose and we avoid java reflection (which should make things faster even on the JVM).

Part of the Scala Native cross compilation effort (#4279)

@jchyb jchyb force-pushed the scala-native/dialect-macro branch 3 times, most recently from 2f9cb5a to 25fe84e Compare September 17, 2024 16:11
Copy link
Collaborator

@kitbellew kitbellew left a comment

Choose a reason for hiding this comment

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

one request: if you are actively working on this code, could you please submit it as draft during that time, before marking it ready for review when you are done?

my review comments keep getting rejected because the patch had been updated in the meantime, it's a bit counterproductive.

@jchyb
Copy link
Contributor Author

jchyb commented Sep 18, 2024

Apologies for the previous force pushes - I submitted as a non-draft because I was confident in this, but it ended up breaking the CI in places I did not predict while PRing, so I tried to fix this

@jchyb jchyb marked this pull request as draft September 18, 2024 11:30
Copy link
Collaborator

@kitbellew kitbellew left a comment

Choose a reason for hiding this comment

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

thank you, this looks really good. i had one small question about the name, but another is: is it possible to add some unit tests for this? perhaps not an exhaustive list of all withXxx methods, as they might change with time, but at least test for a subset...

@jchyb
Copy link
Contributor Author

jchyb commented Sep 18, 2024

About adding the tests - sure! Would it be better to add more general ones in scalafmt-test (like the one dialectOverride test there), or add some in scalafmt-macros, which would just check the macro generated Map?

@kitbellew
Copy link
Collaborator

About adding the tests - sure! Would it be better to add more general ones in scalafmt-test (like the one dialectOverride test there), or add some in scalafmt-macros, which would just check the macro generated Map?

i think all tests are in scalafmt-test. if that's true, then i'd follow the same. if that's not true, then up to you.

@@ -0,0 +1,34 @@
package org.scalafmt.config
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tgodzik non-blocking comment for this pr: should we consider copying this functionality into scalameta? i know you have been working on making that working with scala3, perhaps there's a way to have two macro-based implementations, one for scala2 and another for scala3.

@jchyb jchyb force-pushed the scala-native/dialect-macro branch 2 times, most recently from 948a4bf to 9bf1d65 Compare September 19, 2024 17:02
Copy link
Collaborator

@kitbellew kitbellew left a comment

Choose a reason for hiding this comment

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

almost there...

@jchyb jchyb marked this pull request as ready for review September 19, 2024 17:31
Copy link
Collaborator

@kitbellew kitbellew left a comment

Choose a reason for hiding this comment

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

last request.

Necessary for cross compilation with scala native, since it does not
offer any reflection functionalities.
Instead of the previous method, we create a mapping between
strings (pointed out by the dialectOverride in scalafmt.conf) and
methods that allow us to replace dialect values.
@kitbellew kitbellew merged commit 52c8954 into scalameta:main Sep 19, 2024
11 checks passed
@kitbellew
Copy link
Collaborator

thank you for your patience!

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