Skip to content

Fix #4431: Change semantics of inline params in macro #4460

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
merged 3 commits into from
May 14, 2018

Conversation

nicolasstucki
Copy link
Contributor

  • Only allow access to inline macro parameters in stage 0 if they have type Boolean, Byte, Short, Int, Long, Float, Double, Char or String

This change in semantics allows us to support inline parameters of function type.

@Blaisorblade
Copy link
Contributor

Blaisorblade commented May 4, 2018

For context: the motivation for this semantics in #4431 is that this is a limited form of cross-stage persistence (maybe in reverse) or inspection of trees, which is easy for literals/primitive types but hard in general. (Tho, I was thinking of using a typeclass for extensibility). 👍 for the semantic change (and for updating docs).

@@ -66,16 +66,19 @@ import dotty.tools.dotc.core.quoted._
* ```
* to
* ```
* inline def foo[T1, ...](inline x1: X, ..., y1: Y, ....): Seq[Any] => Object = { (args: Seq[Any]) => {
* inline def foo[T1, ...](inline x1: X, ..., y1: Y, ..., inline f1: X => Y): Seq[Any] => Object = { (args: Seq[Any]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add f1 at the original form as well in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it and made it part of the comment below

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems good, nice.

@nicolasstucki nicolasstucki requested review from biboudis and removed request for odersky May 12, 2018 06:53
@nicolasstucki nicolasstucki assigned biboudis and unassigned odersky May 12, 2018
@@ -625,6 +629,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
}
}

private def isStage0Value(sym: Symbol)(implicit ctx: Context): Boolean =
sym.is(Inline) && sym.owner.is(Macro) && !defn.isFunctionType(sym.info)
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 addition of !defn.isFunctionType(sym.info) is the only real change in this PR, the rest is refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

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

After discussion with Aggelos, also LGTM for me.

@Blaisorblade "cross stage persistence in reverse" is a good way to characterize this.

@nicolasstucki nicolasstucki merged commit 0a486e3 into scala:master May 14, 2018
@Blaisorblade Blaisorblade deleted the fix-#4431 branch May 14, 2018 16:01
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