Skip to content

Prepare bodies of inline forwarders eagerly #16757

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
Feb 12, 2023
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
16 changes: 12 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1227,13 +1227,21 @@ class Namer { typer: Typer =>
case pt: MethodOrPoly => 1 + extensionParamsCount(pt.resType)
case _ => 0
val ddef = tpd.DefDef(forwarder.asTerm, prefss => {
val forwarderCtx = ctx.withOwner(forwarder)
val (pathRefss, methRefss) = prefss.splitAt(extensionParamsCount(path.tpe.widen))
val ref = path.appliedToArgss(pathRefss).select(sym.asTerm)
ref.appliedToArgss(adaptForwarderParams(Nil, sym.info, methRefss))
.etaExpandCFT(using ctx.withOwner(forwarder))
val rhs = ref.appliedToArgss(adaptForwarderParams(Nil, sym.info, methRefss))
.etaExpandCFT(using forwarderCtx)
if forwarder.isInlineMethod then
// Eagerly make the body inlineable. `registerInlineInfo` does this lazily
// but it does not get evaluated during typer as the forwarder we are creating
// is already typed.
val inlinableRhs = PrepareInlineable.makeInlineable(rhs)(using forwarderCtx)
PrepareInlineable.registerInlineInfo(forwarder, inlinableRhs)(using forwarderCtx)
inlinableRhs
else
rhs
})
if forwarder.isInlineMethod then
PrepareInlineable.registerInlineInfo(forwarder, ddef.rhs)
buf += ddef.withSpan(span)
if hasDefaults then
foreachDefaultGetterOf(sym.asTerm,
Expand Down
11 changes: 11 additions & 0 deletions tests/pos-macros/i14131.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Dog:
inline given bark(using msg: String = "Woof!"): String = s"bark: $msg"

class Wolf:
private val dog: Dog = Dog()
export dog.given

def test =
val w = Wolf()
import w.given
summon[String]
15 changes: 15 additions & 0 deletions tests/pos/i16469.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Context {
def normalMethod(): String = "normal"
inline def inlineMethod(): String = "inline"
}

class Script(ctx: Context) {
export ctx.*
normalMethod()
inlineMethod()
}

class MyScript(context: Context) extends Script(context) {
normalMethod()
inlineMethod()
}