Skip to content
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

Class dependency tracking #716

Open
eed3si9n opened this issue Jul 21, 2020 · 0 comments
Open

Class dependency tracking #716

eed3si9n opened this issue Jul 21, 2020 · 0 comments
Milestone

Comments

@eed3si9n
Copy link
Member

In Zinc meeting with Scala Center 2020-07-21 (@lrytz, @dwijnand, @sjrd, @eed3si9n), an idea came up today about informal hook for Class dependency tracking.

In addition (or instead) of Zinc injecting xsbt-dependency phase and try to figure out all instances of class dependencies, the idea is for the compiler to keep track of dependency information during the compilation as it happens, and Zinc can collect it afterwards. This is because we think it would be easier / more accurate if we keep track of dependency information as it happens, and for certain lookups it can only be observed in a certain phase.

Here are some of the example that may benefit from this approach..

SAM type inference

sbt/zinc#830

Wildcard import

This is an example @sjrd mentioned. Suppose x is coming from A.x:

object Test {
  import A._
  {
    import B._
    println(x)
  }
}

The compiler still tried to look up x from B._, which may be tracked. The idea is that if B later adds x it should trigger recompilation. (Is current name hashing able to catch this?)

Dependency

Here is the current implementation of https://github.com/sbt/zinc/blob/v1.4.0-M6/internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala

3 callback called into Zinc are:

callback.dependencyPhaseCompleted()
callback.binaryDependency(file, binaryClassName, fromClassName, sourceFile, context)
callback.classDependency(onClassName, fromClassName, context)

where context is defined by

public enum DependencyContext {
    /**
     * Represents a direct dependency between two symbols :
     * object Foo
     * object Bar { def foo = Foo }
     */
    DependencyByMemberRef,
    /**
     * Represents an inheritance dependency between two symbols :
     * class A
     * class B extends A
     */
    DependencyByInheritance,
    /**
     * Represents an inheritance dependency between a local class
     * and a non local class:
     * // A.scala
     * class A
     * // B.scala
     * class B {
     *   def foo = {
     *     class Local extends A
     *   }
     * }
     */
     LocalDependencyByInheritance;       
 }
@dwijnand dwijnand added this to the Backlog milestone Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants