Skip to content

Commit e5bdd2e

Browse files
committed
Add doc comments for two key methods
1 parent 28c49f7 commit e5bdd2e

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,23 @@ object Erasure {
892892
outerParamDefs(constr)
893893
else Nil
894894

895+
/** For all statements in stats: given a retained inline method and
896+
* its retainedBody method such as
897+
*
898+
* inline override def f(x: T) = body1
899+
* private def f$retainedBody(x: T) = body2
900+
*
901+
* return the runtime version of `f` as
902+
*
903+
* override def f(x: T) = body2
904+
*
905+
* Here, the owner of body2 is changed to f and all references
906+
* to parameters of f$retainedBody are changed to references of
907+
* corresponding parameters in f.
908+
*
909+
* `f$retainedBody` is subseqently mapped to the empty tree in `typedDefDef`
910+
* which is then dropped in `typedStats`.
911+
*/
895912
private def addRetainedInlineBodies(stats: List[untpd.Tree])(using ctx: Context): List[untpd.Tree] =
896913
lazy val retainerDef: Map[Symbol, DefDef] = stats.collect {
897914
case stat: DefDef if stat.symbol.name.is(BodyRetainerName) =>

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,17 @@ object Inliner {
124124
)
125125
}
126126

127-
/** For a retained inline method add a RetainedBody annotaton that
128-
* records the tree for which code will be generated at runtime. This is
129-
* the inline expansion of a call to the method itself with its
130-
* parameters as arguments. Given an inline method
127+
/** For a retained inline method, another method that keeps track of
128+
* the body that is kept at runtime. For instance, an inline method
131129
*
132-
* inline def f[Ts](xs: Us) = body
130+
* inline override def f(x: T) = b
133131
*
134-
* This sets up the call
132+
* is complemented by the body retainer method
135133
*
136-
* f[Ts'](xs')
134+
* private def f$retainedBody(x: T) = f(x)
137135
*
138-
* where the 'ed parameters are copies of the original ones. The call is
139-
* then inline processed in a context which has a clone f' of f as owner.
140-
* The cloning of owner and parameters is necessary since otherwise the
141-
* inliner gets confused in various ways. The inlined body is then
142-
* transformed back by replacing cloned versions of parameters with original
143-
* and replacing the cloned owner f' with f.
136+
* where the call `f(x)` is inline-expanded. This body is then transferred
137+
* back to `f` at erasure, using method addRetainedInlineBodies.
144138
*/
145139
def bodyRetainer(mdef: DefDef)(using ctx: Context): DefDef =
146140
val meth = mdef.symbol.asTerm

0 commit comments

Comments
 (0)