From 7f04c14a123aa7f8d687d34fb51c9851950e90fa Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Thu, 28 Nov 2013 13:42:39 +0100 Subject: [PATCH 1/2] Rename Relations.{memberRefAndInheritanceDeps => nameHashing} The previous name of the flag was rather specific: it indicated whether the new source dependency tracking is supported by given Relations object. However, there will be more functionality added to Relations that is specific to name hashing algorithm. Therefore it makes sense to name the flag as just `nameHashing`. I decided to rename Relations implementation classes to be more consistent with the name of the flag and with the purpose they serve. The flag in AnalysisCallback (and classes implementing it) has been renamed as well. --- interface/src/main/java/xsbti/AnalysisCallback.java | 9 ++++++--- interface/src/test/scala/xsbti/TestCallback.scala | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/interface/src/main/java/xsbti/AnalysisCallback.java b/interface/src/main/java/xsbti/AnalysisCallback.java index ff239ae74..790db124a 100644 --- a/interface/src/main/java/xsbti/AnalysisCallback.java +++ b/interface/src/main/java/xsbti/AnalysisCallback.java @@ -28,8 +28,11 @@ public interface AnalysisCallback * Unreported problems are usually unreported because reporting was not enabled via a command line switch. */ public void problem(String what, Position pos, String msg, Severity severity, boolean reported); /** - * Determines whether member reference and inheritance dependencies should be extracted in given compiler - * run. + * Determines whether method calls through this interface should be interpreted as serving + * name hashing algorithm needs in given compiler run. + * + * In particular, it indicates whether member reference and inheritance dependencies should be + * extracted. * * As the signature suggests, this method's implementation is meant to be side-effect free. It's added * to AnalysisCallback because it indicates how other callback calls should be interpreted by both @@ -38,5 +41,5 @@ public interface AnalysisCallback * NOTE: This method is an implementation detail and can be removed at any point without deprecation. * Do not depend on it, please. */ - public boolean memberRefAndInheritanceDeps(); + public boolean nameHashing(); } \ No newline at end of file diff --git a/interface/src/test/scala/xsbti/TestCallback.scala b/interface/src/test/scala/xsbti/TestCallback.scala index 28bee5466..e620f6be2 100644 --- a/interface/src/test/scala/xsbti/TestCallback.scala +++ b/interface/src/test/scala/xsbti/TestCallback.scala @@ -4,7 +4,7 @@ import java.io.File import scala.collection.mutable.ArrayBuffer import xsbti.api.SourceAPI -class TestCallback(override val memberRefAndInheritanceDeps: Boolean = false) extends AnalysisCallback +class TestCallback(override val nameHashing: Boolean = false) extends AnalysisCallback { val sourceDependencies = new ArrayBuffer[(File, File, Boolean)] val binaryDependencies = new ArrayBuffer[(File, String, File, Boolean)] From 06b862db5f7d4462a13b985a67a2d0abab450f7d Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Tue, 3 Dec 2013 12:27:29 +0100 Subject: [PATCH 2/2] Add support for tracking names used in Scala source files. Tracking of used names is a component needed by the name hashing algorithm. The extraction and storage of used names is active only when `AnalysisCallback.nameHashing` flag is enabled and it's disabled by default. This change constists of two parts: 1. Modification of Relations to include a new `names` relation that allows us to track used names in Scala source files 2. Implementation of logic that extracts used names from Scala compilation units (that correspond to Scala source files) The first part is straightforward: add standard set of methods in Relations (along with their implementation) and update the logic which serializes and deserializes Relations. The second part is implemented as tree walk that collects all symbols associated with trees. For each symbol we extract a simple, decoded name and add it to a set of extracted names. Check documentation of `ExtractUsedNames` for discussion of implementation details. The `ExtractUsedNames` comes with unit tests grouped in `ExtractUsedNamesSpecification`. Check that class for details. Given the fact that we fork while running tests in `compiler-interface` subproject and tests are ran in parallel which involves allocating multiple Scala compiler instances we had to bump the default memory limit. This commit contains fixes for gkossakowski/sbt#3, gkossakowski/sbt#5 and gkossakowski/sbt#6 issues. --- interface/src/main/java/xsbti/AnalysisCallback.java | 1 + interface/src/test/scala/xsbti/TestCallback.scala | 2 ++ 2 files changed, 3 insertions(+) diff --git a/interface/src/main/java/xsbti/AnalysisCallback.java b/interface/src/main/java/xsbti/AnalysisCallback.java index 790db124a..0e083d4eb 100644 --- a/interface/src/main/java/xsbti/AnalysisCallback.java +++ b/interface/src/main/java/xsbti/AnalysisCallback.java @@ -24,6 +24,7 @@ public interface AnalysisCallback public void generatedClass(File source, File module, String name); /** Called when the public API of a source file is extracted. */ public void api(File sourceFile, xsbti.api.SourceAPI source); + public void usedName(File sourceFile, String names); /** Provides problems discovered during compilation. These may be reported (logged) or unreported. * Unreported problems are usually unreported because reporting was not enabled via a command line switch. */ public void problem(String what, Position pos, String msg, Severity severity, boolean reported); diff --git a/interface/src/test/scala/xsbti/TestCallback.scala b/interface/src/test/scala/xsbti/TestCallback.scala index e620f6be2..3ea7e32e1 100644 --- a/interface/src/test/scala/xsbti/TestCallback.scala +++ b/interface/src/test/scala/xsbti/TestCallback.scala @@ -9,12 +9,14 @@ class TestCallback(override val nameHashing: Boolean = false) extends AnalysisCa val sourceDependencies = new ArrayBuffer[(File, File, Boolean)] val binaryDependencies = new ArrayBuffer[(File, String, File, Boolean)] val products = new ArrayBuffer[(File, File, String)] + val usedNames = scala.collection.mutable.Map.empty[File, Set[String]].withDefaultValue(Set.empty) val apis: scala.collection.mutable.Map[File, SourceAPI] = scala.collection.mutable.Map.empty def sourceDependency(dependsOn: File, source: File, inherited: Boolean) { sourceDependencies += ((dependsOn, source, inherited)) } def binaryDependency(binary: File, name: String, source: File, inherited: Boolean) { binaryDependencies += ((binary, name, source, inherited)) } def generatedClass(source: File, module: File, name: String) { products += ((source, module, name)) } + def usedName(source: File, name: String) { usedNames(source) += name } def api(source: File, sourceAPI: SourceAPI): Unit = { assert(!apis.contains(source), s"The `api` method should be called once per source file: $source") apis(source) = sourceAPI