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 {
892
892
outerParamDefs(constr)
893
893
else Nil
894
894
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
+ */
895
912
private def addRetainedInlineBodies (stats : List [untpd.Tree ])(using ctx : Context ): List [untpd.Tree ] =
896
913
lazy val retainerDef : Map [Symbol , DefDef ] = stats.collect {
897
914
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 {
124
124
)
125
125
}
126
126
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
131
129
*
132
- * inline def f[Ts](xs: Us ) = body
130
+ * inline override def f(x: T ) = b
133
131
*
134
- * This sets up the call
132
+ * is complemented by the body retainer method
135
133
*
136
- * f[Ts'](xs' )
134
+ * private def f$retainedBody(x: T) = f(x )
137
135
*
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.
144
138
*/
145
139
def bodyRetainer (mdef : DefDef )(using ctx : Context ): DefDef =
146
140
val meth = mdef.symbol.asTerm
You can’t perform that action at this time.
0 commit comments