summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #5146 from som-snytt/issue/9045-msgLukas Rytz2016-05-132-36/+34
|\ | | | | SI-9045 Error on recursive ctor
| * SI-9045 Error on recursive ctorSom Snytt2016-05-042-8/+14
| | | | | | | | If the constructor invokes itself, say so.
| * SI-9045 Refactor to abuse of matchSom Snytt2016-05-041-36/+28
| | | | | | | | | | Collapse conditionals into match for legible. Yes, guards have scary eval order.
* | Merge pull request #5112 from lrytz/dropRecursiveClasspathJason Zaugg2016-05-0523-890/+316
|\ \ | | | | | | Remove legacy recursive classpath implementation
| * | Remove abstraction layer in classpath implementationLukas Rytz2016-05-0223-381/+290
| | |
| * | faster AggregateClassPath.findClassLukas Rytz2016-04-231-13/+12
| | |
| * | remove recursive classpath implementationLukas Rytz2016-04-2316-541/+59
| | |
* | | Merge pull request #5140 from lrytz/inlineDefaultMethodsJason Zaugg2016-05-055-53/+161
|\ \ \ | |_|/ |/| | SD-140 inline the correct default method
| * | SD-140 inline the correct default methodLukas Rytz2016-04-285-53/+161
| | | | | | | | | | | | | | | When inheriting multiple default methods, select the correct one to inline. Implements method resolution according to the JVM spec.
* | | Emit a warning when a constant expression evaluates to an ↵Olli Helenius2016-05-022-7/+7
| | | | | | | | | | | | ArithmeticException (#5123)
* | | SD-142 Avoid noisy log output in backend (#5134)Jason Zaugg2016-05-022-6/+9
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `withCurrentUnit` is designed to be called once per compilation unit as it side effects by logging and updating progress counters. `GenBCode` was calling it more frequently (once per `ClassDef`.) This is due to the somewhat convoluted internal architecture of that phase, which is designed to support paralellism in the future. This commit factors out the internal part of `withCompilationUnit` that modifies `currentUnit`, and calls that instead in the loop over classes. After this change: ``` % qscala -Ydebug ... [running phase jvm on <console>] // only once ```
* | More efficient code for deciding if a mixin forwarder is needed (#5116)Lukas Rytz2016-04-252-16/+25
| | | | | | | | Also adds a warning on junit test methods that compile as default methods.
* | Merge pull request #5109 from lrytz/pr5064Lukas Rytz2016-04-2316-23/+19
|\ \ | | | | | | SI-9684 Deprecate JavaConversions
| * | SI-9684 Deprecate JavaConversionsSom Snytt2016-04-2216-23/+19
| |/ | | | | | | | | | | | | | | | | Implicit conversions are now in package convert as ImplicitConversions, ImplicitConversionsToScala and ImplicitConversionsToJava. Deprecated WrapAsJava, WrapAsScala and the values in package object. Improve documentation.
* / SI-9516 Fix the behavior of Int shift Long operations. (#5117)Sébastien Doeraene2016-04-232-7/+8
|/ | | | | | | | | | | In any shift operation where the lhs is an Int (or smaller) and the rhs is a Long, the result kind must be Int, and not Long. This is important because the lhs must *not* be promoted to a Long, as that causes an opcode for long shift to be emitted. This uses an rhs modulo 64, instead of int shifts which use an rhs module 32. Instead, the rhs must be downgraded to an Int. The new behavior is consistent with the same operations in the Java programming language.
* Merge pull request #5110 from sjrd/remove-duplicate-implem-of-hashcodesLukas Rytz2016-04-224-21/+19
|\ | | | | Remove the duplicate implem of hash codes for numbers.
| * Remove the duplicate implem of hash codes for numbers.Sébastien Doeraene2016-04-214-21/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, there were two separate implementations of hash code for boxed number classes: * One in Statics, used by the codegen of case class methods. * One in ScalaRunTime + BoxesRunTime, used by everything else. This commit removes the variant implemented in ScalaRunTime + BoxesRunTime, and always uses Statics instead. We use Statics because the one from ScalaRunTime causes an unnecessary module load. The entry point ScalaRunTime.hash() is kept, as deprecated, for bootstrapping reasons.
* | Merge pull request #5096 from lrytz/traitParentsLukas Rytz2016-04-207-240/+276
|\ \ | | | | | | Ensure ClassBTypes constructed from symbol and classfile are identical
| * | Ensure that lzycompute methods are entered into the scopeLukas Rytz2016-04-201-6/+8
| | | | | | | | | | | | | | | For some reason this was not the case, leading to spurious inliner warnings (no inline info found for method O$lzycompute).
| * | Ensure ClassBTypes constructed from symbol and classfile are identicalLukas Rytz2016-04-204-21/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A super call (invokespecial) to a default method T.m is only allowed if the interface T is a direct parent of the class. Super calls are introduced for example in Mixin when generating forwarder methods: trait T { override def clone(): Object = "hi" } trait U extends T class C extends U The class C gets a forwarder that invokes T.clone(). During code generation the interface T is added as direct parent to class C. Note that T is not a (direct) parent in the frontend type of class C. This commit stores interfaces that are added to a class during code generation in the InlineInfo classfile attribute. This allows filtering the interface list when constructing a ClassBType from a classfile.
| * | Clean up code gen for method invocationsLukas Rytz2016-04-203-211/+176
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code was patched many times in the history and became a bit scattered. When emitting a virtual call, the receiver in the bytecode cannot just be the method's owner (the class in which it is declared), because that class may not be accessible at the callsite. Instead we use the type of the receiver. This was basically done to fix - aladdin bug 455 (9954eaf) - SI-1430 (0bea2ab) - basically the same bug, slightly different - SI-4283 (8707c9e) - the same for field reads In this patch we extend the fix to field writes, and clean up the code. This patch basically reverts 6eb55d4b, the fix for SI-4560, which was rather a workaround than a fix. The underlying problem was that in some cases, in a method invocation `foo.bar()`, the method `bar` was not actually a member of `foo.tpe`, causing a NoSuchMethodErrors. The issue was related to trait implementation classes. The idea of the fix was to check, at code-gen time, `foo.tpe.member("bar")`, and if that returns `NoSymbol`, use `barSym.owner`. With the new trait encoding the underlying problem seems to be fixed - all tests still pass (run/t4560.scala and run/t4560b.scala).
| * | SD-98 don't emit unnecessary mixin forwardersLukas Rytz2016-04-121-3/+35
| | | | | | | | | | | | | | | | | | | | | | | | In most cases when a class inherits a concrete method from a trait we don't need to generate a forwarder to the default method in the class. t5148 is moved to pos as it compiles without error now. the error message ("missing or invalid dependency") is still tested by t6440b.
* | | Merge pull request #5100 from lrytz/unitBoxLukas Rytz2016-04-201-4/+4
|\ \ \ | |_|/ |/| | SI-6710 / PR 5072 follow-up: fix Unit.box / Unit.unbox
| * | SI-6710 / PR 5072 follow-up: fix Unit.box / Unit.unboxLukas Rytz2016-04-201-4/+4
| |/ | | | | | | | | | | | | The backend replaces .box / .unbox methods by corresponding invocations to BoxesRunTime, but not for Unit. This commit restores the body of `Unit.box` and `Unit.unbox`.
* / Move ScalaRunTime.box to typechecker.Macros.Sébastien Doeraene2016-04-131-2/+14
|/ | | | Because it was its only call site.
* Merge pull request #5082 from lrytz/inlineImplClassCleanupLukas Rytz2016-04-0710-269/+70
|\ | | | | Cleanups related to the removal of trait impl classes
| * Fix InlineInfo attribute for nested module accessorsLukas Rytz2016-04-071-5/+7
| |
| * Remove references to trait impl classes, mostly in doc commentsLukas Rytz2016-04-074-70/+22
| |
| * Remove unused optimizer warnings related to trait impl classesLukas Rytz2016-04-041-6/+0
| |
| * Remove dead code in the optimizer related to trait impl classesLukas Rytz2016-04-047-188/+41
| |
* | Generate AnyVal source stubs from sbtStefan Zeiger2016-04-063-547/+0
| | | | | | | | | | | | | | | | | | | | | | | | The sbt command `generateSources` now generates both the AnyVal sources and the tuple/function sources (previously done by `genprod`). Source generation is part of the sbt build, the `scala.tools.cmd.gen` package is removed from `scala-compiler`. This simplifies bootstrapping. Generated sources are still in the same location and checked into git. The shell scripts `tools/codegen` and `tools/codegen-anyvals` are also removed. The ant build and the build scripts do not call these. Regenerating sources is a manual step at the moment.
* | General cleanups and less warnings during a Scala buildsoc2016-04-0428-83/+59
| |
* | SI-6710 Clarify stub methods in primitive value classesLukas Rytz2016-04-011-12/+11
|/ | | | | | | | | - Replaces the implementations of box/unbox in AnyVal companions by `???`, the methods are only stubs, and the impls did not correspond to the actual behavior. The doc comment already points to the actual implementation in BoxesRunTime. - Replaces the body of `getClass` from `null` to `???` and clarifies in a comment why the overrides exist.
* Merge pull request #5068 from retronym/topic/jdk8ism2v2.12.0-M4Lukas Rytz2016-04-011-1/+4
|\ | | | | Accomodate and exploit new library, lang features JDK 8
| * Java types and type parameters can be annotated since JSR 308Jason Zaugg2016-03-291-1/+4
| |
* | Merge pull request #5059 from lrytz/t9702Adriaan Moors2016-03-314-53/+53
|\ \ | | | | | | SI-9702 Fix backend crash with classOf[T] annotation argument
| * | SI-9702 Fix backend crash with classOf[T] annotation argumentLukas Rytz2016-03-304-53/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes various issues with classOf literals and Java annotations. - Ensure that a Type within a ConstantType (i.e., a classOf literal) is erased, so `classOf[List[Int]]` becomes `classOf[List]`. - Ensure that no non-erased types are passed to `typeToBType` in the backend. This happens for Java annotations: the annotation type and `classOf` annotation arguments are not erased, the annotationInfos of a symbol are not touched in the compiler pipeline. - If T is an alias to a value class, ensure that `classOf[T]` erases to the value class by calling `dealiasWiden` in erasure.
* | | Merge pull request #4971 from adriaanm/genbcode-delambdafyAdriaan Moors2016-03-3123-1159/+927
|\ \ \ | | | | | | | | Unify treatment of built-in functions and SAMs
| * | | Clarify how/when typedFunction unrolls eta-expansionAdriaan Moors2016-03-312-21/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Jason points out the recursion will be okay if type checking the function inside the eta-expansion provides fully determined argument types, as the result type is not relevant for this phase of typedFunction.
| * | | typedFunction undoes eta-expansion regardless of expected typeAdriaan Moors2016-03-302-45/+31
| | | | | | | | | | | | | | | | | | | | | | | | When recovering missing argument types for an eta-expanded method value, rework the expected type to a method type.
| * | | Keep Function when CBN arg thunk targets a SAMAdriaan Moors2016-03-304-29/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The body of `def delay[T](v: => T) = (v _): F0[T]` becomes `() => v` during `typedEta`, and then uncurry considers whether to strip the function wrapper since `v` is known to be a `Function0` thunk. Stripping is sound when the expected type is `Function0` for this expression, but that's no longer a given, since we could be expecting any nullary SAM. Also sweep up a bit around `typedEta`. Encapsulate the, erm, creative encoding of `m _` as `Typed(m, Function(Nil, EmptyTree))`.
| * | | Bring back AbstractFunction parentAdriaan Moors2016-03-301-1/+5
| | | | | | | | | | | | | | | | | | | | Jason points out we still need it for bytecode efficiency, due to mixin forwarders.
| * | | Keep SAM body in anonfun method in enclosing classJason Zaugg2016-03-301-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rather than in implementation of the abstract method in the expanded anonymous class. This leads to more more efficient use of the constant pool, code shapes more amenable to SAM inlining, and is compatible with the old behaviour of `-Xexperimental` in Scala 2.11, which ScalaJS now relies upon. Manual test: ``` scala> :paste -raw // Entering paste mode (ctrl-D to finish) package p1; trait T { val x = 0; def apply(): Any }; class DelambdafyInline { def t: T = (() => "") } // Exiting paste mode, now interpreting. scala> :javap -c p1.DelambdafyInline Compiled from "<pastie>" public class p1.DelambdafyInline { public p1.T t(); Code: 0: new #10 // class p1/DelambdafyInline$$anonfun$t$1 3: dup 4: aload_0 5: invokespecial #16 // Method p1/DelambdafyInline$$anonfun$t$1."<init>":(Lp1/DelambdafyInline;)V 8: areturn public final java.lang.Object p1$DelambdafyInline$$$anonfun$1(); Code: 0: ldc #22 // String 2: areturn public p1.DelambdafyInline(); Code: 0: aload_0 1: invokespecial #25 // Method java/lang/Object."<init>":()V 4: return } scala> :javap -c p1.DelambdafyInline$$anonfun$t$1 Compiled from "<pastie>" public final class p1.DelambdafyInline$$anonfun$t$1 implements p1.T,scala.Serializable { public static final long serialVersionUID; public int x(); Code: 0: aload_0 1: getfield #25 // Field x:I 4: ireturn public void p1$T$_setter_$x_$eq(int); Code: 0: aload_0 1: iload_1 2: putfield #25 // Field x:I 5: return public final java.lang.Object apply(); Code: 0: aload_0 1: getfield #34 // Field $outer:Lp1/DelambdafyInline; 4: invokevirtual #37 // Method p1/DelambdafyInline.p1$DelambdafyInline$$$anonfun$1:()Ljava/lang/Object; 7: areturn public p1.DelambdafyInline$$anonfun$t$1(p1.DelambdafyInline); Code: 0: aload_1 1: ifnonnull 6 4: aconst_null 5: athrow 6: aload_0 7: aload_1 8: putfield #34 // Field $outer:Lp1/DelambdafyInline; 11: aload_0 12: invokespecial #42 // Method java/lang/Object."<init>":()V 15: aload_0 16: invokespecial #45 // Method p1/T.$init$:()V 19: return } scala> :quit ``` Adriaan is to `git blame` for `reflection-mem-typecheck.scala`.
| * | | LMF cannot instantiate SAM of trait with non-trait superclassAdriaan Moors2016-03-292-11/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also, drop AbstractFunction for parent of anonymous subclass of function type that must have its class spun up at compile time (rather than at linkage time by LambdaMetaFactory). This revealed an old problem with typedTemplate, in which parent types may be normalized at the level of trees, while this change does not get propagated to the class's info in time for the constructor to be located when we type check the primary constructor.
| * | | LMF cannot run trait's "initializer" (constructor)Adriaan Moors2016-03-291-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Thus, rule out traits that have a constructor (which we use as a proxy for having potentially side-effecting statements), and create an anonymous subclass for them at compile time.
| * | | Better detection of types LMF cannot instantiate.Adriaan Moors2016-03-292-15/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | LambdaMetaFactory can only properly instantiate Java interfaces (with one abstract method, of course). A trait always compiles to an interface, but a subclass that can be instantiated may require mixing in further members, which LMF cannot do. (Nested traits, traits with fields,... do not qualify.) Traits that cannot be instantiated by LMF are still SAM targets, we simply created anonymous subclasses as before.
| * | | Specialization precludes use of LambdaMetaFactory for SAMAdriaan Moors2016-03-293-7/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a SAM type is specialized (i.e., a specialized type parameter receives a specialized type argument), do not use LambdaMetaFactory (expand during Uncurry instead). This is an implementation restriction -- the current specialization scheme is not amenable to using LambdaMetaFactory to spin up subclasses. Since the generic method is abstract, and the specialized ones are concrete, specialization is rendered moot because we cannot implement the specialized method with the lambda using LMF.
| * | | Target FunctionN, not scala/runtime/java8/JFunction.Adriaan Moors2016-03-284-13/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We compile FunctionN to Java 8's idea of a function now, so no need to target the artisanal JFunction and friends, except when the function is specialized, as I don't yet see how we can use LMF with the way specialization handles FunctionN: First, the working status quo -- the hand-crafted specialized versions of JFunction0. Notice how `apply$mcB$sp` is looking pretty SAMmy: ``` @FunctionalInterface public interface JFunction0$mcB$sp extends JFunction0 { @Override public byte apply$mcB$sp(); @Override default public Object apply() { return BoxesRunTime.boxToByte(this.apply$mcB$sp()); } } ``` Contrast this with our specialized standard FunctionN: ``` public interface Function0<R> { public R apply(); default public byte apply$mcB$sp() { return BoxesRunTime.unboxToByte(this.apply()); } } public interface Function0$mcB$sp extends Function0<Object> { } ``` The single abstract method in `Function0$mcB$sp` is `apply`, and the method that would let us avoid boxing, if it were abstract, is `apply$mcB$sp`... TODO (after M4): - do same for specialized functions (issues with boxing?) - remove scala/runtime/java8/JFunction* (need new STARR?)
| * | | SAM conversion can be disabled using `-Xsource:2.11`Adriaan Moors2016-03-261-0/+2
| | | | | | | | | | | | | | | | For completeness, `-Xsource:2.11 -Xexperimental` does enable it.
| * | | Refactor: simplify fallbackAfterVanillaAdapt.Adriaan Moors2016-03-262-100/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Trying to figure out if we can avoid adapting to SAM, and just type them once and for all in typedFunction. Looks like overload resolution requires SAM adaptation to happen in adapt. Cleaned up while I was in the area.