Skip to content

Commit 0d9dd7c

Browse files
committed
Use inline flag instead of @inline annotation
Convert `@inline` annotations to `inline` flags, not the other way round as was done before.
1 parent 913f76a commit 0d9dd7c

File tree

5 files changed

+9
-23
lines changed

5 files changed

+9
-23
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: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ class Namer { typer: Typer =>
521521
mergeCompanionDefs()
522522
val ctxWithStats = (ctx /: stats) ((ctx, stat) => indexExpanded(stat)(ctx))
523523
createCompanionLinks(ctxWithStats)
524+
//stats foreach enterAnnotations
524525
ctxWithStats
525526
}
526527

@@ -568,19 +569,9 @@ class Namer { typer: Typer =>
568569
val cls = typedAheadAnnotation(annotTree)
569570
val ann = Annotation.deferred(cls, implicit ctx => typedAnnotation(annotTree))
570571
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)
572+
if (cls == defn.InlineAnnot && denot.is(Method, butNot = Accessor))
573+
denot.setFlag(Inline)
574+
if (denot.isInlineMethod) addInlineInfo(denot, original)
584575
}
585576
case _ =>
586577
}

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)