Skip to content

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
merged 5 commits into from
Jan 13, 2018

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Jan 10, 2018

Usage:

> sbt
> dotc -Ythrough-tasty <.scala sources>

The /bin/dotc does not support this option.


val fromSourcesOut = Files.createTempDirectory(Paths.get("out").toAbsolutePath, "from-sources-tmp")

println(s"Compiling scala to sources to $fromSourcesOut")
Copy link
Contributor

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

Copy link
Contributor Author

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure out exist?

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 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 =>
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a temporary directory?

Copy link
Contributor Author

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()
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@smarter
Copy link
Member

smarter commented Jan 12, 2018

I would call the option something else than -Yfrom-tasty since it's a bit too easy to confuse it with -from-tasty.

@nicolasstucki
Copy link
Contributor Author

Any good ideas for the name of the flag?

@smarter
Copy link
Member

smarter commented Jan 12, 2018

-Ythrough-tasty ? :)

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

// see <https://groups.google.com/forum/#!topic/scala-user/kte6nak-zPM>.
val _ = NonFatal

assert(!args.contains("-d"))
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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")
Copy link
Contributor

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")
Copy link
Contributor

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"

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 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('/', '.')
Copy link
Contributor

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

Copy link
Contributor Author

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")
Copy link
Contributor

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

Copy link
Contributor Author

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")
Copy link
Contributor

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")
Copy link
Contributor

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"

Copy link
Contributor Author

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.

@allanrenucci allanrenucci removed their assignment Jan 12, 2018
@nicolasstucki nicolasstucki changed the title Add -Yfrom-tasty to debug from TASTY compilation direct from sources Add -Ythrough-tasty to debug from TASTY compilation direct from sources Jan 13, 2018
@nicolasstucki nicolasstucki merged commit 4cd1122 into scala:master Jan 13, 2018
@allanrenucci allanrenucci deleted the add-from-tasty-debug branch January 13, 2018 13:14
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