-
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
Add -Ythrough-tasty to debug from TASTY compilation direct from sources #3786
Conversation
|
||
val fromSourcesOut = Files.createTempDirectory(Paths.get("out").toAbsolutePath, "from-sources-tmp") | ||
|
||
println(s"Compiling scala to sources to $fromSourcesOut") |
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.
No sure it useful to print the output directory since the file will be deleted when the program exit
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.
We do not delete them in case of failure. I will print the directories only in case of failure.
println("From tasty debug driver") | ||
assert(!args.contains("-d")) | ||
|
||
val fromSourcesOut = Files.createTempDirectory(Paths.get("out").toAbsolutePath, "from-sources-tmp") |
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.
Make sure out
exist?
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.
It works only on sbt dotc
, out
should exist.
val fromTastyOut = Files.createTempDirectory(Paths.get("out").toAbsolutePath, "from-tasty-tmp") | ||
|
||
val ext = "hasTasty" | ||
val classes = Path(fromSourcesOut).walk.filter(x => x.isFile && x.extension == ext).map { x => |
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.
Directory
sys.exit(1) | ||
} | ||
|
||
val fromTastyOut = Files.createTempDirectory(Paths.get("out").toAbsolutePath, "from-tasty-tmp") |
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 a temporary directory?
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 ensure it is a clean directory and the only contents are the ones coming from this compilation.
sys.exit(1) | ||
} | ||
|
||
Path(fromSourcesOut).deleteRecursively() |
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.
Is this needed if the directory is temporary?
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.
Those temporary directories do not delete themselves. The deleteOnExit
is not set by default on them.
I would call the option something else than -Yfrom-tasty since it's a bit too easy to confuse it with -from-tasty. |
Any good ideas for the name of the flag? |
-Ythrough-tasty ? :) |
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
// see <https://groups.google.com/forum/#!topic/scala-user/kte6nak-zPM>. | ||
val _ = NonFatal | ||
|
||
assert(!args.contains("-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.
Could this tool support the -d
option? I think it would nice. Maybe use it as the base director instead of out
if specified
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 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.
|
||
val fromSourcesOut = Files.createDirectory(tmpOut.resolve("from-source")) | ||
|
||
println(s"Compiling .scala") |
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.
Since you pointed out to me that temporary directory are not deleted on exit, I would revert to you previous version: s"Compiling from sources to $fromSourcesOut"
val compilation1 = dotc.Main.process("-d" +: fromSourcesOut.toString +: args) | ||
|
||
if (compilation1.hasErrors) { | ||
println("Failed compilation from sources") |
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.
I would remove this. If the compilation failed, the compiler already tells you "error found"
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.
It would not tell me which of the two compilation failed.
val ext = "hasTasty" | ||
val classes = Directory(fromSourcesOut).walk.filter(x => x.isFile && x.extension == ext).map { x => | ||
val source = x.toString | ||
source.substring(fromSourcesOut.toString.length + 1, source.length - ext.length - 1).replace('/', '.') |
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.
Maybe add a comment to explain what this does
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.
ok
|
||
val fromSourcesOut = Files.createDirectory(tmpOut.resolve("from-source")) | ||
|
||
println(s"Compiling .scala") |
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.
"Compiling from source..."
? Also the s
interpolator is not needed
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.
I will change it to Compiling from .scala sources
as in the second step the sources are the .class
files.
I will change the second one to Compiling TASTY from .class sources
to also be explicit.
classes | ||
} | ||
|
||
println(s"Compiling TASTY") |
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.
"Compiling from TASTY..."? Also the s
interpolator is not needed
val compilation2 = dotc.Main.process(fromTastyArgs.toArray) | ||
|
||
if (compilation2.hasErrors) { | ||
println("Failed compilation from TASTY") |
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.
I would remove this. If the compilation failed, the compiler already tells you "error found"
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.
The issue is that the errors will not tell you which of the compilation failed. I prefer to be explicit, so anyone that uses the tool know exactly what is happening.
Usage:
The
/bin/dotc
does not support this option.