Skip to content

Fix #3515: Do not save tasty in .class with -YemitTasty #3517

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 3 commits into from
Nov 23, 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
28 changes: 16 additions & 12 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,24 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter

if (claszSymbol.isClass) // @DarkDimius is this test needed here?
for (binary <- ctx.compilationUnit.pickled.get(claszSymbol.asClass)) {
val dataAttr = new CustomAttr(nme.TASTYATTR.mangledString, binary)
val store = if (mirrorC ne null) mirrorC else plainC
val tasty =
if (ctx.settings.emitTasty.value) {
val outTastyFile = getFileForClassfile(outF, store.name, ".tasty")
val outstream = new DataOutputStream(outTastyFile.bufferedOutput)
try outstream.write(binary)
finally outstream.close()
// TASTY attribute is created but 0 bytes are stored in it.
// A TASTY attribute has length 0 if and only if the .tasty file exists.
Array.empty[Byte]
} else {
// Create an empty file to signal that a tasty section exist in the corresponding .class
// This is much cheaper and simpler to check than doing classfile parsing
getFileForClassfile(outF, store.name, ".hasTasty")
binary
}
val dataAttr = new CustomAttr(nme.TASTYATTR.mangledString, tasty)
store.visitAttribute(dataAttr)
if (ctx.settings.emitTasty.value) {
val outTastyFile = getFileForClassfile(outF, store.name, ".tasty")
val outstream = new DataOutputStream(outTastyFile.bufferedOutput)

try outstream.write(binary)
finally outstream.close()
} else {
// Create an empty file to signal that a tasty section exist in the corresponding .class
// This is much cheaper and simpler to check than doing classfile parsing
getFileForClassfile(outF, store.name, ".hasTasty")
}
}

// -------------- bean info class, if needed --------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scala.collection.{ mutable, immutable }
import scala.collection.mutable.{ ListBuffer, ArrayBuffer }
import scala.annotation.switch
import typer.Checking.checkNonCyclic
import io.AbstractFile
import io.{AbstractFile, PlainFile}
import scala.util.control.NonFatal

object ClassfileParser {
Expand Down Expand Up @@ -781,7 +781,13 @@ class ClassfileParser(

if (scan(tpnme.TASTYATTR)) {
val attrLen = in.nextInt
return unpickleTASTY(in.nextBytes(attrLen))
if (attrLen == 0) {
// A tasty attribute implies the existence of the .tasty file
val file = new PlainFile(io.File(classfile.jpath).changeExtension("tasty"))
if (file.exists) return unpickleTASTY(new AbstractFileReader(file).nextBytes(file.sizeOption.get))
else ctx.error("Could not find " + file)
}
else return unpickleTASTY(in.nextBytes(attrLen))
}

if (scan(tpnme.ScalaATTR) && !scalaUnpickleWhitelist.contains(classRoot.name)) {
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CompilationTests extends ParallelTesting {
compileFilesInDir("../tests/pos-scala2", scala2Mode) +
compileFilesInDir("../tests/pos", defaultOptions) +
compileFilesInDir("../tests/pos-deep-subtype", allowDeepSubtypes) +
compileDir("../tests/pos/i1137-1", defaultOptions and "-YemitTasty") +
compileFile(
// succeeds despite -Xfatal-warnings because of -nowarn
"../tests/neg/customArgs/xfatalWarnings.scala",
Expand Down