Skip to content

Simplify enclosedInlineds #4990

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 2 commits into from
Aug 24, 2018
Merged
Changes from all commits
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
30 changes: 18 additions & 12 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1082,21 +1082,27 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
/** A key to be used in a context property that tracks enclosing inlined calls */
private val InlinedCalls = new Property.Key[List[Tree]]

override def inlineContext(call: Tree)(implicit ctx: Context): Context =
ctx.fresh.setProperty(InlinedCalls, call :: enclosingInlineds)

/** All enclosing calls that are currently inlined, from innermost to outermost.
* EmptyTree calls cancel the next-enclosing non-empty call in the list
*/
def enclosingInlineds(implicit ctx: Context): List[Tree] = {
def normalize(ts: List[Tree]): List[Tree] = ts match {
case t :: (ts1 @ (t1 :: ts2)) if t.isEmpty => normalize(if (t1.isEmpty) ts1 else ts2)
case t :: ts1 => t :: normalize(ts1)
case Nil => Nil
/** Record an enclosing inlined call.
* EmptyTree calls (for parameters) cancel the next-enclosing call in the list instead of being added to it.
* We assume parameters are never nested inside parameters.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WIP further experiments suggest this can't be true, even tho this code works.

Copy link
Contributor

Choose a reason for hiding this comment

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

After normalization, we should not have them, so it should be fine or the normalization was not performed correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True after normalization — I thought that was also true before normalization, but that was wrong.

*/
override def inlineContext(call: Tree)(implicit ctx: Context): Context = {
// We assume enclosingInlineds is already normalized, and only process the new call with the head.
val oldIC = enclosingInlineds
val newIC = (call, oldIC) match {
case (t, t1 :: ts2) if t.isEmpty =>
assert(!t1.isEmpty)
ts2
case _ => call :: oldIC
}
normalize(ctx.property(InlinedCalls).getOrElse(Nil))
ctx.fresh.setProperty(InlinedCalls, newIC)
}

/** All enclosing calls that are currently inlined, from innermost to outermost.
*/
def enclosingInlineds(implicit ctx: Context): List[Tree] =
ctx.property(InlinedCalls).getOrElse(Nil)

/** The source file where the symbol of the `inline` method referred to by `call`
* is defined
*/
Expand Down