Skip to content

Commit 68342ba

Browse files
committed
Only allow jar and tasty as input for -from-tasty
This ensures that we don't accidentally load other versions of the classes that are on the current classpath.
1 parent ca67e4d commit 68342ba

File tree

5 files changed

+18
-82
lines changed

5 files changed

+18
-82
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,28 @@ class Driver {
8686
protected def fromTastySetup(fileNames0: List[String], ctx0: Context): (List[String], Context) =
8787
given Context = ctx0
8888
if (ctx0.settings.fromTasty.value) {
89+
val fromTastyFilter = ctx0.settings.YfromTastyFilter.value
90+
val filter =
91+
if fromTastyFilter.isEmpty then ".*".r
92+
else fromTastyFilter.r
8993
// Resolve classpath and class names of tasty files
90-
val (classPaths, classNames) = fileNames0.flatMap { name =>
91-
val path = Paths.get(name)
92-
if (name.endsWith(".jar"))
93-
new dotty.tools.io.Jar(File(name)).toList.collect {
94-
case e if e.getName.endsWith(".tasty") =>
95-
(name, e.getName.stripSuffix(".tasty").replace("/", "."))
94+
val (classPaths, classNames) = fileNames0.flatMap { fileName =>
95+
val path = Paths.get(fileName)
96+
if (fileName.endsWith(".jar"))
97+
new dotty.tools.io.Jar(File(fileName)).toList.collect {
98+
case e if e.getName.endsWith(".tasty") && filter.matches(e.getName) =>
99+
(fileName, e.getName.stripSuffix(".tasty").replace("/", "."))
96100
}
97-
else if (!name.endsWith(".tasty"))
98-
("", name) :: Nil
99-
else if (Files.exists(path))
101+
else if Files.exists(path) then
100102
TastyFileUtil.getClassName(path) match {
101103
case Some(res) => res:: Nil
102104
case _ =>
103-
report.error(s"Could not load classname from $name.")
104-
("", name) :: Nil
105+
report.error(s"Could not load classname from: $fileName")
106+
Nil
105107
}
106108
else {
107-
report.error(s"File $name does not exist.")
108-
("", name) :: Nil
109+
report.error(s"File not found: $fileName")
110+
Nil
109111
}
110112
}.unzip
111113
val ctx1 = ctx0.fresh

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ScalaSettings extends Settings.SettingGroup {
4545
val language: Setting[List[String]] = MultiStringSetting("-language", "feature", "Enable one or more language features.") withAbbreviation "--language"
4646
val rewrite: Setting[Option[Rewrites]] = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with a `...-migration` source version, rewrites sources to migrate to new version.") withAbbreviation "--rewrite"
4747
val silentWarnings: Setting[Boolean] = BooleanSetting("-nowarn", "Silence all warnings.") withAbbreviation "--no-warnings"
48-
val fromTasty: Setting[Boolean] = BooleanSetting("-from-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.") withAbbreviation "--from-tasty"
48+
val fromTasty: Setting[Boolean] = BooleanSetting("-from-tasty", "Compile classes from tasty files. The arguments are .tasty or .jar files.") withAbbreviation "--from-tasty"
4949

5050
val newSyntax: Setting[Boolean] = BooleanSetting("-new-syntax", "Require `then` and `do` in control expressions.")
5151
val oldSyntax: Setting[Boolean] = BooleanSetting("-old-syntax", "Require `(...)` around conditions.")
@@ -158,6 +158,7 @@ class ScalaSettings extends Settings.SettingGroup {
158158
val YretainTrees: Setting[Boolean] = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
159159
val Ysemanticdb: Setting[Boolean] = BooleanSetting("-Ysemanticdb", "Store information in SemanticDB.")
160160
val YshowTreeIds: Setting[Boolean] = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
161+
val YfromTastyFilter: Setting[String] = StringSetting("-Yfrom-tasty-filter", "file", "Filter tasty files in jar files when using -from-tasty", "")
161162

162163
val YprofileEnabled: Setting[Boolean] = BooleanSetting("-Yprofile-enabled", "Enable profiling.")
163164
val YprofileDestination: Setting[String] = StringSetting("-Yprofile-destination", "file", "Where to send profiling output - specify a file, default is to the console.", "")

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
504504
tastyOutput.mkdir()
505505
val flags = flags0 and ("-d", tastyOutput.getPath) and "-from-tasty"
506506

507-
def tastyFileToClassName(f: JFile): String = {
508-
val pathStr = targetDir.toPath.relativize(f.toPath).toString.replace(JFile.separatorChar, '.')
509-
pathStr.stripSuffix(".tasty").stripSuffix(".hasTasty")
510-
}
511-
val classes = flattenFiles(targetDir).filter(isTastyFile).map(tastyFileToClassName)
507+
val classes = flattenFiles(targetDir).filter(isTastyFile).map(_.toString)
512508

513509
val reporter =
514510
TestReporter.reporter(realStdout, logLevel =

tests/run-custom-args/tasty-inspector/i8215.scala

Lines changed: 0 additions & 41 deletions
This file was deleted.

tests/run-custom-args/tasty-inspector/i8558.scala

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)