forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scala#3205 from dotty-staging/fix-#3130
Fix scala#3130: Various fixes to inline
- Loading branch information
Showing
13 changed files
with
160 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
compiler/src/dotty/tools/dotc/transform/ElimOuterSelect.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dotty.tools.dotc | ||
package transform | ||
|
||
import core._ | ||
import TreeTransforms.{MiniPhaseTransform, TransformerInfo} | ||
import Contexts.Context | ||
import Types._ | ||
import Decorators._ | ||
import NameKinds.OuterSelectName | ||
import ast.Trees._ | ||
|
||
/** This phase rewrites outer selects `E.n_<outer>` which were introduced by | ||
* inlining to outer paths. | ||
*/ | ||
class ElimOuterSelect extends MiniPhaseTransform { thisTransform => | ||
import ast.tpd._ | ||
|
||
override def phaseName: String = "elimOuterSelect" | ||
|
||
override def runsAfterGroupsOf = Set(classOf[ExplicitOuter]) | ||
// ExplicitOuter needs to have run to completion before so that all classes | ||
// that need an outer accessor have one. | ||
|
||
/** Convert a selection of the form `qual.n_<outer>` to an outer path from `qual` of | ||
* length `n`. | ||
*/ | ||
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo) = | ||
tree.name match { | ||
case OuterSelectName(_, nhops) => | ||
val SkolemType(tp) = tree.tpe | ||
ExplicitOuter.outer.path(start = tree.qualifier, count = nhops).ensureConforms(tp) | ||
case _ => tree | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
object Test { | ||
private def foo(arg1: Int): Int = { | ||
inline def bar: Int = foo(0) | ||
if (arg1 == 0) 0 else bar | ||
} | ||
assert(foo(11) == 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
object companions2 { | ||
inline def foo() = { | ||
class C { | ||
println(C.p) | ||
} | ||
|
||
object C { | ||
private val p = 1 | ||
} | ||
} | ||
} | ||
|
||
class A { | ||
val b = new B | ||
|
||
class B { | ||
private def getAncestor2(p: A): A = p | ||
private inline def getAncestor(p: A): A = { | ||
p.b.getAncestor(p) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
object O { | ||
new D(2).DD.apply() | ||
} | ||
|
||
class D(val x: Int) { | ||
class DD() | ||
object DD { | ||
inline def apply() = x // new DD() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Outer { | ||
trait F { def f(): Int } | ||
inline def inner: F = { | ||
class InnerClass(x: Int) extends F { | ||
def this() = this(3) | ||
def f() = x | ||
} | ||
new InnerClass(3) | ||
} | ||
} | ||
|
||
object Test extends App { | ||
val o = new Outer | ||
assert(o.inner.f() == 3) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
trait Test { | ||
trait Global { | ||
type Tree | ||
def get: Tree | ||
} | ||
|
||
trait TreeBuilder { | ||
val global: Global | ||
inline def set(tree: global.Tree) = {} | ||
} | ||
|
||
val nsc: Global | ||
|
||
trait FileImpl { | ||
object treeBuilder extends TreeBuilder { | ||
val global: nsc.type = nsc | ||
} | ||
treeBuilder.set(nsc.get) | ||
} | ||
def file: FileImpl | ||
|
||
file.treeBuilder.set(nsc.get) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class D(x: Int) { | ||
class DD { | ||
inline def apply() = new DD() | ||
} | ||
val inner = new DD | ||
} | ||
object Test { | ||
new D(2).inner.apply() | ||
} |