Commit Graph

370 Commits

Author SHA1 Message Date
Grzegorz Kossakowski 39036e7c20 Make recompilation on macro definition optional.
Introduce a new incremental compiler option that controls
incremental compiler's treatment of macro definitions and their clients.
The current strategy is that whenever a source file containing a macro
definition is touched it will cause recompilation of all direct
dependencies of that file.

That strategy has proven to be too conservative for some projects like
Scala compiler of specs2 leading to too many source files being recompiled.
We make this behavior optional by introducing a new option
`recompileOnMacroDef` in `IncOptions` class. The default value is set to
`true` which preserves the previous behavior.
2013-11-12 21:33:19 +01:00
Grzegorz Kossakowski a6f04cf53b Add specialized copy methods to IncOptions class.
Add methods that allow one to set a new value to one of the fields of
IncOptions class. These methods are meant to be an alternative to
copy method that is hard to keep binary compatible when new fields are
added to the class.

Each copying method is related to one field of the class so when new
fields are added existing methods (and their signatures) are unaffected.
2013-11-12 21:32:14 +01:00
Grzegorz Kossakowski b77b0e161e Desugar case class IncOptions in binary compatible way.
Expand case class `IncOptions` in binary compatible way so we can have
better control of methods like `unapply` when new fields are added.

Great precaution has been taken to ensure that this commit doesn't break
binary compatibility. I took a dump of javap output before and after
this change for both the class and it's companion object.
The diff is presented below:

diff -u ~/inc-options-before ~/inc-options-after
--- /Users/grek/inc-options-before	2013-11-03 14:48:45.000000000 +0100
+++ /Users/grek/inc-options-after	2013-11-03 15:53:10.000000000 +0100
@@ -9,7 +9,11 @@
     public static java.lang.String transitiveStepKey();
     public static sbt.inc.IncOptions setTransactional(sbt.inc.IncOptions, java.io.File);
     public static sbt.inc.IncOptions defaultTransactional(java.io.File);
+    public static scala.Option unapply(sbt.inc.IncOptions);
+    public static sbt.inc.IncOptions apply(int, double, boolean, boolean, int, scala.Option, scala.Function0);
     public static sbt.inc.IncOptions Default();
+    public static scala.Function1 tupled();
+    public static scala.Function1 curried();
     public int transitiveStep();
     public double recompileAllFraction();
     public boolean relationsDebug();

diff -u inc-options-module-before inc-options-module-after
--- inc-options-module-before	2013-11-03 14:48:55.000000000 +0100
+++ inc-options-module-after	2013-11-12 21:00:41.000000000 +0100
@@ -3,6 +3,9 @@
     public static final sbt.inc.IncOptions$ MODULE$;
     public static {};
     public sbt.inc.IncOptions Default();
+    public final java.lang.String toString();
+    public sbt.inc.IncOptions apply(int, double, boolean, boolean, int, scala.Option, scala.Function0);
+    public scala.Option unapply(sbt.inc.IncOptions);
     public sbt.inc.IncOptions defaultTransactional(java.io.File);
     public sbt.inc.IncOptions setTransactional(sbt.inc.IncOptions, java.io.File);
     public java.lang.String transitiveStepKey();
@@ -13,7 +16,5 @@
     public java.lang.String apiDiffContextSize();
     public sbt.inc.IncOptions fromStringMap(java.util.Map);
     public java.util.Map toStringMap(sbt.inc.IncOptions);
-    public sbt.inc.IncOptions apply(int, double, boolean, boolean, int, scala.Option, scala.Function0);
-    public scala.Option unapply(sbt.inc.IncOptions);
 }

The first diff shows that there are just more static forwarders defined
for top-level companion object and that is binary compatible change.

The second diff shows that there are just a few minor differences in
order in which `unapply`, `apply` and bridge method for `apply` are
defined. Also, there's a new `toString` declaration. All those changes are
binary compatible.

All methods that are generated for a case class are marked as deprecated
and will be removed in the future.
2013-11-12 21:31:28 +01:00
Grzegorz Kossakowski 4b43110a2c Represent api changes as values and cleanup APIChanges class.
The main motivation behind this commit is to reify information about
api changes that incremental compiler considers. We introduce a new
sealed class `APIChange` that has (at the moment) two subtypes:

  * APIChangeDueToMacroDefinition - as the name explains, this represents
    the case where incremental compiler considers an api to be changed
    just because given source file contains a macro definition
  * SourceAPIChange - this represents the case of regular api change;
    at the moment it's just a simple wrapper around value representing
    source file but in the future it will get expanded to contain more
    detailed information about API changes (e.g. collection of changed
    name hashes)

The APIChanges becomes just a collection of APIChange instances.
In particular, I removed `names` field that seems to be a dead code in
incremental compiler. The `NameChanges` class and methods that refer to
it in `SameAPI` has been deprecated.

The Incremental.scala has been adapted to changed signature of APIChanges
class. The `sameSource` method returns representation of APIChange
(if there's one) instead of just simple boolean. One notable change is
that information about APIChanges is pushed deeper into invalidation logic.
This will allow us to treat the APIChangeDueToMacroDefinition case properly
once name hashing scheme arrives.

This commit shouldn't change any behavior and is purely a refactoring.
2013-11-11 15:43:28 +01:00
Grzegorz Kossakowski 4ed8abd4fb More detailed logging of incremental compiler's invalidation logic.
The following events are logged:

  * invalidation of source file due to macro definition
  * inclusion of dependency invalidated by inheritance; we log both
    nodes of dependency edge (dependent and dependency)

The second bullet helps to understand what's going on in case of
complex inheritance hierarchies like in Scala compiler.
2013-11-11 15:27:18 +01:00
Mark Harrah 2f683ef81d Generate an error when the incremental compiler is given relative source files. Fixes #923.
Review by @gkossakowski
2013-11-08 20:43:26 -05:00
Grzegorz Kossakowski 33514ab6d7 Recover from class files and Analysis object getting out of sync.
The #958 describes a scenario where partially successful results are
produced in form of class files written to disk. However, if compilation
fails down the road we do not record any new compilation results (products)
in Analysis object. This leads to Analysis object and disk contents to get
out of sync.

One way to solve this problem is to use transactional ClassfileManager that
commits changes to class files on disk only when entire incremental
compilation session is successful. Otherwise, new class files are rolled
back to previous state.

The other way to solve this problem is to record time stamps of class files
in Analysis object. This way, incremental compiler can detect that class
files and Analysis object got out of sync and recover from that by
recompiling corresponding sources.

This commit uses latter solution which enables simpler (non-transactional)
ClassfileManager to handle scenario from #958.

Fixes #958
2013-11-08 11:29:17 +01:00
Benjy 8779409605 Allow zinc to use InternedAnalysisFormats. 2013-11-04 09:30:28 -05: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
Mark Harrah 7bcc00f637 Merge remote-tracking branch 'gkossakowski/separate-dependency-phase' into 0.13 2013-10-24 16:57:32 -04:00
Grzegorz Kossakowski 59de0f00b0 Remove long comment that explains phase ordering issues.
As pointed out by @harrah in #705, we might want to merge both API
and dependency phases so we should mention that in the comment explaining
phase ordering constraints instead.

I'd still like to keep the old comment in the history (as separate commit)
because it took me a while to figure out cryptic issues related to
continuations plugin so it's valuable to keep the explanation around in
case somebody else in the future tries to mess around with dependencies
defined by sbt.
2013-10-24 16:44:46 +02:00
Grzegorz Kossakowski e8746dc0c7 Add a bit documentation to Dependency phase.
It gives some high-level overview of what this phase does.
2013-10-24 16:44:45 +02:00
Grzegorz Kossakowski 838416360a Move dependency extraction into separate compiler phase.
This is the first step towards using new mechanism for dependency
extraction that is based on tree walking.

We need dependency extraction in separate phase because the code
walking trees should run before refchecks whereas analyzer phase runs
at the very end of phase pipeline.

This change also includes a work-around for phase ordering issue with
continuations plugin. See included comment and SI-7217 for details.
2013-10-24 16:44:45 +02: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 3d5a348e1a Deprecate AnalysisFormats. 2013-10-23 11:17:51 -04:00
Benjy 8046ad7eec Added some modifiers, per code review comments. 2013-10-23 10:58:44 -04:00
Benjy c66eefcec9 Switch to using the interned serialization format. 2013-10-23 10:41:13 -04:00
Benjy 0b033337df Interned serialization format for Analysis objects. 2013-10-22 13:02:53 -04:00
Benjy 948a9cf5cc Change how test labels are combined, per code review comments. 2013-10-18 15:34:47 -07:00
Mark Harrah e3e95f902d Merge remote-tracking branch 'benjy/analysis_test' into 0.13 2013-10-17 15:17:57 -04:00
Mark Harrah 49f2f9fe1a Merge remote-tracking branch 'benjy/internpool2' into 0.13 2013-10-17 15:17:43 -04:00
Benjy da6af7c5f7 Test for Analysis split/merge.
Requires scalacheck generators for Analysis and its subobjects. These
may be useful for other tests in the future.

Also fixes a bug in RelationTest.
2013-10-17 11:56:10 -07:00
Mark Harrah 4506c8b877 remove dead APIFormats code 2013-10-16 19:26:26 -04:00
Benjy 9c380a9f1f An intern pool implementation, and associated serialization formats. 2013-10-15 13:26:20 -07:00
Benjy 30cdb1a1bb Add correct implementations of merge/groupBy to Analysis.
Copious comments to explain the non-trivial logic.
2013-10-13 21:48:02 -07:00
Benjy b208f47275 Add a merge method to Compilations.
Also fixed a cut-n-paste mishap in Relations.
2013-10-10 19:47:56 -07:00
Benjy c3aad1cd32 Deprecate Relations.groupBy.
Also add equals/hashCode implementations for MRelations.

Also add some comments to explain that ++ and -- are naively implemented.

Also fix some tabs-vs-spaces indentation nits.
2013-10-10 13:21:08 -07:00
Mark Harrah 022307c71e Merge remote-tracking branch 'benjy/apis3' into 0.13 2013-10-10 14:24:18 -04:00
Mark Harrah 89114bcb59 Merge remote-tracking branch 'benjy/stamps2' into 0.13 2013-10-10 14:24:12 -04:00
Mark Harrah 6f2b4eaa8c Merge remote-tracking branch 'benjy/sourceinfos' into 0.13 2013-10-10 14:23:38 -04:00
Benjy 95226e8639 Add equals/hashCode to APIs, and deprecate groupBy.
equals/hashCode are useful for debugging/verifying/testing,
and the groupBy implementation is naive. It'll be replaced
by a groupBy implementation in Analysis that will handle
external/internal dep transitions correction.
2013-10-10 11:17:33 -07:00
Benjy 45a3a8ae0a Add useful methods to Stamps.
- Adds equals/hashCode to Stamp and Stamps.
- Adds a static method to merge multiple Stamps instances into one.
2013-10-10 10:52:55 -07:00
Benjy 347ef1a881 Add a merge method for SourceInfos.
Also fixes a naming consistency nit.
2013-10-10 10:37:32 -07:00
Mark Harrah 8941d4f9f5 minor fixes to Relations API documentation 2013-10-10 10:43:16 -04:00
Mark Harrah b8b6426cf9 Allow main class to be non-public. Fixes #883. 2013-09-26 09:42:30 -04:00
Jason Zaugg c4efcc4df7 Make the DelegatingReporter aware of -nowarn
The test case compiles a project without and with this
setting and checks that a warning is and isn't emitted
respectively.

It's a multi-project build; this bug didn't seem to turn
up in a single-project build.
2013-09-05 13:31:04 -04:00
Grzegorz Kossakowski beea6a9b4a Move API extraction logic to a separate class.
This way we have a little bit more clear separation
between compiler phase logic and the core logic responsible for
processing each compilation unit and extracting an api for it.

As added benefit, we have a little bit less of mutable state
(e.g. sourceFile doesn't need to be a var anymore).

The API extraction logic contains some internal caches that are
required for correctness. It wasn't very clear if they have to
be maintained during entire phase run or just during single compilation
unit processing. It looks like they have to be maintained during
single compilation unit processing and refactored code both
documents that contracts and implements it in the API phase.
2013-07-24 15:18:44 -07:00
Grzegorz Kossakowski 7d4cf7b8ab Factor out class file lookup out of Analyzer class.
Move logic related to class file lookup to separate class that
can be reused outside of Analyzer class.
2013-07-23 17:11:42 -07:00
Grzegorz Kossakowski aec466cb4d Factor out compiler interface compatibility layer.
Move collection (a class `Compat`) of compatibility hacks into separate
file. This aids understanding of the code as both Analyzer and API make
use of that class and keeping it `Analyzer.scala` file suggested that
it's used only by Analyzer.
2013-07-23 15:19:24 -07:00
Mark Harrah ab5e81fc23 Merge remote-tracking branch 'cancel-bug' into 0.13 2013-07-19 18:56:01 -04: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 4b8f0f3f94 Use IMain.bindValue to bind repl values. This does a better job of getting the type to use for a bound value. 2013-07-17 14:58:53 -04:00
Mark Harrah 4bf4a80b5e Deleted unused type parsing class 2013-07-09 14:55:30 -04:00
Mark Harrah 931c297f52 make APIDiff private[inc] 2013-06-25 08:13:06 -04:00
Grzegorz Kossakowski 0d2dc75115 Make api diff context size valuable configurable.
Add `apiDiffContextSize` option to `IncOptions` which allows one
to control the size (in lines) of a context used when printing
diffs for textual API representation.

The default value for `apiDiffContextSize` is 5 which seems to be
enough for most situations. This is verified by many debugging
sessions I performed when using api diffing functionality.
2013-06-25 00:04:45 -07:00
Grzegorz Kossakowski 025eae9103 Log API diffs using ShowAPI and java-diff-utils library.
Implement displaying API changes by using textual representation
of an API (ShowAPI) and good, old textual diff algorithm. We are
using java-diff-utils library that is distributed under Apache 2.0
license.

Notice that we have only soft dependency on java-diff-utils. It means
that we'll try to lookup java-diff-utils class through reflection
and fail gracefully if none is found on the classpath. This way
sbt is not getting any new dependency. If user needs to debug
api diffs then it's matter of starting sbt with
`-Dsbt.extraClasspath=path/to/diffutils.jar` option passed
to sbt launcher.
2013-06-25 00:04:39 -07:00
xuwei-k 3f2133729b allow java varargs main
http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.1.4
2013-06-16 15:47:47 -04:00
Mark Harrah cd2b1edf6c IncOptions class backup directory should be per-compilation, not shared.
Otherwise, one concurrent compilation will clean the directory out from under another.
2013-05-30 15:00:26 -04:00
Mark Harrah 0a7a579f5b Merge ExtendedReporter into Reporter. 2013-05-27 19:12:39 -04:00
Mark Harrah d2d406969b Make imports from MurmurHash explicit for clarity. 2013-05-27 19:12:39 -04:00