Skip to content

Optimize ReifyQuotes#mayChange #4261

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 1 commit into from
Apr 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
transform(tp)
}

override protected def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = sym.is(Macro)
override protected def mayChange(sym: Symbol)(implicit ctx: Context): Boolean =
ctx.compilationUnit.containsQuotesOrSplices && sym.isTerm && sym.is(Macro)
Copy link
Contributor

Choose a reason for hiding this comment

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

ctx.compilationUnit.containsQuotesOrSplices will always be true. We only run this phase if it is true
https://github.com/lampepfl/dotty/pull/4261/files#diff-7b199cbe62cc044a10a26459c0f0fa46R94

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wrong, we do need this check.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could also avoid accessing the symbol

  override def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation =
    if (ctx.compilationUnit.containsQuotesOrSplices) super.transform(ref) else ref

  override protected def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = sym.isTerm && sym.is(Macro)

Copy link
Member Author

Choose a reason for hiding this comment

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

Calling Denotation#symbol is just a field access, so I don't think that's worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok


/** Returns the type of the compiled macro as a lambda: Seq[Any] => Object */
private def macroReturnType(implicit ctx: Context): Type =
Expand Down