Skip to content

Disallow interpretation of arbitrary calls in parameters #10103

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

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Oct 27, 2020

Only the macro call should be interpreted. The code within the parameters should only contain quoted code and literal constants.

inline def f(x: Expr[X]) = ${ impl('x) }
inline def f(x: Expr[X]) = ${ impl(doSomethong('x)) } // error

In the future, we could support having arbitrary code in the macros, but it should be done the right way. The code within the top-level splice should be precompiled and that code would be executed when calling the macro.

Migration

- inline def f(x: Expr[X]) = ${ impl(doSomethong('x)) } // error
+ inline def f(x: Expr[X]) = ${ impl0('x) } // interpreted code
+ private def impl0[X: Type](x: Expr[X])(using QuoteContext) = impl(doSomethong(x)) // compiled code

Future

Now that we have compilation unit suspension we could auto-generate the intermediary implementation and place it in a global object that gets compiled first. This is not a priority as it does not provide any extra functionality, it can always be written down explicitly.

@nicolasstucki nicolasstucki force-pushed the disallow-interpreation-of-arbitrary-calls-in-paramteres branch 4 times, most recently from 65abb7e to 6e7599d Compare October 28, 2020 15:07
@nicolasstucki nicolasstucki marked this pull request as ready for review October 28, 2020 16:10
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

Only the macro call should be interpreted.
@nicolasstucki nicolasstucki force-pushed the disallow-interpreation-of-arbitrary-calls-in-paramteres branch from cedf483 to 3b83534 Compare October 29, 2020 12:12
@nicolasstucki nicolasstucki merged commit df7aa25 into scala:master Oct 29, 2020
@nicolasstucki nicolasstucki deleted the disallow-interpreation-of-arbitrary-calls-in-paramteres branch October 29, 2020 15:35
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

4 participants