@@ -8,7 +8,7 @@ import java.nio.file.Path
8
8
import java .util .{Arrays , EnumSet }
9
9
10
10
import dotty .tools .dotc .ast .tpd
11
- import dotty .tools .dotc .classpath .FileUtils .{isTasty , isClassExtension , isTastyExtension }
11
+ import dotty .tools .dotc .classpath .FileUtils .{isTasty , hasClassExtension , hasTastyExtension }
12
12
import dotty .tools .dotc .core .Contexts ._
13
13
import dotty .tools .dotc .core .Decorators ._
14
14
import dotty .tools .dotc .core .Flags ._
@@ -424,10 +424,28 @@ class DependencyRecorder {
424
424
classDependencies.foreach(recordClassDependency(cb, _))
425
425
clear()
426
426
427
+ private val _siblingClassfiles = new mutable.HashMap [PlainFile , Path ]
428
+
429
+ extension (pf : PlainFile )
430
+ /** Constructs a sibling class to the `jpath`.
431
+ * Does not validate if it exists as a real file.
432
+ * The way this works is that by the end of compilation analysis,
433
+ * there should be a corresponding NonLocalClass sent to zinc with the same class file name.
434
+ *
435
+ * FIXME: we still need a way to resolve the correct classfile when we split tasty and classes between
436
+ * different outputs (e.g. stdlib-bootstrapped).
437
+ */
438
+ private def siblingClass : Path =
439
+ _siblingClassfiles.getOrElseUpdate(pf, {
440
+ val jpath = pf.jpath
441
+ jpath.getParent.resolve(jpath.getFileName.toString.stripSuffix(" .tasty" ) + " .class" )
442
+ })
443
+
427
444
/** Clear all state. */
428
445
def clear (): Unit =
429
446
_usedNames.clear()
430
447
_classDependencies.clear()
448
+ _siblingClassfiles.clear()
431
449
lastOwner = NoSymbol
432
450
lastDepSource = NoSymbol
433
451
_responsibleForImports = NoSymbol
@@ -440,18 +458,18 @@ class DependencyRecorder {
440
458
val fromClassName = classNameAsString(dep.fromClass)
441
459
val sourceFile = ctx.compilationUnit.source
442
460
443
- def binaryDependency (file : Path , binaryClassName : String ) =
444
- cb.binaryDependency(file , binaryClassName, fromClassName, sourceFile, dep.context)
461
+ def binaryDependency (path : Path , binaryClassName : String ) =
462
+ cb.binaryDependency(path , binaryClassName, fromClassName, sourceFile, dep.context)
445
463
446
- def processExternalDependency (depFile : AbstractFile , binaryClassName : String ) = {
464
+ def processExternalDependency (depFile : AbstractFile , binaryClassName : String , convertTasty : Boolean ) = {
447
465
depFile match {
448
466
case ze : ZipArchive # Entry => // The dependency comes from a JAR
449
467
ze.underlyingSource match
450
468
case Some (zip) if zip.jpath != null =>
451
469
binaryDependency(zip.jpath, binaryClassName)
452
470
case _ =>
453
471
case pf : PlainFile => // The dependency comes from a class file, Zinc handles JRT filesystem
454
- binaryDependency(pf.jpath, binaryClassName)
472
+ binaryDependency(if convertTasty then pf.siblingClass else pf.jpath, binaryClassName)
455
473
case _ =>
456
474
internalError(s " Ignoring dependency $depFile of unknown class ${depFile.getClass}} " , dep.fromClass.srcPos)
457
475
}
@@ -461,15 +479,10 @@ class DependencyRecorder {
461
479
if depFile != null then {
462
480
// Cannot ignore inheritance relationship coming from the same source (see sbt/zinc#417)
463
481
def allowLocal = dep.context == DependencyByInheritance || dep.context == LocalDependencyByInheritance
464
- if depFile.isTastyExtension then
465
- val depClassFile = ctx.getSiblingClassfile(depFile)
466
- if depClassFile != NoAbstractFile then
467
- // did not find associated class file, e.g. for a TASTy-only classpath.
468
- // The file that Zinc recieves with binaryDependency is used to lookup any either any
469
- // generated non-local classes or produced xsbti.API associated with the file.
470
- processExternalDependency(depClassFile, dep.toClass.binaryClassName)
471
- else if depFile.isClassExtension then
472
- processExternalDependency(depFile, dep.toClass.binaryClassName)
482
+ if depFile.hasTastyExtension then
483
+ processExternalDependency(depFile, dep.toClass.binaryClassName, convertTasty = true )
484
+ else if depFile.hasClassExtension then
485
+ processExternalDependency(depFile, dep.toClass.binaryClassName, convertTasty = false )
473
486
else if allowLocal || depFile != sourceFile.file then
474
487
// We cannot ignore dependencies coming from the same source file because
475
488
// the dependency info needs to propagate. See source-dependencies/trait-trait-211.
0 commit comments