Skip to content

Don't use empty files to indicate presence of tasty in class path. #2569

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 1 commit into from
May 29, 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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
val dataAttr = new CustomAttr(nme.TASTYATTR.mangledString, binary)
val store = if (mirrorC ne null) mirrorC else plainC
store.visitAttribute(dataAttr)
val outTastyFile = getFileForClassfile(outF, store.name, ".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()
} else if (!outTastyFile.isVirtual) {
} 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
outTastyFile.create()
getFileForClassfile(outF, store.name, ".hasTasty")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ class InteractiveDriver(settings: List[String]) extends Driver {
binFile.name.stripSuffix(".class")
else
null
// Presence of a file with one of these suffixes indicates that the
// corresponding class has been pickled with TASTY.
val tastySuffixes = List(".hasTasty", ".tasty")
prefix != null && {
val tastyFile = prefix + ".tasty"
binFile match {
case pf: PlainFile =>
val tastyPath = pf.givenPath.parent / tastyFile
tastyPath.exists
tastySuffixes.map(suffix => pf.givenPath.parent / (prefix + suffix)).exists(_.exists)
case _ =>
sys.error(s"Unhandled file type: $binFile [getClass = ${binFile.getClass}]")
}
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ object Build {


sbtPlugin := true,
version := "0.1.0",
version := "0.1.1",
ScriptedPlugin.scriptedSettings,
ScriptedPlugin.sbtTestDirectory := baseDirectory.value / "sbt-test",
ScriptedPlugin.scriptedBufferLog := false,
Expand Down
12 changes: 6 additions & 6 deletions sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,27 @@ object DottyPlugin extends AutoPlugin {
}
}

/** Patches the IncOptions so that .tasty files are pruned as needed.
/** Patches the IncOptions so that .tasty and .hasTasty files are pruned as needed.
*
* This code is adapted from `scalaJSPatchIncOptions` in Scala.js, which needs
* to do the exact same thing but for classfiles.
*
* This complicated logic patches the ClassfileManager factory of the given
* IncOptions with one that is aware of .tasty files emitted by the Dotty
* IncOptions with one that is aware of .tasty and .hasTasty files emitted by the Dotty
* compiler. This makes sure that, when a .class file must be deleted, the
* corresponding .tasty file is also deleted.
* corresponding .tasty or .hasTasty file is also deleted.
*/
def dottyPatchIncOptions(incOptions: IncOptions): IncOptions = {
val inheritedNewClassfileManager = incOptions.newClassfileManager
val newClassfileManager = () => new ClassfileManager {
private[this] val inherited = inheritedNewClassfileManager()

def delete(classes: Iterable[File]): Unit = {
val tastySuffixes = List(".tasty", ".hasTasty")
inherited.delete(classes flatMap { classFile =>
val dottyFiles = if (classFile.getPath endsWith ".class") {
val f = new File(classFile.getAbsolutePath.stripSuffix(".class") + ".tasty")
if (f.exists) List(f)
else Nil
val prefix = classFile.getAbsolutePath.stripSuffix(".class")
tastySuffixes.map(suffix => new File(prefix + suffix)).filter(_.exists)
} else Nil
classFile :: dottyFiles
})
Expand Down