-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add -Ythrough-tasty to debug from TASTY compilation direct from sources #3786
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
nicolasstucki
merged 5 commits into
scala:master
from
dotty-staging:add-from-tasty-debug
Jan 13, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19c13f3
Add -Yfrom-tasty to debug from TASTY compilation direct from sources
nicolasstucki cf0212f
Improve fromtasty.Debug
nicolasstucki d525de3
Rename -Yfrom-tasty to -Ythrough-tasty
nicolasstucki d992f6c
Create ./out if it does not exist
nicolasstucki 4b1385e
Improve messages
nicolasstucki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package dotty.tools | ||
package dotc | ||
package fromtasty | ||
|
||
import scala.util.control.NonFatal | ||
|
||
import dotty.tools.io.Directory | ||
|
||
import java.nio.file.{Files, Paths} | ||
|
||
object Debug { | ||
def main(args: Array[String]): Unit = { | ||
// Preload scala.util.control.NonFatal. Otherwise, when trying to catch a StackOverflowError, | ||
// we may try to load it but fail with another StackOverflowError and lose the original exception, | ||
// see <https://groups.google.com/forum/#!topic/scala-user/kte6nak-zPM>. | ||
val _ = NonFatal | ||
|
||
assert(!args.contains("-d")) | ||
|
||
val outPath = Paths.get("out") | ||
Directory(outPath).createDirectory() | ||
|
||
val tmpOut = Files.createTempDirectory(outPath.toAbsolutePath, "from-tasty-tmp") | ||
|
||
val fromSourcesOut = Files.createDirectory(tmpOut.resolve("from-source")) | ||
|
||
println("Compiling from .scala sources") | ||
val compilation1 = dotc.Main.process("-d" +: fromSourcesOut.toString +: args) | ||
|
||
if (compilation1.hasErrors) { | ||
println("Failed compilation from sources") | ||
Directory(tmpOut).deleteRecursively() | ||
sys.exit(1) | ||
} | ||
|
||
val fromTastyOut = Files.createDirectory(tmpOut.resolve("from-tasty")) | ||
|
||
val ext = "hasTasty" | ||
val classes = Directory(fromSourcesOut).walk.filter(x => x.isFile && x.extension == ext).map { x => | ||
val source = x.toString | ||
// transform foo/bar/Baz.hasTasty into foo.bar.Baz | ||
source.substring(fromSourcesOut.toString.length + 1, source.length - ext.length - 1).replace('/', '.') | ||
}.toList | ||
|
||
val fromTastyArgs = { | ||
"-from-tasty" :: | ||
"-d" :: fromTastyOut.toString :: | ||
insertClasspathInArgs(args.filterNot(_.endsWith(".scala")).toList, fromSourcesOut.toString) ::: | ||
classes | ||
} | ||
|
||
println("Compiling TASTY from .class sources") | ||
val compilation2 = dotc.Main.process(fromTastyArgs.toArray) | ||
|
||
if (compilation2.hasErrors) { | ||
println("Failed compilation from TASTY") | ||
println("Compilation input: " + fromSourcesOut) | ||
// In this case we do not delete the generated class files to allow further debugging. | ||
// For example `dotc -decompile` on one of the intermediate class files. | ||
sys.exit(1) | ||
} | ||
|
||
Directory(tmpOut).deleteRecursively() | ||
} | ||
|
||
private def insertClasspathInArgs(args: List[String], cp: String): List[String] = { | ||
val (beforeCp, fromCp) = args.span(_ != "-classpath") | ||
val classpath = fromCp.drop(1).headOption.fold(cp)(_ + ":" + cp) | ||
"-classpath" :: classpath :: beforeCp ::: fromCp.drop(2) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could this tool support the
-d
option? I think it would nice. Maybe use it as the base director instead ofout
if specifiedThere 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 someone needs that feature in the future, he can implement it.
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.
That would actually be unsafe. For the test to be reproducible the output directory needs to be empty.