Skip to content

Commit 1293e2f

Browse files
committed
Emit empty .tasty files by default
Before this commit, we only created .tasty files under -YemitTasty, we haven't decided yet if this should be the default, but even if we don't end up doing that, it is still useful to emit empty .tasty files to signal that the corresponding .class file has a tasty section, this is much simpler to check than parsing classfiles to look for a tasty section. Also, fix -YemitTasty tof work with AbstractFile who are not backed by java.io.File, previously this lead to NullPointerException.
1 parent bfdf732 commit 1293e2f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Symbols._
2525
import Denotations._
2626
import Phases._
2727
import java.lang.AssertionError
28-
import java.io.{FileOutputStream, File => JFile}
28+
import java.io.{DataOutputStream, File => JFile}
2929

3030
import scala.tools.asm
3131
import scala.tools.asm.tree._
@@ -205,12 +205,16 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
205205
val dataAttr = new CustomAttr(nme.TASTYATTR.mangledString, binary)
206206
val store = if (mirrorC ne null) mirrorC else plainC
207207
store.visitAttribute(dataAttr)
208+
val outTastyFile = getFileForClassfile(outF, store.name, ".tasty")
208209
if (ctx.settings.emitTasty.value) {
209-
val outTastyFile = getFileForClassfile(outF, store.name, ".tasty").file
210-
val fos = new FileOutputStream(outTastyFile, false)
211-
fos.write(binary)
212-
fos.close()
213-
210+
val outstream = new DataOutputStream(outTastyFile.bufferedOutput)
211+
212+
try outstream.write(binary)
213+
finally outstream.close()
214+
} else if (!outTastyFile.isVirtual) {
215+
// Create an empty file to signal that a tasty section exist in the corresponding .class
216+
// This is much cheaper and simpler to check than doing classfile parsing
217+
outTastyFile.create()
214218
}
215219
}
216220

0 commit comments

Comments
 (0)