-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Test compilation of decompiled code #4266
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
Test compilation of decompiled code #4266
Conversation
b08eff1
to
4382eae
Compare
Currently it only tests compilation of decompiled code for which a |
This PR also contains a partial fix for module object decompilation. |
97ad093
to
b231f93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
@@ -631,7 +631,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { | |||
val tparamsTxt = withEnclosingDef(constr) { tparamsText(tparams) } | |||
val primaryConstrs = if (constr.rhs.isEmpty) Nil else constr :: Nil | |||
val prefix: Text = | |||
if (vparamss.isEmpty || primaryConstrs.nonEmpty) tparamsTxt | |||
if (constr.symbol.owner.is(Module)) " " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be the empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To print object Foo { .. }
instead of object Foo{ ... }
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But in puzzle.decompiled
I see two spaces after object Test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally fixed this one detail
new TASTYDecompiler | ||
} | ||
|
||
override def setup(args0: Array[String], rootCtx: Context): (List[String], Context) = { | ||
var args = args0.filter(a => a != "-decompile") | ||
args = if (args.contains("-from-tasty")) args else "-from-tasty" +: args | ||
if (!args.contains("-from-tasty")) args = "-from-tasty" +: args | ||
if (args.contains("-d")) args = "-color:never" +: args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we print colors in the output file it is impossible to read (and probably compile) the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we do this even if args
does not contain -d
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If args does not contain -d
the output is printed on the terminal. There it is fine and nicer to have colors. Also copy-pasting from the terminal usually removes the colors.
@@ -55,7 +55,11 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) { | |||
} | |||
|
|||
override protected def toTextTemplate(impl: Template, ofNew: Boolean = false): Text = { | |||
val impl1 = impl.copy(parents = impl.parents.filterNot(_.symbol.maybeOwner == defn.ObjectClass)) | |||
def filter(sym: Symbol): Boolean = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give a better name (e.g. isSyntheticParent
)
@@ -642,7 +643,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { | |||
val selfText = { | |||
val selfName = if (self.name == nme.WILDCARD) keywordStr("this") else self.name.toString | |||
(selfName ~ optText(self.tpt)(": " ~ _) ~ " =>").close | |||
} provided !self.isEmpty | |||
} provided (!self.isEmpty && !constr.symbol.owner.is(Module)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this should go into RefinedPrinter
. You could reproduce this behavior in DecompilerPrinter
by replacing the self type with an EmptyTree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will move it to DecompilerPrinter
def compileTastyInDir(f: String, flags0: TestFlags, blacklist: Set[String] = Set.empty)( | ||
implicit testGroup: TestGroup): (CompilationTest, CompilationTest, CompilationTest) = { | ||
def compileTastyInDir(f: String, flags0: TestFlags, blacklist: Set[String], recompileBlacklist: Set[String])( | ||
implicit testGroup: TestGroup): (CompilationTest, CompilationTest, CompilationTest, CompilationTest) = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably create the class TastyCompilationTest
and replace the returned Tuple4
Needs a new review after the changes
They only exist after step3 has been executed
e0c7506
to
6971c0d
Compare
176c787
to
5f5f474
Compare
RefinedPrinter cannot make use of symbols in order to be able to print after all phases (e.g. Parser).
5f5f474
to
3301cf4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @nicolasstucki please review last commit
Changes by @allanrenucci LGTM |
No description provided.