Commit Graph

75 Commits

Author SHA1 Message Date
eugene yokota be78b7fc4c Merge pull request #1759 from jedesah/topic/minor_cleanup
Minor code cleanup
2015-01-14 16:13:06 -05:00
Jean-Rémi Desjardins ca736e55d3 Minor code cleanup 2014-12-03 09:56:34 -08:00
eugene yokota 7df9802f0c Merge pull request #1714 from sbt/wip/bytecode-enhancement
Expose mechanism whereby bytecode enhancement can be run *before* saving incremental compiler hashes.
2014-12-03 08:46:52 -05:00
Josh Suereth 3c4bc23cdb First set of refactorings from review.
* Split Java analyzing compile into its own class.
* MixedAnalyzingCompiler now only does the mixing
* Start moving methods around to more-final locations
* Static analyzingCompile method now constructs a MixedAnalyzingCOmpiler and delegates to incremental compile.
2014-12-01 13:35:51 -05:00
Josh Suereth 40bf599f4a Deprecating old APIs and attempting to document behavior correctly.
* Removed as many binary incompatibilities as I could find.
* Deprecating old APIs
* Attempt to construct new nomenclature that fits the design of Incremental API.
* Add as much documentation as I was comfortable writing (from my understanding of things).
2014-12-01 13:35:51 -05:00
Martin Duhem 98c789b826 Abstract over dependency context in Compile
This commit completes the abstraction over dependency kinds in the
incremental compiler, started with #1340.
2014-11-19 10:35:07 +01:00
Martin Duhem deda8eee70 Remove trait `DependencyContext` in favor of enum
Since `DependencyContext` is needed in the compiler interface
subproject, it has to be defined in this same subproject.

`DependencyContext` is needed in this subproject because the
`AnalysisCallback` interface uses it.
2014-11-19 10:35:07 +01:00
Josh Suereth 70cdce0830 Create a new API for calling Java toolchains.
* Create a new sbt.compiler.javac package
* Create new interfaces to control running `javac` and `javadoc` whether forked or local.
* Ensure new interfaces make use of `xsbti.Reporter`.
* Create new method on `xsbti.compiler.JavaCompiler` which takes a `xsbti.Reporter`
* Create a new mechanism to parse (more accurately) Warnings + Errors, to distinguish the two.
* Ensure older xsbti.Compiler implementations still succeed via catcing NoSuchMethodError.
* Feed new toolchain through sbt.actions.Compiler API via dirty hackery until we can break things in sbt 1.0
* Added a set of unit tests for parsing errors from Javac/Javadoc
* Added a new integration test for hidden compilerReporter key, including testing threading of javac reports.

Fixes #875, Fixes #1542,  Related #1178 could be looked into/cleaned up.
2014-10-29 20:06:08 -04:00
Grzegorz Kossakowski a9a709ccc0 Add hashing of public names defined in a source file.
A hash for given name in a source file is computed by combining
hashes of all definitions with given name. When hashing a single
definition we take into account all information about it except nested
definitions. For example, if we have following definition

class Foo[T] {
  def bar(x: Int): Int = ???
}

hash sum for `Foo` will include the fact that we have a class with
a single type parameter but it won't include hash sum of `bar` method.

Computed hash sums are location-sensitive. Each definition is hashed along
with its location so we properly detect cases when definition's signature
stays the same but it's moved around in the same compilation unit.

The location is defined as sequence of selections. Each selection consists
of a name and name type. The name type is either term name or type name.
Scala specification (9.2) guarantees that each publicly visible definition
is uniquely identified by a sequence of such selectors.

For example, if we have:

object Foo {
  class Bar { def abc: Int }
}

then location of `abc` is Seq((TermName, Foo), (TypeName, Bar))

It's worth mentioning that we track name-hash pairs separately for
regular (non implicit) and implicit members. That's required for name
hashing algorithm because it does not apply its heuristic when implicit
members are being modified.

Another important characteristic is that we include all inherited members
when computing name hashes.

Here comes the detailed list of changes made in this commit:

  * HashAPI has new parameter `includeDefinitions` that allows
    shallow hashing of Structures (where we do not compute hashes
    recursively)
  * HashAPI exposes `finalizeHash` method that allow one to capture
    current hash at any time. This is useful if you want to hash a list of
    definitions and not just whole `SourceAPI`.
  * NameHashing implements actual extraction of public definitions,
    grouping them by simple name and computing hash sums for each group
    using HashAPI
  * `Source` class (defined in interface/other file) has been extended to
    include `_internalOnly_nameHashes` field. This field stores
    NameHashes data structure for given source file. The NameHashes
    stores two separate collections of name-hash pairs for regular and
    implicit members.
    The prefix `_internalOnly_` is used to indicate that this is not an
    official incremental compiler's or sbt's API and it's for use by
    incremental compiler internals only. We had to use such a prefix
    because the `datatype` code generator doesn't support emitting access
    modifiers
  * `AnalysisCallback` implementation has been modified to gather all
    name hashes and store them in the Source object
  * TestCaseGenerators has been modified to implement generation of
    NameHashes
  * The NameHashingSpecification contains a few unit tests that make sure
    that the basic functionality works properly
2013-12-04 01:34:18 +01:00
Grzegorz Kossakowski 304796bb7a 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.
2013-12-03 12:27:29 +01:00
Grzegorz Kossakowski 2a3a3d0d7a 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.
2013-11-28 13:42:39 +01:00
Grzegorz Kossakowski aac19fd02b Extract source code dependencies by tree walking.
Previously incremental compiler was extracting source code
dependencies by inspecting `CompilationUnit.depends` set. This set is
constructed by Scala compiler and it contains all symbols that given
compilation unit refers or even saw (in case of implicit search).
There are a few problems with this approach:

  * The contract for `CompilationUnit.depend` is not clearly defined
    in Scala compiler and there are no tests around it. Read: it's
    not an official, maintained API.
  * Improvements to incremental compiler require more context
    information about given dependency. For example, we want to
    distinguish between dependency on a class when you just select
    members from it or inherit from it. The other example is that
    we might want to know dependencies of a given class instead of
    the whole compilation unit to make the invalidation logic more
    precise.

That led to the idea of pushing dependency extracting logic to
incremental compiler side so it can evolve indepedently from Scala
compiler releases and can be refined as needed. We extract
dependencies of a compilation unit by walking a type-checked tree
and gathering symbols attached to them.

Specifically, the tree walk is implemented as a separate phase that
runs after pickler and extracts symbols from following tree nodes:

  * `Import` so we can track dependencies on unused imports
  * `Select` which is used for selecting all terms
  * `Ident` used for referring to local terms, package-local terms
            and top-level packages
  * `TypeTree` which is used for referring to all types

Note that we do not extract just a single symbol assigned to `TypeTree`
node because it might represent a complex type that mentions
several symbols. We collect all those symbols by traversing the type
with CollectTypeTraverser. The implementation of the traverser is inspired
by `CollectTypeCollector` from Scala 2.10. The
`source-dependencies/typeref-only` test covers a scenario where the
dependency is introduced through a TypeRef only.
2013-11-26 18:39:23 +01:00
Grzegorz Kossakowski a37d8d4770 Fix unstable existential type names bug.
Fix the problem with unstable names synthesized for existential
types (declared with underscore syntax) by renaming type variables
to a scheme that is guaranteed to be stable no matter where given
the existential type appears.

The sheme we use are De Bruijn-like indices that capture both position
of type variable declarion within single existential type and nesting
level of nested existential type. This way we properly support nested
existential types by avoiding name clashes.

In general, we can perform renamings like that because type variables
declared in existential types are scoped to those types so the renaming
operation is local.

There's a specs2 unit test covering instability of existential types.
The test is included in compiler-interface project and the build
definition has been modified to enable building and executing tests
in compiler-interface project. Some dependencies has been modified:

  * compiler-interface project depends on api project for testing
    (test makes us of SameAPI)
  * dependency on junit has been introduced because it's needed
    for `@RunWith` annotation which declares that specs2 unit
    test should be ran with JUnitRunner

SameAPI has been modified to expose a method that allows us to
compare two definitions.

This commit also adds `ScalaCompilerForUnitTesting` class that allows
to compile a piece of Scala code and inspect information recorded
callbacks defined in  `AnalysisCallback` interface. That class uses
existing ConsoleLogger for logging. I considered doing the same for
ConsoleReporter. There's LoggingReporter defined which would fit our
usecase but it's defined in compile subproject that compiler-interface
doesn't depend on so we roll our own.

ScalaCompilerForUnit testing uses TestCallback from compiler-interface
subproject for recording information passed to callbacks. In order
to be able to access TestCallback from compiler-interface
subproject I had to tweak dependencies between interface and
compiler-interface so test classes from the former are visible in the
latter. I also modified the TestCallback itself to accumulate apis in
a HashMap instead of a buffer of tuples for easier lookup.

An integration test has been added which tests scenario
mentioned in #823.

This commit fixes #823.
2013-10-29 16:39:50 +01:00
Grzegorz Kossakowski 18a87e61c9 Move TestCallback.scala to a directory matching its package name. 2013-10-29 16:39:50 +01:00
Grzegorz Kossakowski 580c84974a Remove dead source file `F0.scala` from interface subproject.
It doesn't seem to be used anywhere.
2013-10-29 16:39:50 +01:00
Grzegorz Kossakowski fea18a4fbe Remove AnalysisCallback.{beginSource, endSource} methods.
As pointed out by @harrah in #705, both beginSource and endSource are
not used in sbt internally for anything meaningful.

We've discussed an option of deprecating those methods but since they
are not doing anything meaningful Mark prefers to have compile-time
error in case somebody implements or calls those methods. I agree with
that hence removal.
2013-10-24 16:44:45 +02:00
Benjy 0b2de2d9b4 equals/hashCode on Modifiers. 2013-10-10 20:43:13 -07:00
Grzegorz Kossakowski d77930394f Handle compilation cancellation properly.
Incremental compiler didn't have any explicit logic to handle
cancelled compilation so it would go into inconsistent state.

Specifically, what would happen is that it would treat cancelled
compilation as a compilation that finished normally and try to
produce a new Analysis object out of partial information collected
in AnalysisCallback. The most obvious outcome would be that the
new Analysis would contain latest hashes for source files. The
next time incremental compiler was asked to recompile the same files
that it didn't recompile due to cancelled compilation it would think
they were already successfully compiled and would do nothing.

We fix that problem by following the same logic that handles compilation
errors, cleans up partial results (produced class files) and makes sure
that no Analysis is created out of broken state.

We do that by introducing a new exception `CompileCancelled`
and throwing it at the same spot as an exception signalizing compilation
errors is being thrown. We also modify `IncrementalCompile` to
catch that exception and gracefully return as there was no compilation
invoked.

NOTE: In case there were compilation errors reported _before_
compilation cancellations was requested we'll still report them
using an old mechanism so partial errors are not lost in case
of cancelled compilation.
2013-07-19 14:39:26 -07:00
Mark Harrah 0a7a579f5b Merge ExtendedReporter into Reporter. 2013-05-27 19:12:39 -04:00
Mark Harrah 429131bdd8 fix compilation error in TestCallback 2013-04-27 16:28:45 -04:00
Mark Harrah 4dc75343ae Record and persist public inheritance dependencies.
Includes placeholders for adding public inherited dependencies for Java classes.
2013-04-26 22:35:27 -04:00
Mark Harrah f2d29d8678 Export approximate command lines executed for 'doc', 'compile', and 'console' 2013-02-28 17:59:38 -05:00
Mark Harrah 5b5577a187 Replace Scala jars in UpdateReport with ScalaProvider jars in more situations. Fixes #661.
Specifically, when the Scala version for sbt is the same as that for the project being built,
the jars in UpdateReport should be the same as those in ScalaProvider.  This is because the
loader will come from the ScalaProvider, which uses jars in the boot directory instead of the
cache.  The first part of the fix for #661 checks that loaded classes come from the classpath
and so they need to line up.
2013-02-21 20:44:26 -05:00
Grzegorz Kossakowski 70036812ab Introduce incremental compiler options.
Introduce a way to configure incremental compiler itself instead
of underlying Java/Scala compiler.

Specific list of changes in this commit:
  * Add a method to `xsbti.compile.Setup` that returns incremental
    compiler options as a `java.util.Map<String, String>`. We considered
    statis interface instead of a `Map` but based on mailing
    list feedback we decided that it's not the best way to go because
    static interface is hard to evolve it by adding new options.
  * Since passing `java.util.Map<String, String>` not very convenient
    we convert it immediately to `sbt.inc.IncOptions`
  * Add options argument to various methods/classes that implement
    incremental compilation so in the end options reach
    `sbt.inc.IncOptions` object
  * Add `incOptions` task that allows users to configure incremental
    compiler options in their build files. Default implementation of
    that tasks returns just `IncOptions.DEFAULT`
  * Both system property `xsbt.inc.debug` and `IncOptions.relationsDebug`
    trigger debugging of relations now. In the near future, we should
    deprecate use of `xsbt.inc.debug`.
2013-02-19 12:23:07 -05:00
Grzegorz Kossakowski d6f4c5ae4f Strip down trailing whitespace.
I have Eclipse configured to do that automatically when saving file.
I decided to finally commit those changes to files I touch a lot.
2013-02-19 12:18:26 -05:00
Paolo G. Giarrusso 1d7e68be1b Silence boring Eclipse warnings: unused imports 2013-01-22 09:05:15 -05:00
Mark Harrah 18a03f0e25 API extraction: handle any type that is annotated, not just the spec'd simple type. Fixes #559. 2012-10-05 09:06:35 -04:00
Eugene Vigdorchik 1b814ae8b1 Extend reporter to be used by the IDE. 2012-07-24 15:35:06 -04:00
Eugene Vigdorchik 76943e82ed Add xsbti.Reporter to required inputs instead of maxErrors. 2012-07-13 14:33:26 -04:00
Eugene Vigdorchik b5a29987e6 Changes required to use sbt as-is from Scala-IDE. 2012-07-13 14:33:26 -04:00
Mark Harrah f53d20a7a3 disable resident-compiler related code paths when it isn't being used. fixes #486.
The underlying issue with the resident compiler needs fixing, however.
2012-06-16 23:40:52 -04:00
Mark Harrah 7bed381bec cleanup compilation tests 2012-05-12 23:12:29 -04:00
Mark Harrah 864580aae1 approximate type parameters and references by name
not as accurate, but simpler.
2012-05-12 23:12:29 -04:00
Mark Harrah 99a04466f1 move to revised warning interface in the compiler 2012-05-06 14:15:03 -04:00
Mark Harrah 6769c94208 basis for a resident compiler
unstable, but can be tested with -Dsbt.resident.limit=n
 n is the maximum Globals kept around
2012-04-28 18:58:52 -04:00
Mark Harrah 2bd103f1fa implement embedded interface 2012-04-18 16:01:45 -04:00
Mark Harrah d837f869bd using some of the embedding interfaces 2012-04-18 11:02:52 -04:00
Mark Harrah 4a53ace752 API for embedding incremental compilation 2012-04-18 08:19:33 -04:00
Mark Harrah 8594e4443d reorganize compilation modules 2012-04-18 08:08:25 -04:00
Mark Harrah 1cbb7ce93c print-warnings task for Scala 2.10+ to avoid needing to rerun 'compile' to see deprecation/unchecked warnings 2012-03-17 19:31:55 -04:00
Jason Zaugg 067917a0fb Macro def aware recompilation.
- Read macro modifier from method definition.
 - Always recompile downstream files after a file containing macro defs is recompiled.
 - Source is extended with a hasMacro attribute. Mark suggests that this might be better
   tracked in Relations, but I'm not sure how to make that change.
2012-03-04 17:35:51 +01:00
Mark Harrah 03ba47c58c API for embedding incremental compilation 2012-01-09 08:00:35 -05:00
Mark Harrah 82ad44a701 preserve API information needed for detecting annotations on defs. fixes #232 2011-10-19 22:23:47 -04:00
Mark Harrah e4848efcc8 store hashes of API instead of full API. fixes #21 2011-10-05 18:09:27 -04:00
Mark Harrah 0b3ec05a81 support incremental recompilation when using exportJars. fixes #108 2011-07-18 17:14:22 -04:00
Mark Harrah c0a21c1524 implement shortcut for API equality checking, fixes #18 2011-06-01 02:19:46 -04:00
Mark Harrah 24dfb69400 an annotation can reference a non-simple type, fixes #24 2011-05-23 18:40:03 -04:00
Mark Harrah ba8f43a23e starting to convert integration tests 2011-02-22 22:36:48 -05:00
Mark Harrah cc06667f3e handle constant types 2011-02-14 18:59:54 -05:00
Mark Harrah 403fa42fa2 Type cache in API extraction for smaller cache size and faster I/O
manually implement Modifiers, use byte-size bit field
2010-10-30 17:46:56 -04:00