Skip to content

Implement compiletime.code with a macro #8859

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

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented May 1, 2020

Now, the implementation is simpler with macros. At the time we did not have pattern matching on quoted code.

@nicolasstucki nicolasstucki force-pushed the reimplement-compiletime-code branch 3 times, most recently from 3dbbcf0 to 6d772ed Compare May 1, 2020 16:37
@nicolasstucki nicolasstucki force-pushed the reimplement-compiletime-code branch from 6d772ed to b6995d5 Compare May 2, 2020 06:10
@nicolasstucki nicolasstucki marked this pull request as ready for review May 2, 2020 07:00
@nicolasstucki
Copy link
Contributor Author

Note that I changed the printer. Now it shows the actual code rather than a simplified view of it. I am considering adding an alternative that would print the actual source code of the parameters.

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

* ```
*
* @note only by-name arguments will be displayed as "code".
* Other values may display unintutively.
*/
inline def (self: => StringContext) code (args: => Any*): String = ???
transparent inline def (inline self: StringContext) code (inline args: Any*): String = ${ codeExpr('self, 'args) }
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not clear to me why we need transparent, given that the result type is always String.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is because we want this to return a string literal that can be constant folded with other string literals. Also, the error method used the type of the string know the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intrinsic implementation was also transparent, but we forgot to mark the definition as such.

@nicolasstucki nicolasstucki merged commit 5d6d6aa into scala:master May 3, 2020
@nicolasstucki nicolasstucki deleted the reimplement-compiletime-code branch May 3, 2020 13:23
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