Skip to content

Use inline flag instead of @inline annotation #1677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,7 @@ object desugar {
*/
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = TypeTree(), inlineable: Boolean)(implicit ctx: Context) = {
var mods = synthetic
if (inlineable)
mods = mods.withAddedAnnotation(New(ref(defn.InlineAnnotType), Nil).withPos(body.pos))
if (inlineable) mods |= Inline
Block(
DefDef(nme.ANON_FUN, Nil, params :: Nil, tpt, body).withMods(mods),
Closure(Nil, Ident(nme.ANON_FUN), EmptyTree))
Expand Down
5 changes: 1 addition & 4 deletions src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,7 @@ object SymDenotations {
// def isOverridable: Boolean = !!! need to enforce that classes cannot be redefined
def isSkolem: Boolean = name == nme.SKOLEM

def isInlineMethod(implicit ctx: Context): Boolean =
is(Method, butNot = Accessor) &&
!isCompleting && // don't force method type; recursive inlines are ignored anyway.
hasAnnotation(defn.InlineAnnot)
def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the butNot still necessary? Do accessors get the inline flag too somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They might if we have an accessor of an inline val. Better play it safe.


// ------ access to related symbols ---------------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
sym.completer.withDecls(newScope)
forkAt(templateStart).indexTemplateParams()(localContext(sym))
}
else if (annots.exists(_.symbol == defn.InlineAnnot))
else if (sym.isInlineMethod)
sym.addAnnotation(LazyBodyAnnotation { ctx0 =>
implicit val ctx: Context = localContext(sym)(ctx0).addMode(Mode.ReadPositions)
// avoids space leaks by not capturing the current context
Expand Down
17 changes: 4 additions & 13 deletions src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ class Namer { typer: Typer =>
mergeCompanionDefs()
val ctxWithStats = (ctx /: stats) ((ctx, stat) => indexExpanded(stat)(ctx))
createCompanionLinks(ctxWithStats)
//stats foreach enterAnnotations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray comment?

ctxWithStats
}

Expand Down Expand Up @@ -568,19 +569,9 @@ class Namer { typer: Typer =>
val cls = typedAheadAnnotation(annotTree)
val ann = Annotation.deferred(cls, implicit ctx => typedAnnotation(annotTree))
denot.addAnnotation(ann)
if (cls == defn.InlineAnnot) {
hasInlineAnnot = true
addInlineInfo(denot, original)
}
}
if (!hasInlineAnnot && denot.is(InlineMethod)) {
// create a @inline annotation. Currently, the inlining trigger
// is really the annotation, not the flag. This is done so that
// we can still compile inline methods from Scala2x. Once we stop
// being compatible with Scala2 we should revise the logic to
// be based on the flag. Then creating a separate annotation becomes unnecessary.
denot.addAnnotation(Annotation(defn.InlineAnnot))
addInlineInfo(denot, original)
if (cls == defn.InlineAnnot && denot.is(Method, butNot = Accessor))
denot.setFlag(Inline)
if (denot.isInlineMethod) addInlineInfo(denot, original)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that addInlineInfo will be called for every annotation if the method is marked inline, previously hasInlineAnnot prevented that.

}
case _ =>
}
Expand Down
5 changes: 2 additions & 3 deletions src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
val vdef1 = assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
if (sym.is(Inline, butNot = DeferredOrParamAccessor))
checkInlineConformant(rhs1, "right-hand side of inline value")
checkInlineConformant(rhs1, em"right-hand side of inline $sym")
patchIfLazy(vdef1)
vdef1
}
Expand Down Expand Up @@ -1176,8 +1176,7 @@ 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
if (sym.hasAnnotation(defn.InlineAnnot))
Inliner.registerInlineInfo(sym, _ => rhs1)
if (sym.isInlineMethod) Inliner.registerInlineInfo(sym, _ => rhs1)

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