Skip to content

Commit da6a5aa

Browse files
committed
wip
1 parent 48c6a0e commit da6a5aa

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

Bar.scala

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Bar {
2+
3+
// asfdfdsfsadfsdfdsf
4+
// asfdfdsfsadfsdfdsf
5+
// asfdfdsfsadfsdfdsf
6+
// asfdfdsfsadfsdfdsf
7+
// asfdfdsfsadfsdfdsf
8+
// asfdfdsfsadfsdfdsf
9+
// asfdfdsfsadfsdfdsf
10+
// asfdfdsfsadfsdfdsf
11+
// asfdfdsfsadfsdfdsf
12+
// asfdfdsfsadfsdfdsf
13+
// asfdfdsfsadfsdfdsf
14+
// asfdfdsfsadfsdfdsf
15+
// asfdfdsfsadfsdfdsf
16+
// asfdfdsfsadfsdfdsf
17+
// asfdfdsfsadfsdfdsf
18+
// asfdfdsfsadfsdfdsf
19+
// asfdfdsfsadfsdfdsf
20+
// asfdfdsfsadfsdfdsf
21+
// asfdfdsfsadfsdfdsf
22+
// asfdfdsfsadfsdfdsf
23+
// asfdfdsfsadfsdfdsf
24+
// asfdfdsfsadfsdfdsf
25+
// asfdfdsfsadfsdfdsf
26+
// asfdfdsfsadfsdfdsf
27+
// asfdfdsfsadfsdfdsf
28+
// asfdfdsfsadfsdfdsf
29+
// asfdfdsfsadfsdfdsf
30+
// asfdfdsfsadfsdfdsf
31+
// asfdfdsfsadfsdfdsf
32+
// asfdfdsfsadfsdfdsf
33+
// asfdfdsfsadfsdfdsf
34+
// asfdfdsfsadfsdfdsf
35+
36+
def bar: Int = {
37+
Foo.foo(baz, 5)
38+
}
39+
40+
def baz: Int = 2
41+
42+
}

Foo.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Foo {
2+
3+
inline def foo(x: Int, y: Int): Int = {
4+
println()
5+
x + y
6+
}
7+
}

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
236236
private val bindingsBuf = new mutable.ListBuffer[ValOrDefDef]
237237

238238
private def newSym(name: Name, flags: FlagSet, info: Type): Symbol =
239-
ctx.newSymbol(ctx.owner, name, flags, info, coord = call.span)
239+
ctx.newSymbol(ctx.owner, name, flags, info, coord = inlinedMethod.span)
240240

241241
/** A binding for the parameter of an inline method. This is a `val` def for
242242
* by-value parameters and a `def` def for by-name parameters. `val` defs inherit
@@ -249,6 +249,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
249249
*/
250250
private def paramBindingDef(name: Name, paramtp: Type, arg: Tree,
251251
bindingsBuf: mutable.ListBuffer[ValOrDefDef]): ValOrDefDef = {
252+
implicit val ctx: Context = this.ctx.withSource(inlinedMethod.source(this.ctx))
253+
252254
val argtpe = arg.tpe.dealiasKeepAnnots
253255
val isByName = paramtp.dealias.isInstanceOf[ExprType]
254256
var inlineFlag = InlineProxy
@@ -257,11 +259,21 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
257259
if (isByName) (InlineByNameProxy.toTermFlags, ExprType(argtpe.widen))
258260
else (inlineFlag, argtpe.widen)
259261
val boundSym = newSym(name, bindingFlags, bindingType).asTerm
262+
println("=================")
263+
println(arg.show)
264+
println(arg)
265+
println()
266+
println(boundSym.span)
267+
println()
260268
val binding = {
261-
if (isByName) DefDef(boundSym, arg.changeOwner(ctx.owner, boundSym))
262-
else ValDef(boundSym, arg)
263-
}.withSpan(boundSym.span)
269+
if (isByName) DefDef(boundSym, Inlined(EmptyTree, arg.changeOwner(ctx.owner, boundSym)))
270+
else ValDef(boundSym, Inlined(EmptyTree, arg).withSpan(inlinedMethod.span))
271+
}.withSpan(inlinedMethod.span)
264272
bindingsBuf += binding.setDefTree
273+
println("********")
274+
println(binding.show)
275+
println()
276+
println()
265277
binding
266278
}
267279

@@ -516,6 +528,11 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
516528
// Drop unused bindings
517529
val (finalBindings, finalExpansion) = dropUnusedDefs(bindingsBuf.toList, expansion1)
518530

531+
println()
532+
println(expansion1)
533+
println(expansion1.span)
534+
println()
535+
println()
519536
if (inlinedMethod == defn.Compiletime_error) issueError()
520537

521538
// Widen TermRefs to bindings
@@ -529,7 +546,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
529546
finalExpansion
530547
}
531548

532-
tpd.Inlined(call, tpd.seq(finalBindings, finalExpansion2))
549+
tpd.Inlined(call, tpd.seq(finalBindings, finalExpansion2)(ctx.withSource(inlinedMethod.source)).withSpan(inlinedMethod.span union finalExpansion2.span))
533550
}
534551
}
535552

0 commit comments

Comments
 (0)