Skip to content

Commit 844be0d

Browse files
Merge pull request #9379 from dotty-staging/fix-#9342
Fix #9342: Use semantic name for inline bindings
2 parents 7ae7f1f + 8aabfac commit 844be0d

File tree

9 files changed

+38
-16
lines changed

9 files changed

+38
-16
lines changed

compiler/src/dotty/tools/dotc/core/NameKinds.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ object NameKinds {
295295
val DocArtifactName: UniqueNameKind = new UniqueNameKind("$doc")
296296
val UniqueInlineName: UniqueNameKind = new UniqueNameKind("$i")
297297
val InlineScrutineeName: UniqueNameKind = new UniqueNameKind("$scrutinee")
298-
val InlineBinderName: UniqueNameKind = new UniqueNameKind("$elem")
298+
val InlineBinderName: UniqueNameKind = new UniqueNameKind("$proxy")
299299

300300
/** A kind of unique extension methods; Unlike other unique names, these can be
301301
* unmangled.

compiler/src/dotty/tools/dotc/typer/Inliner.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
421421
val (bindingFlags, bindingType) =
422422
if (isByName) (inlineFlags, ExprType(argtpe.widen))
423423
else (inlineFlags, argtpe.widen)
424-
val boundSym = newSym(name, bindingFlags, bindingType).asTerm
424+
val boundSym = newSym(InlineBinderName.fresh(name.asTermName), bindingFlags, bindingType).asTerm
425425
val binding = {
426426
if (isByName) DefDef(boundSym, arg.changeOwner(ctx.owner, boundSym))
427427
else ValDef(boundSym, arg)

compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
424424

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

tests/pos/i9342a.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
inline def label(x: Int, inline g: Int => String): String = g(x)
2+
def f: Int => String = ???
3+
def label2(g: Int) = label(g, f)

tests/pos/i9342b.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait Label[A]:
2+
def apply(v: A): String
3+
4+
given [A] as Label[A] = _.toString
5+
6+
extension [A](x: A) inline def label(using inline l: Label[A]): String = l(x)
7+
8+
def label1[A](v: A) = v.label
9+
10+
def label2[A](l: A) = l.label

tests/pos/i9342c.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Label[A]:
2+
def apply(v: A): String
3+
4+
def g[A]: Label[A] = _.toString
5+
6+
inline def label[A](x: A, inline l: Label[A]): String = l(x)
7+
8+
def label1[A](v: A) = label(v, g)
9+
def label2[A](l: A) = label(l, g)

tests/run-macros/quote-inline-function.check

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Normal function
33
var i: scala.Int = 0
44
val j: scala.Int = 5
55
while (i.<(j)) {
6-
f.apply(i)
6+
f$proxy1.apply(i)
77
i = i.+(1)
88
}
99
while ({
10-
f.apply(i)
10+
f$proxy1.apply(i)
1111
i = i.+(1)
1212
i.<(j)
1313
}) ()
@@ -18,11 +18,11 @@ By name function
1818
var i: scala.Int = 0
1919
val j: scala.Int = 5
2020
while (i.<(j)) {
21-
f.apply(i)
21+
f$proxy2.apply(i)
2222
i = i.+(1)
2323
}
2424
while ({
25-
f.apply(i)
25+
f$proxy2.apply(i)
2626
i = i.+(1)
2727
i.<(j)
2828
}) ()

tests/run-macros/quoted-matching-docs.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
6
33
10.+(Test.a)
44
15
5-
args.sum[scala.Int](scala.math.Numeric.IntIsIntegral)
5+
args$proxy5.sum[scala.Int](scala.math.Numeric.IntIsIntegral)
66
9

tests/run-macros/tasty-argument-tree-1.check

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tree deref. vals: Literal(Constant(3))
55
tree: Inlined(None, Nil, Ident("v"))
66
tree deref. vals: Literal(Constant(1))
77

8-
tree: Inlined(None, Nil, Ident("x"))
8+
tree: Inlined(None, Nil, Ident("x$proxy1"))
99
tree deref. vals: Literal(Constant(2))
1010

1111
tree: Inlined(None, Nil, Ident("l"))
@@ -14,29 +14,29 @@ tree deref. vals: Literal(Constant(3))
1414
tree: Inlined(None, Nil, Ident("a"))
1515
tree deref. vals: Ident("a")
1616

17-
tree: Inlined(None, Nil, Ident("x"))
17+
tree: Inlined(None, Nil, Ident("x$proxy2"))
1818
tree deref. vals: Ident("b")
1919

20-
tree: Inlined(None, Nil, Ident("x"))
20+
tree: Inlined(None, Nil, Ident("x$proxy3"))
2121
tree deref. vals: Apply(Ident("d2"), Nil)
2222

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

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

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

32-
tree: Inlined(None, Nil, Ident("x"))
32+
tree: Inlined(None, Nil, Ident("x$proxy6"))
3333
tree deref. vals: Literal(Constant(1))
3434

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

38-
tree: Inlined(None, Nil, Ident("x"))
38+
tree: Inlined(None, Nil, Ident("x$proxy7"))
3939
tree deref. vals: Literal(Constant(2))
4040

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

0 commit comments

Comments
 (0)