Skip to content

Commit 28c2e04

Browse files
authored
Merge pull request #1677 from dotty-staging/fix-#1647
Use inline flag instead of @inline annotation
2 parents ab652d1 + 2e02b29 commit 28c2e04

File tree

5 files changed

+10
-25
lines changed

5 files changed

+10
-25
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,7 @@ object desugar {
615615
*/
616616
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = TypeTree(), inlineable: Boolean)(implicit ctx: Context) = {
617617
var mods = synthetic
618-
if (inlineable)
619-
mods = mods.withAddedAnnotation(New(ref(defn.InlineAnnotType), Nil).withPos(body.pos))
618+
if (inlineable) mods |= Inline
620619
Block(
621620
DefDef(nme.ANON_FUN, Nil, params :: Nil, tpt, body).withMods(mods),
622621
Closure(Nil, Ident(nme.ANON_FUN), EmptyTree))

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,10 +751,7 @@ object SymDenotations {
751751
// def isOverridable: Boolean = !!! need to enforce that classes cannot be redefined
752752
def isSkolem: Boolean = name == nme.SKOLEM
753753

754-
def isInlineMethod(implicit ctx: Context): Boolean =
755-
is(Method, butNot = Accessor) &&
756-
!isCompleting && // don't force method type; recursive inlines are ignored anyway.
757-
hasAnnotation(defn.InlineAnnot)
754+
def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor)
758755

759756
// ------ access to related symbols ---------------------------------
760757

src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
474474
sym.completer.withDecls(newScope)
475475
forkAt(templateStart).indexTemplateParams()(localContext(sym))
476476
}
477-
else if (annots.exists(_.symbol == defn.InlineAnnot))
477+
else if (sym.isInlineMethod)
478478
sym.addAnnotation(LazyBodyAnnotation { ctx0 =>
479479
implicit val ctx: Context = localContext(sym)(ctx0).addMode(Mode.ReadPositions)
480480
// avoids space leaks by not capturing the current context

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -568,25 +568,14 @@ class Namer { typer: Typer =>
568568
val cls = typedAheadAnnotation(annotTree)
569569
val ann = Annotation.deferred(cls, implicit ctx => typedAnnotation(annotTree))
570570
denot.addAnnotation(ann)
571-
if (cls == defn.InlineAnnot) {
572-
hasInlineAnnot = true
573-
addInlineInfo(denot, original)
574-
}
575-
}
576-
if (!hasInlineAnnot && denot.is(InlineMethod)) {
577-
// create a @inline annotation. Currently, the inlining trigger
578-
// is really the annotation, not the flag. This is done so that
579-
// we can still compile inline methods from Scala2x. Once we stop
580-
// being compatible with Scala2 we should revise the logic to
581-
// be based on the flag. Then creating a separate annotation becomes unnecessary.
582-
denot.addAnnotation(Annotation(defn.InlineAnnot))
583-
addInlineInfo(denot, original)
571+
if (cls == defn.InlineAnnot && denot.is(Method, butNot = Accessor))
572+
denot.setFlag(Inline)
584573
}
585574
case _ =>
586575
}
587576

588-
private def addInlineInfo(denot: SymDenotation, original: untpd.Tree) = original match {
589-
case original: untpd.DefDef =>
577+
private def addInlineInfo(denot: SymDenotation) = original match {
578+
case original: untpd.DefDef if denot.isInlineMethod =>
590579
Inliner.registerInlineInfo(
591580
denot,
592581
implicit ctx => typedAheadExpr(original).asInstanceOf[tpd.DefDef].rhs
@@ -599,6 +588,7 @@ class Namer { typer: Typer =>
599588
*/
600589
def completeInCreationContext(denot: SymDenotation): Unit = {
601590
addAnnotations(denot)
591+
addInlineInfo(denot)
602592
denot.info = typeSig(denot.symbol)
603593
Checking.checkWellFormed(denot.symbol)
604594
}

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11421142
}
11431143
val vdef1 = assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
11441144
if (sym.is(Inline, butNot = DeferredOrParamAccessor))
1145-
checkInlineConformant(rhs1, "right-hand side of inline value")
1145+
checkInlineConformant(rhs1, em"right-hand side of inline $sym")
11461146
patchIfLazy(vdef1)
11471147
vdef1
11481148
}
@@ -1176,8 +1176,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11761176
val rhs1 = typedExpr(ddef.rhs, tpt1.tpe)(rhsCtx)
11771177

11781178
// Overwrite inline body to make sure it is not evaluated twice
1179-
if (sym.hasAnnotation(defn.InlineAnnot))
1180-
Inliner.registerInlineInfo(sym, _ => rhs1)
1179+
if (sym.isInlineMethod) Inliner.registerInlineInfo(sym, _ => rhs1)
11811180

11821181
if (sym.isAnonymousFunction) {
11831182
// If we define an anonymous function, make sure the return type does not

0 commit comments

Comments
 (0)