@@ -40,8 +40,7 @@ object PostTyper {
4040 *
4141 * (10) Adds Child annotations to all sealed classes
4242 *
43- * (11) Minimizes `call` fields of `Inlined` nodes to just point to the toplevel
44- * class from which code was inlined.
43+ * (11) Replace RHS of `erased` (but not `inline`) members by `(???: rhs.type)`
4544 *
4645 * The reason for making this a macro transform is that some functions (in particular
4746 * super and protected accessors and instantiation checks) are naturally top-down and
@@ -178,23 +177,22 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
178177 }
179178 }
180179
181- private object dropInlines extends TreeMap {
182- override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
183- case Inlined (call, _, _) =>
184- cpy.Inlined (tree)(call, Nil , Typed (ref(defn.Predef_undefined ), TypeTree (tree.tpe)))
185- case _ => super .transform(tree)
186- }
180+ private def handleInlineCall (sym : Symbol )(implicit ctx : Context ): Unit = {
181+ if (sym.is(Inline ))
182+ ctx.compilationUnit.containsInlineCalls = true
187183 }
188184
189185 override def transform (tree : Tree )(implicit ctx : Context ): Tree =
190186 try tree match {
191187 case tree : Ident if ! tree.isType =>
188+ handleInlineCall(tree.symbol)
192189 handleMeta(tree.symbol)
193190 tree.tpe match {
194191 case tpe : ThisType => This (tpe.cls).withPos(tree.pos)
195192 case _ => tree
196193 }
197194 case tree @ Select (qual, name) =>
195+ handleInlineCall(tree.symbol)
198196 handleMeta(tree.symbol)
199197 if (name.isTypeName) {
200198 Checking .checkRealizable(qual.tpe, qual.pos.focus)
@@ -203,14 +201,15 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
203201 else
204202 transformSelect(tree, Nil )
205203 case tree : Apply =>
204+ handleInlineCall(tree.symbol)
206205 val methType = tree.fun.tpe.widen
207206 val app =
208207 if (methType.isErasedMethod)
209208 tpd.cpy.Apply (tree)(
210209 tree.fun,
211210 tree.args.map(arg =>
212211 if (methType.isImplicitMethod && arg.pos.isSynthetic) ref(defn.Predef_undefined )
213- else dropInlines.transform( arg) ))
212+ else arg))
214213 else
215214 tree
216215 methPart(app) match {
@@ -223,6 +222,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
223222 super .transform(app)
224223 }
225224 case tree : TypeApply =>
225+ handleInlineCall(tree.symbol)
226226 val tree1 @ TypeApply (fn, args) = normalizeTypeArgs(tree)
227227 if (fn.symbol != defn.ChildAnnot .primaryConstructor) {
228228 // Make an exception for ChildAnnot, which should really have AnyKind bounds
@@ -236,19 +236,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
236236 case _ =>
237237 super .transform(tree1)
238238 }
239- case Inlined (call, bindings, expansion) if ! call.isEmpty =>
240- // Leave only a call trace consisting of
241- // - a reference to the top-level class from which the call was inlined,
242- // - the call's position
243- // in the call field of an Inlined node.
244- // The trace has enough info to completely reconstruct positions.
245- // The minimization is done for two reasons:
246- // 1. To save space (calls might contain large inline arguments, which would otherwise
247- // be duplicated
248- // 2. To enable correct pickling (calls can share symbols with the inlined code, which
249- // would trigger an assertion when pickling).
250- val callTrace = Ident (call.symbol.topLevelClass.typeRef).withPos(call.pos)
251- cpy.Inlined (tree)(callTrace, transformSub(bindings), transform(expansion)(inlineContext(call)))
252239 case tree : Template =>
253240 withNoCheckNews(tree.parents.flatMap(newPart)) {
254241 val templ1 = paramFwd.forwardParamAccessors(tree)
@@ -335,9 +322,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
335322 }
336323
337324 /** Transforms the rhs tree into a its default tree if it is in an `erased` val/def.
338- * Performed to shrink the tree that is known to be erased later.
339- */
325+ * Performed to shrink the tree that is known to be erased later.
326+ */
340327 private def normalizeErasedRhs (rhs : Tree , sym : Symbol )(implicit ctx : Context ) =
341- if (sym.isEffectivelyErased) dropInlines.transform(rhs) else rhs
328+ if (! sym.isEffectivelyErased || sym.isInlineMethod || ! rhs.tpe.exists) rhs
329+ else Typed (ref(defn.Predef_undefined ), TypeTree (rhs.tpe))
342330 }
343331}
0 commit comments