Skip to content

Add -print-tasty setting #3519

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 1 commit into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ScalaSettings extends Settings.SettingGroup {
val rewrite = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax")
val silentWarnings = BooleanSetting("-nowarn", "Silence all warnings.")
val fromTasty = BooleanSetting("-from-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.")
val printTasty = BooleanSetting("-print-tasty", "Prints the raw tasty when decompiling.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-picky: Should we add that -print-tasty can only be used together with -fromTasty? Or, as a blank before L45, to put tasty related options together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It must not necessarily be the case. In the future we might use it to print the pickled tasty while compiling without -from-tasty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently it can only be used with -decompile which is stated. -from-tasty has nothing to do with it.


/** -X "Advanced" settings
*/
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
def printContents(): Unit = {
println("Names:")
printNames()
println()
println("Trees:")
unpickle(new TreeSectionUnpickler)
unpickle(new PositionSectionUnpickler)
Expand Down Expand Up @@ -111,7 +112,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
val positions = new PositionUnpickler(reader).positions
println(s" position bytes:")
val sorted = positions.toSeq.sortBy(_._1.index)
for ((addr, pos) <- sorted) println(s"${addr.index}: ${offsetToInt(pos.start)} .. ${pos.end}")
for ((addr, pos) <- sorted) println(s" ${addr.index}: ${offsetToInt(pos.start)} .. ${pos.end}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package decompiler

import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.core.tasty.TastyPrinter

/** Phase that prints the trees in all loaded compilation units.
*
Expand All @@ -26,5 +27,10 @@ class DecompilationPrinter extends Phase {

println(unit.tpdTree.show)
println(line)

if (ctx.settings.printTasty.value) {
new TastyPrinter(unit.pickled.head._2).printContents()
println(line)
}
}
}