Skip to content

Fix decompilation of while loops #4584

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 4 commits into from
Jun 9, 2018

Conversation

nicolasstucki
Copy link
Contributor

Show that there is no semantic difference between inline functions and by name functions.

@nicolasstucki
Copy link
Contributor Author

@odersky here are some examples of inline Int => Unit and => Int => Unit macro arguments. Both get inlined if spliced with ~f.apply('(i)) which uses the quoted.Exprs.FunctionAppliedTo to perform the beta reduction on the aplication. From the inline macro perspective inline functions are useless.

@odersky
Copy link
Contributor

odersky commented Jun 6, 2018

We are bout to disallow inline parameters of function type anyway. So should we close this commit?

@odersky odersky assigned nicolasstucki and unassigned odersky Jun 6, 2018
@nicolasstucki
Copy link
Contributor Author

I will remove the inline function part and keep the by name functions as regression tests

@nicolasstucki nicolasstucki changed the title Fix inline function types as macros args Regression test on by name function types as macros args Jun 6, 2018
* Show that there is no semantic difference between
  inline functions and by name functions
@nicolasstucki nicolasstucki force-pushed the fix-inline-function branch from c1b4c72 to 3e8b773 Compare June 6, 2018 14:42
@nicolasstucki nicolasstucki removed the request for review from odersky June 6, 2018 14:42
@nicolasstucki nicolasstucki changed the title Regression test on by name function types as macros args Fix decompilation of while loops Jun 6, 2018
@nicolasstucki
Copy link
Contributor Author

Found a regression

allanrenucci
allanrenucci previously approved these changes Jun 6, 2018
@@ -225,7 +245,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
this += " = "
printTree(rhs)

case Term.Block(stats, expr) =>
case Term.Block(stats0, expr) =>
def isLoopContinue(tree: Tree): Boolean = tree match {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename is isLoopEntryPoint?

@nicolasstucki nicolasstucki force-pushed the fix-inline-function branch from 3e8b773 to fdff56e Compare June 6, 2018 18:51
@nicolasstucki nicolasstucki force-pushed the fix-inline-function branch from fdff56e to 9db9d9b Compare June 6, 2018 19:00
@nicolasstucki nicolasstucki dismissed allanrenucci’s stale review June 6, 2018 19:34

Reviewed all version

@nicolasstucki
Copy link
Contributor Author

@allanrenucci this needs a review as the code completely changed

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

printTree(cond)
this += ")"

case expr if isLoopEntryPoint(expr) && stats.size == 1 =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be cleaner to have this case be part of the extractor:

def unapply(arg: Tree)(implicit ctx: Context): Option[(Term, List[Statement])] = arg match {
  case DefDef("while$", _, _, _, Some(Term.If(cond, Term.Block(bodyStats, _), _))) => Some((cond, bodyStats))
  case Block(List(tree), _) => unapply(tree)
  case _ => None
}

@@ -753,6 +748,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
private object While {
def unapply(arg: Tree)(implicit ctx: Context): Option[(Term, List[Statement])] = arg match {
case DefDef("while$", _, _, _, Some(Term.If(cond, Term.Block(bodyStats, _), _))) => Some((cond, bodyStats))
case Term.Block(List(tree), _) => unapply(tree)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose you will need to add the same case for the DoWhile extractor

@nicolasstucki nicolasstucki force-pushed the fix-inline-function branch from 612feb2 to 75b315b Compare June 8, 2018 20:27
@nicolasstucki nicolasstucki merged commit b369dcf into scala:master Jun 9, 2018
@Blaisorblade Blaisorblade deleted the fix-inline-function branch June 9, 2018 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants