Commit Graph

100 Commits

Author SHA1 Message Date
Grzegorz Kossakowski d7eee101d0 Add a pending test for self variable bug (#2504)
Add a pending test that shows a problem with instability of representing
self variables. This test covers the bug described in #2504.

In order to test API representation of a class declared either in source
file or unpickled from a class file, ScalaCompilerForUnitTesting has been
extended to extract APIs from multiple compiler instances sharing a
classpath.
2016-03-08 20:42:11 +01:00
Eugene Yokota 2fe5eabd6e Merge branch '0.13.10' into wip/0.13.10-merge 2016-02-22 13:19:38 -05:00
Martin Duhem 6576844698 Hash of traits: include private fields, objects and super accessors 2016-02-10 18:15:44 +01:00
Martin Duhem 7d94251108 Also include private vals 2016-02-09 14:55:30 +01:00
Martin Duhem 8e17269c97 Include non-public vars in API hash of traits 2016-02-09 14:35:12 +01:00
Martin Duhem be8ba763fa Include ONLY non-public members in API hash of traits
The previous logic was wrong and included all members of traits in their
API hash, which degraded the performance of the incremental compiler.

This commit changes this logic so that only the non-public members of
traits are included into their API hash.

Fixes #2436
2016-02-04 16:32:36 +01:00
Martin Duhem 34d2aabfa9 Attempt at fixing Codacy's complaints 2016-02-04 13:24:22 +01:00
Martin Duhem b7b1f2453d Do not rely on filename of package objects
Add a new field in `Source` that indicates whether this `Source`
represents a package object. This field is used in the incrmental
compiler to perform recompilation of package objects rather than relying
on the file name being `package.scala`.

Mark pending test `source-dependencies/package-object-name` as passing.
2016-02-03 16:32:35 +01:00
Adriaan Moors 3e03e0d1b5 Clean up ShowApi implicit overload
Motivated because we want to make it more robust & configurable.
Original motivation was to diagnose a cyclic type representation,
likely due to an f-bounded existential type, as illustrated by the following:

```
class Dep {
  // The API representation for `bla`'s result type contains a cycle
  // (an existential's type variable's bound is the existential type itself)
  // This results in a stack overflow while showing the API diff.
  // Note that the actual result type in the compiler is not cyclic
  // (the f-bounded existential for Comparable is truncated)
  def bla(c: Boolean) = if (c) new Value else "bla"
}

class Value extends java.lang.Comparable[Value] { def compareTo(that: Value): Int = 1 }
```

Limit nesting (`-Dsbt.inc.apidiff.depth=N`, where N defaults to `2`),
and number of declarations shown for a class/structural type
(via `sbt.inc.apidiff.decls`, which defaults to `0` -- no limit).

Limiting nesting is crucial in keeping the size of api diffs of large programs
within a reasonable amount of RAM...

For example, compiling the Scala library, the API diff with nesting at `4`
exhausts 4G of RAM...
2016-01-06 13:56:54 -05:00
Grzegorz Kossakowski bad824c0b1 Do not compute name hashes for private members.
The NameHashing classes assumed that extracted API data structure have
private members filtered out already. That assumption was wrong and
resulted in bug #2324.

We fix the bug by simply reusing the same logic as used by SameAPI class.

Fixes #2324.
2015-12-18 14:32:43 -08:00
Grzegorz Kossakowski ae2ddab009 Add pending test for #2324 (name hashes of private members)
Add a pending test that shows a bug in calculation of name hashes.
By design, only non-private members should contribute to name hashes. The
test shows that name hashes are calcuclated for strictly private members
too.
2015-12-18 14:05:00 -08:00
Stu Hood 9fbbaab58e Add a test that we`re able to parse inner classes. 2015-11-10 14:45:04 -08:00
Stu Hood 5a3b95cd6d Add support for parsing system classes. 2015-09-18 16:37:22 -07:00
Martin Duhem 8a31702253 Add overloads to restore binary compatibility 2015-08-17 16:31:09 +02:00
Martin Duhem 40ebc82531 Include private members in API hash of traits.
During compilation, scalac generates getters and setters for the fields
of traits, regardless of their access modifiers. Therefore, when a
field of a trait is modified, all its implementors must be recompiled to
take these changes into account.

Private fields of traits were not included in the API hash of traits,
and their implementors were thus not recompiled when modified.

This commit changes the way the API hash is computed for traits only, so
that the generated hash includes the private members of traits.

Fixes sbt/sbt#2155
2015-08-17 11:59:48 +02:00
Pierre DAL-PRA 54d54b9f4f Replace procedure syntax by explicit Unit annotation 2015-08-04 10:07:38 +02:00
Pierre DAL-PRA b9171e59ad Simplify operations on collections 2015-08-01 02:25:17 +02:00
Pierre DAL-PRA 13b37cc987 Fix several warnings 2015-07-17 09:17:42 +02:00
Stu Hood 7e7aca5f55 Mismatch APIs on type changes as well 2015-07-13 21:29:14 -07:00
Stu Hood a80c3e2bb8 Review feedback 2015-07-09 22:01:05 -07:00
Stu Hood aa11e9ca87 Improve comments 2015-07-07 10:56:51 -07:00
Stu Hood 2982018e5a Parse ClassFile as a lazy val, and provide it to fieldToDef 2015-07-07 10:25:16 -07:00
Stu Hood 6846bbd3ed Encode static-final constant fields as Singletons, so that when the api changes, they change. 2015-07-01 21:37:32 -07:00
Jean-Rémi Desjardins ca736e55d3 Minor code cleanup 2014-12-03 09:56:34 -08:00
Grzegorz Kossakowski 20f50100be Use Option.apply instead of Some.apply in ClassToAPI
When dealing with Java APIs (Java reflection in case of ClassToAPI), one
should always go through Option.apply that performs null check.

This is supposed to fix NPE reported in #1617. We don't have a reproduction
so this is just an educated guess.
2014-09-24 23:05:52 +02:00
Josh Suereth abffc3e1bd Bump expected 2.11 module versions so we can compile with 2.11
Add scala 2.11 test/build verification.

* Add 2.11 build configuratoin to travis ci
* Create command which runs `safe` unit tests
* Create command to test the scala 2.11 build
* Update scalacheck to 1.11.4
* Update specs2 to 2.3.11
* Fix various 2.11/deprecation removals
  and other changes.

Fix eval test failure in scala 2.11 with XML not existing.
2014-05-14 19:08:05 -04:00
Josh Suereth 244abd3b6f Scalariforming test code 2014-05-07 11:52:23 -04:00
Eugene Yokota adb41611cf added scalariform 2014-05-01 12:50:07 -04:00
Grzegorz Kossakowski 36db1207cf Move NameHashing from incremental to api subproject.
It should have been there from the beginning because NameHashing is tied
to internals of the API subproject.

It was added to incremental subproject by mistake.
2014-04-10 20:21:42 +02:00
Martin Duhem 5a40641cc1 Classes that only inherit a macro don't have a macro
Prior to this commit, a class that inherited a macro from another
class was considered by incremental compiler as having a macro.
Now, only classes that explicitly define a macro are considered as having
a macro. This influences decision whether to invalidate (recompile)
dependencies of a file that inherits a macro upon a whitespace change.
From now on, we don't invalidate dependencies in such case which
results in much better incremental compiler experience when macros are
being involved. Check #1142 for detailed discussion.

The change to the behavior is reflected by marking the
source-dependencies/inherited-macros test as passing.
The source-dependencies/macro test covers the case of defining the macro
directly in source file. Therefore we know that the desired behavior of
invalidating dependencies of macros is preserved.

Fixes #1142
2014-04-03 18:27:17 +02:00
Mark Harrah b09cf5b5e7 Fixes #1035 by catching the format error and returning the erased type as a backup.
Review by @gkossakowski.
2013-12-13 14:04:31 -05:00
Grzegorz Kossakowski 1bbbbb38c9 Get rid of MurmurHash.finalizeHash import in HashAPI.
That import is shadowed by the local definition of `finalizeHash`
introduced to HashAPI class.
2013-12-04 12:50:29 +01:00
Grzegorz Kossakowski fa220f372a Add overloaded constructor to HashAPI for backwards compatibility.
Add a variant of constructor to `HashAPI` that is binary and source
backwards compatible with sbt 0.13.0.
2013-12-04 12:49:15 +01: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 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 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 b8b6426cf9 Allow main class to be non-public. Fixes #883. 2013-09-26 09:42:30 -04:00
Mark Harrah 4bf4a80b5e Deleted unused type parsing class 2013-07-09 14:55:30 -04: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 d2d406969b Make imports from MurmurHash explicit for clarity. 2013-05-27 19:12:39 -04:00
Mark Harrah 7088a7dd5a test cases for Java inherited dependency extraction 2013-05-02 12:01:01 -04:00
Mark Harrah a867d8e87c extract public inherited dependencies from Java class files 2013-05-01 17:54:10 -04:00
Mark Harrah f6d73128fc deprecations 2013-02-25 09:24:04 -05:00
Mark Harrah 6e30bd7842 short-circuit the macro check in the incremental compiler if the source isn't a Scala source file 2013-02-22 16:31:32 -05:00
Grzegorz Kossakowski 4c261d360f Revert "Revert "Fix sbt/sbt#676: swapped declarations and members in `ClassToAPI`.""
This reverts commit 9dd5f076ea which was a revert
itself so we are back to the state before those two reverts.

The problem that caused revert that happened in 9dd5f076ea
has been fixed in 88061dd262.
2013-02-22 07:36:55 -05:00
Grzegorz Kossakowski 129df3e812 Fix problem with initialization order in `ClassToAPI.scala`.
In `ClassToAPI` both `Private` and `Protected` vals had forward
reference to `Unqualified` so they would get `null` as a result.
Fixed that by rearranging the order of vals being declared.

This fixes a problem described in 9dd5f076ea.
2013-02-22 07:36:55 -05:00
Mark Harrah 9dd5f076ea Revert "Fix sbt/sbt#676: swapped declarations and members in `ClassToAPI`."
This reverts commit beb87f2789.  It causes java/options to fail.

CC @gkossakowski
2013-02-21 20:44:54 -05:00
Grzegorz Kossakowski 5119ea2574 Mark inherited definitions in `ShowAPI`.
Mark every inherited definition with `^inherited^` marker. This helps
understanding `ShowAPI`s output.
2013-02-20 10:52:28 -05:00
Grzegorz Kossakowski f101bcd3d0 Show some of inherited members of a structure in `ShowAPI.scala`
Showing inherited members of a structure was disabled so we would not
run into cycles. To best of my knowledge, we can run into cycles only
if inherited member is `ClassLike`. We filter out those and let
anything else to be shown.
2013-02-20 10:52:27 -05:00
Grzegorz Kossakowski beb87f2789 Fix sbt/sbt#676: swapped declarations and members in `ClassToAPI`.
As described in sbt/sbt#676, arguments to `mergeMap` and `merge` methods
were swapped causing wrong structures being created for Java compiled
class files.

This commit fixes sbt/sbt#676 and makes pending test to pass now.
2013-02-20 10:52:27 -05:00