Dotty Documentation

0.1.1-bin-SNAPSHOT

private class ExtractDependenciesCollector
extends TreeTraverser

Extract the dependency information of a compilation unit.

To understand why we track the used names see the section "Name hashing algorithm" in http://www.scala-sbt.org/0.13/docs/Understanding-Recompilation.html To understand why we need to track dependencies introduced by inheritance specially, see the subsection "Dependencies introduced by member reference and inheritance" in the "Name hashing algorithm" section.

[-] Constructors

ExtractDependenciesCollector ( )
ExtractDependenciesCollector ( implicit ctx: Context )

[-] Members

[+] private object usedTypeTraverser

Traverse a used type and record all the dependencies we need to keep track of for incremental recompilation.

As a motivating example, given a type T defined as:

type T >: L <: H type L <: A1 type H <: B1 class A1 extends A0 class B1 extends B0

We need to record a dependency on T, L, H, A1, B1. This is necessary because the API representation that ExtractAPI produces for T just refers to the strings "L" and "H", it does not contain their API representation. Therefore, the name hash of T does not change if for example the definition of L changes.

We do not need to keep track of superclasses like A0 and B0 because the API representation of a class (and therefore its name hash) already contains all necessary information on superclasses.

A natural question to ask is: Since traversing all referenced types to find all these names is costly, why not change the API representation produced by ExtractAPI to contain that information? This way the name hash of T would change if any of the types it depends on change, and we would only need to record a dependency on T. Unfortunately there is no simple answer to the question "what does T depend on?" because it depends on the prefix and ExtractAPI does not compute types as seen from every possible prefix, the documentation of ExtractAPI explains why.

The tests in sbt types-in-used-names-a, types-in-used-names-b, as-seen-from-a and as-seen-from-b rely on this.

[+] private val _topLevelDependencies : HashSet [ Symbol ]
[+] private val _topLevelInheritanceDependencies : HashSet [ Symbol ]
[+] private val _usedNames : HashSet [ Name ]
[+] implicit val ctx : Context
[+] private def addDependency ( sym: Symbol ) : Unit
[+] private def addInheritanceDependency ( sym: Symbol ) : Unit
[+] private def addUsedName ( name: Name ) : HashSet [ Name ]
[+] private def ignoreDependency ( sym: Symbol ) : Boolean
[+] def topLevelDependencies : Set [ Symbol ]

The set of top-level classes that the compilation unit depends on because it refers to these classes or something defined in them. This is always a superset of topLevelInheritanceDependencies by definition.

[+] def topLevelInheritanceDependencies : Set [ Symbol ]

The set of top-level classes that the compilation unit extends or that contain a non-top-level class that the compilaion unit extends.

[+] override def traverse ( tree: Tree ) ( implicit ctx: Context ) : Unit

Traverse the tree of a source file and record the dependencies which can be retrieved using topLevelDependencies, topLevelInheritanceDependencies, and usedNames

[+] def usedNames : Set [ Name ]

The names used in this class, this does not include names which are only defined and not referenced.