-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix staging using inline methods in quotes #10803
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package dotty.tools.dotc | ||
package transform | ||
|
||
import core._ | ||
import Decorators._ | ||
import Flags._ | ||
import Types._ | ||
import Contexts._ | ||
import Symbols._ | ||
import Constants._ | ||
import ast.Trees._ | ||
import ast.{TreeTypeMap, untpd} | ||
import util.Spans._ | ||
import tasty.TreePickler.Hole | ||
import SymUtils._ | ||
import NameKinds._ | ||
import dotty.tools.dotc.ast.tpd | ||
import typer.Implicits.SearchFailureType | ||
nicolasstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import scala.collection.mutable | ||
import dotty.tools.dotc.core.Annotations._ | ||
nicolasstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import dotty.tools.dotc.core.Names._ | ||
import dotty.tools.dotc.core.StdNames._ | ||
import dotty.tools.dotc.core.StagingContext._ | ||
import dotty.tools.dotc.quoted._ | ||
import dotty.tools.dotc.transform.TreeMapWithStages._ | ||
import dotty.tools.dotc.typer.Inliner | ||
import dotty.tools.dotc.typer.ImportInfo.withRootImports | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import seems to be not used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are from #9984. I kept them to simplify the merge afterward. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will cleanup all imports in #9984 |
||
|
||
import scala.annotation.constructorOnly | ||
|
||
/** Inlines all calls to inline methods that are not in an inline method or a quote */ | ||
class Inlining extends MacroTransform { | ||
import tpd._ | ||
|
||
override def phaseName: String = Inlining.name | ||
|
||
override def allowsImplicitSearch: Boolean = true | ||
|
||
override def checkPostCondition(tree: Tree)(using Context): Unit = | ||
tree match { | ||
case tree: RefTree if !Inliner.inInlineMethod && StagingContext.level == 0 => | ||
assert(!tree.symbol.isInlineMethod) | ||
case _ => | ||
} | ||
|
||
protected def newTransformer(using Context): Transformer = new Transformer { | ||
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = | ||
tree match | ||
case tree: DefTree => | ||
if tree.symbol.is(Inline) then tree | ||
else super.transform(tree) | ||
case _: Typed | _: Block => | ||
super.transform(tree) | ||
case _ if Inliner.isInlineable(tree) && !tree.tpe.widen.isInstanceOf[MethodOrPoly] && StagingContext.level == 0 => | ||
val tree1 = super.transform(tree) | ||
val inlined = Inliner.inlineCall(tree1) | ||
if tree1 eq inlined then inlined | ||
else transform(inlined) | ||
case _: TypeApply if tree.symbol.isQuote => | ||
ctx.compilationUnit.needsStaging = true | ||
super.transform(tree) | ||
case _ => | ||
super.transform(tree) | ||
|
||
} | ||
} | ||
|
||
object Inlining { | ||
val name: String = "inlining" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
6 | ||
6 | ||
Test.inlineLambda.apply(3) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
|
||
6 | ||
{ | ||
val x: 3 = { | ||
scala.Predef.println() | ||
3 | ||
} | ||
6 | ||
} | ||
Test.inlineLambda.apply({ | ||
scala.Predef.println() | ||
3 | ||
}) |
Uh oh!
There was an error while loading. Please reload this page.