Skip to content

Fix #9342: Use semantic name for inline bindings #9379

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
Aug 10, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/NameKinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ object NameKinds {
val DocArtifactName: UniqueNameKind = new UniqueNameKind("$doc")
val UniqueInlineName: UniqueNameKind = new UniqueNameKind("$i")
val InlineScrutineeName: UniqueNameKind = new UniqueNameKind("$scrutinee")
val InlineBinderName: UniqueNameKind = new UniqueNameKind("$elem")
val InlineBinderName: UniqueNameKind = new UniqueNameKind("$proxy")

/** A kind of unique extension methods; Unlike other unique names, these can be
* unmangled.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
val (bindingFlags, bindingType) =
if (isByName) (inlineFlags, ExprType(argtpe.widen))
else (inlineFlags, argtpe.widen)
val boundSym = newSym(name, bindingFlags, bindingType).asTerm
val boundSym = newSym(InlineBinderName.fresh(name.asTermName), bindingFlags, bindingType).asTerm
val binding = {
if (isByName) DefDef(boundSym, arg.changeOwner(ctx.owner, boundSym))
else ValDef(boundSym, arg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {

val fun = getMethod(clsNode, "test")
val instructions = instructionsFromMethod(fun)
val expected = List(Invoke(INVOKESTATIC, "Foo", "f$1", "()V", false), Op(RETURN))
val expected = List(Invoke(INVOKESTATIC, "Foo", "f$proxy1$1", "()V", false), Op(RETURN))
assert(instructions == expected,
"`inlined` was not properly inlined in `test`\n" + diffInstructions(instructions, expected))

Expand Down
3 changes: 3 additions & 0 deletions tests/pos/i9342a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
inline def label(x: Int, inline g: Int => String): String = g(x)
def f: Int => String = ???
def label2(g: Int) = label(g, f)
10 changes: 10 additions & 0 deletions tests/pos/i9342b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
trait Label[A]:
def apply(v: A): String

given [A] as Label[A] = _.toString

extension [A](x: A) inline def label(using inline l: Label[A]): String = l(x)

def label1[A](v: A) = v.label

def label2[A](l: A) = l.label
9 changes: 9 additions & 0 deletions tests/pos/i9342c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait Label[A]:
def apply(v: A): String

def g[A]: Label[A] = _.toString

inline def label[A](x: A, inline l: Label[A]): String = l(x)

def label1[A](v: A) = label(v, g)
def label2[A](l: A) = label(l, g)
8 changes: 4 additions & 4 deletions tests/run-macros/quote-inline-function.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Normal function
var i: scala.Int = 0
val j: scala.Int = 5
while (i.<(j)) {
f.apply(i)
f$proxy1.apply(i)
i = i.+(1)
}
while ({
f.apply(i)
f$proxy1.apply(i)
i = i.+(1)
i.<(j)
}) ()
Expand All @@ -18,11 +18,11 @@ By name function
var i: scala.Int = 0
val j: scala.Int = 5
while (i.<(j)) {
f.apply(i)
f$proxy2.apply(i)
i = i.+(1)
}
while ({
f.apply(i)
f$proxy2.apply(i)
i = i.+(1)
i.<(j)
}) ()
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/quoted-matching-docs.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
6
10.+(Test.a)
15
args.sum[scala.Int](scala.math.Numeric.IntIsIntegral)
args$proxy5.sum[scala.Int](scala.math.Numeric.IntIsIntegral)
9
16 changes: 8 additions & 8 deletions tests/run-macros/tasty-argument-tree-1.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tree deref. vals: Literal(Constant(3))
tree: Inlined(None, Nil, Ident("v"))
tree deref. vals: Literal(Constant(1))

tree: Inlined(None, Nil, Ident("x"))
tree: Inlined(None, Nil, Ident("x$proxy1"))
tree deref. vals: Literal(Constant(2))

tree: Inlined(None, Nil, Ident("l"))
Expand All @@ -14,29 +14,29 @@ tree deref. vals: Literal(Constant(3))
tree: Inlined(None, Nil, Ident("a"))
tree deref. vals: Ident("a")

tree: Inlined(None, Nil, Ident("x"))
tree: Inlined(None, Nil, Ident("x$proxy2"))
tree deref. vals: Ident("b")

tree: Inlined(None, Nil, Ident("x"))
tree: Inlined(None, Nil, Ident("x$proxy3"))
tree deref. vals: Apply(Ident("d2"), Nil)

tree: Inlined(None, Nil, Ident("x"))
tree: Inlined(None, Nil, Ident("x$proxy4"))
tree deref. vals: Apply(Ident("d3"), List(Literal(Constant(3))))

tree: Inlined(None, Nil, Ident("x"))
tree: Inlined(None, Nil, Ident("x$proxy5"))
tree deref. vals: TypeApply(Ident("d4"), List(TypeIdent("Int")))

tree: Inlined(None, Nil, Ident("vv"))
tree deref. vals: Literal(Constant(1))

tree: Inlined(None, Nil, Ident("x"))
tree: Inlined(None, Nil, Ident("x$proxy6"))
tree deref. vals: Literal(Constant(1))

tree: Inlined(None, Nil, Ident("vd"))
tree deref. vals: Literal(Constant(2))

tree: Inlined(None, Nil, Ident("x"))
tree: Inlined(None, Nil, Ident("x$proxy7"))
tree deref. vals: Literal(Constant(2))

tree: Inlined(None, Nil, Ident("x"))
tree: Inlined(None, Nil, Ident("x$proxy8"))
tree deref. vals: Apply(TypeApply(Select(Ident("Tuple2"), "apply"), List(Inferred(), Inferred())), List(Literal(Constant(1)), Literal(Constant(2))))