diff options
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 9 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inliner.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 10 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 6 |
5 files changed, 24 insertions, 16 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 977c76668..9381f45dd 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -281,6 +281,15 @@ object SymDenotations { case nil => None } + /** The same as getAnnotation, but without ensuring + * that the symbol carrying the annotation is completed + */ + final def unforcedAnnotation(cls: Symbol)(implicit ctx: Context): Option[Annotation] = + dropOtherAnnotations(myAnnotations, cls) match { + case annot :: _ => Some(annot) + case nil => None + } + /** Add given annotation to the annotations of this denotation */ final def addAnnotation(annot: Annotation): Unit = annotations = annot :: myAnnotations diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 142aeb7dc..b148cced5 100644 --- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -488,11 +488,9 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle sym.completer.withDecls(newScope) forkAt(templateStart).indexTemplateParams()(localContext(sym)) } - else (annots.find(_.symbol == defn.InlineAnnot)) match { - case Some(inlineAnnot) => - val inlineCtx = localContext(sym).addMode(Mode.ReadPositions) - Inliner.attachInlineInfo(inlineAnnot, implicit ctx => forkAt(rhsStart).readTerm())(inlineCtx) - case none => + else if (annots.exists(_.symbol == defn.InlineAnnot)) { + val inlineCtx = localContext(sym).addMode(Mode.ReadPositions) + Inliner.registerInlineInfo(sym, implicit ctx => forkAt(rhsStart).readTerm())(inlineCtx) } goto(start) sym diff --git a/src/dotty/tools/dotc/typer/Inliner.scala b/src/dotty/tools/dotc/typer/Inliner.scala index c640244c4..e865c0596 100644 --- a/src/dotty/tools/dotc/typer/Inliner.scala +++ b/src/dotty/tools/dotc/typer/Inliner.scala @@ -204,20 +204,23 @@ object Inliner { /** A key to be used in a context property that tracks enclosing inlined calls */ private val InlinedCalls = new Property.Key[List[Tree]] // to be used in context - /** Attach inline info to `@inline` annotation. + /** Register inline info for given inline method `sym`. * + * @param sym The symbol denotatioon of the inline method for which info is registered * @param treeExpr A function that computes the tree to be inlined, given a context * This tree may still refer to non-public members. * @param ctx The current context is the one in which the tree is computed. It needs * to have the inlined method as owner. */ - def attachInlineInfo(inlineAnnot: Annotation, treeExpr: Context => Tree)(implicit ctx: Context): Unit = + def registerInlineInfo(sym: SymDenotation, treeExpr: Context => Tree)(implicit ctx: Context): Unit = { + val inlineAnnot = sym.unforcedAnnotation(defn.InlineAnnot).get inlineAnnot.tree.getAttachment(InlineInfo) match { case Some(inlineInfo) if inlineInfo.isEvaluated => // keep existing attachment case _ => if (!ctx.isAfterTyper) inlineAnnot.tree.putAttachment(InlineInfo, new InlineInfo(treeExpr, ctx)) } + } /** Optionally, the inline info attached to the `@inline` annotation of `sym`. */ private def inlineInfo(sym: SymDenotation)(implicit ctx: Context): Option[InlineInfo] = diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 6f730a585..5e2ff4164 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -566,17 +566,17 @@ class Namer { typer: Typer => val cls = typedAheadAnnotation(annotTree) val ann = Annotation.deferred(cls, implicit ctx => typedAnnotation(annotTree)) denot.addAnnotation(ann) - if (cls == defn.InlineAnnot) addInlineInfo(denot.symbol, ann, original) + if (cls == defn.InlineAnnot) addInlineInfo(denot, original) } case _ => } - private def addInlineInfo(inlineMethod: Symbol, inlineAnnot: Annotation, original: untpd.Tree) = original match { + private def addInlineInfo(denot: SymDenotation, original: untpd.Tree) = original match { case original: untpd.DefDef => - Inliner.attachInlineInfo( - inlineAnnot, + Inliner.registerInlineInfo( + denot, implicit ctx => typedAheadExpr(original).asInstanceOf[tpd.DefDef].rhs - )(localContext(inlineMethod)) + )(localContext(denot.symbol)) case _ => } diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index c8362522d..d1a2ad5c2 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1172,10 +1172,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val rhs1 = typedExpr(ddef.rhs, tpt1.tpe)(rhsCtx) // Overwrite inline body to make sure it is not evaluated twice - sym.getAnnotation(defn.InlineAnnot) match { - case Some(ann) => Inliner.attachInlineInfo(ann, ctx => rhs1) - case _ => - } + if (sym.hasAnnotation(defn.InlineAnnot)) + Inliner.registerInlineInfo(sym, ctx => rhs1) if (sym.isAnonymousFunction) { // If we define an anonymous function, make sure the return type does not |