File tree Expand file tree Collapse file tree 2 files changed +24
-13
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +24
-13
lines changed Original file line number Diff line number Diff 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 ) =>
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments