summaryrefslogtreecommitdiff
path: root/src/compiler
Commit message (Collapse)AuthorAgeFilesLines
* Javadoc: consider DocDefs when checking for constructorsJakob Odersky2016-08-011-6/+15
|
* Javadoc: ignore comments when deciding where to put interface methodsJakob Odersky2016-08-011-3/+10
|
* Javadoc: fix assertion errors for java fieldsJakob Odersky2016-07-261-2/+2
|
* Merge pull request #5296 from retronym/ticket/SD-186Lukas Rytz2016-07-221-1/+1
|\ | | | | SD-186 Fix positions in trait method bytecode
| * SD-186 Fix positions in trait method bytecodeJason Zaugg2016-07-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Concrete, non private methods in traits are translated into a static method with an explicit `$this` parameter. After this translation, the references to `$this` (subistuted for `this` in user written code) where being positioned at the position of the method, which makes debugging unpleasant. This commit leaves the `Ident($this)` trees unpositioned. This is analagous to what we do in the body of extension methods, which is the other user of `ThisSubstitutor`. It would be more correct to copy the position of each `This` tree over to the substituted tree. That would let us set a breakpoint on a line that _only_ contained `this`. But in 99% of cases users won't be able to spot the difference, so I've opted for the tried and tested approach here.
* | Merge pull request #5278 from retronym/ticket/SD-120Lukas Rytz2016-07-223-30/+32
|\ \ | | | | | | SD-120 Non FunctionN lambdas should not be universally serializable
| * | SD-120 Non FunctionN lambdas should not be universally serializableJason Zaugg2016-07-223-30/+32
| | | | | | | | | | | | | | | | | | | | | | | | Instead, we follow the example set by javac, and predicate serializability of bot anon-class and invokedynamic-based lambdas on whether or not the SAM type extends java.io.Serializable. Fixes https://github.com/scala/scala-dev/issues/120
* | | SD-121 Remove now-unneeded J{Function,Proc}N functional interfacesJason Zaugg2016-07-221-2/+6
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Non specialized functions can directly use `scala.FunctionN` as the functional interface, now that mixin generates default methods in the new trait encoding. Unfortunately we can't do this for specialized functions as things stand: specialization leaves the wrong method abstract. In principle, we could/should amend the specialization transform to fix this. But my earlier attempts at this weren't sucessful, so for now we have to stick with the fallback plan of keeping some hand rolled functional interfaces around. This commit reduces the surface area of `scala.runtime.java8` to the minimal requiremnt: one functional interface for each specialized variant of `Function{0,1,2}`.
* | Upgrade asm to 5.1Lukas Rytz2016-07-204-26/+35
| | | | | | | | | | The constructor of scala.tools.asm.Handle now takes an additional boolean parameter to denote whether the owner is an interface.
* | Merge pull request #5257 from szeiger/wip/final-tuplesLukas Rytz2016-07-201-3/+1
|\ \ | | | | | | SI-7301 Make tuple classes final
| * | SI-7301 Make tuple classes finalStefan Zeiger2016-07-071-3/+1
| | | | | | | | | | | | | | | This includes undoing the special case for `-Xfuture` introduced in https://github.com/scala/scala/pull/2299 and updating tests to take the new errors into account.
* | | Merge pull request #5246 from jodersky/javadocAdriaan Moors2016-07-185-25/+41
|\ \ \ | | | | | | | | SI-4826 Retain javadoc comments in scaladoc [ci: last-only]
| * | | Retain javadoc comments in scaladocJakob Odersky2016-07-155-25/+41
| | |/ | |/| | | | | | | | | | * Hook into java parser to generate doc comments * Generate empty trees for java implementation bodies
* | | Merge pull request #5273 from retronym/ticket/9855Adriaan Moors2016-07-181-14/+3
|\ \ \ | | | | | | | | SI-9855 Fix regression in extractor pattern translation
| * | | SI-9855 Fix regression in extractor pattern translationJason Zaugg2016-07-141-14/+3
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In faa5ae6, I changed the pattern matchers code generator to use stable references (`Ident`-s with the singleton type, rather than the widened type) to the synthetic vals used to store intermediate results ("binders"). In the case where the scrutinee matched the unapply parameter type of some extractor pattern, but the pattern subsequently failed, this led to an regression. It turns out that this was due to the way that the type of the binder was mutated to upcast to the exact type of a subsequent pattern in `ensureConformsTo`: https://github.com/scala/scala/blob/953559988/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala#L165-L174 This was added in 32c57329a as a workaround for the problem caused in t6664.scala, when the binder type was `KList with KCons`, and the code generator wasn't able to find the case field accessors for `KCons` in the decls. The change to use stable references meant that this mutation was now observed in another part of the tree, as opposed to the 2.11.8 situation, where we had used the original, sharper type of the binder eagerly to assign to the `Ident` that referred to it. This led to a tree: Assign(Ident(x3), Ident(x1).setType(x1.tpe) Now that we instead refer generate: Assign(Ident(x3), Ident(x1).setType(stableTypeFor(x1)) and we don't typecheck this until after the mutation of `x1.symbol.info`, we can get a type error. This commit removes this mutation of the binder type altogether, and instead uses `aligner.wholeType`, which is based on the result type of the `Apply(TypeTree(MethodType(params, resultType))` that encodes a typechecked constructor pattern. In `t6624.scala`, this is `KCons`, the case class that has the extractors as its decls.
* | | Merge pull request #5269 from lrytz/t9849Lukas Rytz2016-07-131-1/+1
|\ \ \ | | | | | | | | SI-9849 set privateWithin on default getters
| * | | SI-9849 set privateWithin on default gettersLukas Rytz2016-07-121-1/+1
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A default getter get the same access flag (private / protected) as the method whose default it implements. However, we forgot to set the privateWithin flag, which defines the scope in a qualified private / protected modifier. For a private[p], the default getter was therefore public, which is less restricted (a private[p] method has privateWithin set to p, but the private flag is not set). For a protected[p], the default getter was protected, which is more restricted.
* | | Merge pull request #5135 from soc/topic/biased-eitherStefan Zeiger2016-07-131-11/+2
|\ \ \ | |_|/ |/| | Right-bias Either
| * | Right-bias EitherSimon Ochsenreither2016-05-271-11/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Add operations like map, flatMap which assume right-bias - Deprecate {Left,Right}Projection - Deprecate left and right in favor of swap - Add contains, toOption, toTry, toSeq and filterOrElse - toSeq returns collection.immutable.Seq instead of collection.Seq - Don't add get There are no incompatible changes. The only possibility of breakage that exists is when people have added extension methods named map, flatMap etc. to Either in the past doing something different than the methods added to Either now. One detail that moved the scales in favor of deprecating LeftProjection and RightProjection was the desire to have toSeq return scala.collection.immutable.Seq instead of scala.collection.Seq like LeftProjection and RightProjection do. Therefore keeping LeftProjection and RightProjection would introduce inconsistency. filter is called filterOrElse because filtering in a for-comprehension doesn't work if the method needs an explicit argument. contains was added as safer alternative to if (either.isRight && either.right.get == $something) ... While adding filter with an implicit zero value is possible, it's dangerous as it would require that developers add a "naked" implicit value of type A to their scope and it would close the door to a future in which the Scala standard library ships with Monoid and filter could exist with an implicit Monoid parameter.
* | | SI-9515 closure elimination also for non-Scala-Function SAM typesLukas Rytz2016-07-044-38/+5
| |/ |/| | | | | | | | | | | | | | | | | Also logged in as SD-162 The optimizer had conservative checks in place to perform closure elimination only for Scala Function types. We can eliminate IndyLambda instructions for any functional interface. LambdaMetaFactory only constructs lambda objects for interface types, which don't have any side-effects on construction - they don't have a constructor.
* | Emit trait method bodies in staticsJason Zaugg2016-06-2815-162/+235
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | And use this as the target of the default methods or statically resolved super or $init calls. The call-site change is predicated on `-Yuse-trait-statics` as a stepping stone for experimentation / bootstrapping. I have performed this transformation in the backend, rather than trying to reflect this in the view from Scala symbols + ASTs. We also need to add an restriction related to invokespecial to Java parents: to support a super call to one of these to implement a super accessor, the interface must be listed as a direct parent of the class. The static method names has a trailing $ added to avoid duplicate name and signature errors in classfiles.
* | Revert pruning of redundant Java parentsJason Zaugg2016-06-281-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This partially reverts the fix for SI-5278 made in 7a99c03da. The original motivation for this case to avoid bytecode that stretched platform limitations in Android. For super calls to Scala defined trait methods, we won't use `invokespecial`, but rather use `invokestatic` to a static trait implementation method. As such, we can continue to prune redundant Scala interfaces. It might be worth considering removing the pruning of redundant parents altoghether, though: - We no longer include `ScalaObject` as a parent of every class, which was mentioned as a problem in SI-5728. - Scala 2.12 has left Android behind for the time being due to use of Java 8 facilities. - javac doesn't do this, so why should we?
* | Don't minimize parents of java defined syms.Jason Zaugg2016-06-281-1/+2
| |
* | Better diagnostic for optimizer crashesJason Zaugg2016-06-281-3/+9
| |
* | Remove nonsensical body for trait getterJason Zaugg2016-06-281-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This corrects an error in the change to the trait encoding in #5003: getters in traits should have empty bodies and be emitted as abstract. ``` % ~/scala/2.12.0-M4/bin/scalac sandbox/test.scala && javap -c T Compiled from "test.scala" public interface T { public abstract void T$_setter_$x_$eq(int); public int x(); Code: 0: aload_0 1: invokeinterface #15, 1 // InterfaceMethod x:()I 6: ireturn public int y(); Code: 0: aload_0 1: invokeinterface #20, 1 // InterfaceMethod y:()I 6: ireturn public void y_$eq(int); Code: 0: aload_0 1: iload_1 2: invokeinterface #24, 2 // InterfaceMethod y_$eq:(I)V 7: return public void $init$(); Code: 0: aload_0 1: bipush 42 3: invokeinterface #29, 2 // InterfaceMethod T$_setter_$x_$eq:(I)V 8: aload_0 9: bipush 24 11: invokeinterface #24, 2 // InterfaceMethod y_$eq:(I)V 16: return } % qscalac sandbox/test.scala && javap -c T Compiled from "test.scala" public interface T { public abstract void T$_setter_$x_$eq(int); public abstract int x(); public abstract int y(); public abstract void y_$eq(int); public static void $init$(T); Code: 0: aload_0 1: bipush 42 3: invokeinterface #21, 2 // InterfaceMethod T$_setter_$x_$eq:(I)V 8: aload_0 9: bipush 24 11: invokeinterface #23, 2 // InterfaceMethod y_$eq:(I)V 16: return public void $init$(); Code: 0: aload_0 1: invokestatic #27 // Method $init$:(LT;)V 4: return } ```
* | Merge commit '91b6944' into merge-2.11-to-2.12-june-19Lukas Rytz2016-06-191-1/+1
|\ \
| * | SI-9245 Fresher name in Try and testSom Snytt2016-06-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Fresh name for catcher gets a dollar. "Here, have a dollar." Test due to retronym demonstrates possible conflict. Over the lifetime of the universe, surely at least one code monkey would type in that identifier to catch a banana.
* | | Keep line numbers when inlining from the same compilation unitLukas Rytz2016-06-061-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | So far, line numbers were kept only when inlining from the same class. We can also keep them when inlining from a different class defined in the same compilation unit. Longer-term we should support JSR-45, see SI-7518 and scala-dev#3.
* | | SI-9256 check companions in same compilation unit only if same runLukas Rytz2016-06-061-0/+1
| | |
* | | Store source file paths of classes being compiled in the bytecode repoLukas Rytz2016-06-065-70/+65
| | | | | | | | | | | | | | | | | | | | | For classes being compiled (vs. being loaded from classfiles), keep the source file path in the bytecode repo. This will allow to keep line numbers when inlining from one class into another in case the two are defined in the same compilation unit.
* | | Avoid separate traversal in inliner to remove line number nodesLukas Rytz2016-06-062-9/+7
| | |
* | | Merge pull request #5099 from retronym/ticket/9390Jason Zaugg2016-06-063-11/+39
|\ \ \ | | | | | | | | SI-9390 Emit local defs that don't capture this as static
| * | | SI-9390 Avoid needless outer capture with local classesJason Zaugg2016-06-033-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An existing optimization in `Constructors` elides the outer field in member and local classes, if the class doesn't use the outer reference. (Member classes also need to be final, which is a secret handshake to say we're also happy to weaken prefix matching in the pattern matcher.) That optimization leaves the constructor signature as is: the constructor still accepts the outer instance, but does not store it. For member classes, this means that we can separately compile code that calls the constructor. Local classes need not be hampered by this constraint, we could remove the outer instance from the constructor call too. Why would we want to do this? Let's look at the case before and after this commit. Before: ``` class C extends Object { def foo(): Function1 = $anonfun(); final <static> <artifact> def $anonfun$foo$1($this: C, x: Object): Object = new <$anon: Object>($this); def <init>(): C = { C.super.<init>(); () } }; final class anon$1 extends Object { def <init>($outer: C): <$anon: Object> = { anon$1.super.<init>(); () } } ``` After: ``` class C extends Object { def foo(): Function1 = $anonfun(); final <static> <artifact> def $anonfun$foo$1(x: Object): Object = new <$anon: Object>(null); def <init>(): C = { C.super.<init>(); () } }; final class anon$1 extends Object { def <init>($outer: C): <$anon: Object> = { anon$1.super.<init>(); () } } ``` However, the status quo means that a lambda that This in turn makes lambdas that refer to such classes serializable even when the outer class is not itself serialiable. I have not attempted to extend this to calls to secondary constructors.
| * | | SI-9390 Emit local defs that don't capture this as staticJason Zaugg2016-06-011-8/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This avoids unnecessary memory retention, and allows lambdas that call the local methods to be serializable, regardless of whether or not the enclosing class is serializable. The second point is especially pressing, given that the enclosing class for local methods defined in a used to be the (serializable) anonymous function class, but as of Scala 2.12 will be the enclosing class of the lambda. This change is similar in spirit to SI-9408 / 93bee55e.
* | | | Merge pull request #5157 from retronym/topic/lambda-staticsJason Zaugg2016-06-069-23/+105
|\ \ \ \ | | | | | | | | | | Lambda impl methods static and more stably named
| * | | | Drop local suffix in lambda impl method nameJason Zaugg2016-06-021-1/+1
| |/ / /
| * | | Treat self parameter as non-null in the optimizerLukas Rytz2016-06-014-8/+14
| | | |
| * | | Lambda impl methods static and more stably namedJason Zaugg2016-06-016-16/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The body of lambdas is compiled into a synthetic method in the enclosing class. Previously, this method was a public virtual method named `fully$qualified$Class$$anonfun$n`. For lambdas that didn't capture a `this` reference, a static method was used. This commit changes two aspects. Firstly, all lambda impl methods are now emitted static. An extra parameter is added to those that require a this reference. This is an improvement as it: - allows, shorter, more readable names for the lambda impl method - avoids pollution of the vtable of the class. Note that javac uses private instance methods, rather than public static methods. If we followed its lead, we would be unable to support important use cases in our inliner Secondly, the name of the enclosing method has been included in the name of the lambda impl method to improve debuggability and to improve serialization compatibility. The serialization improvement comes from the way that fresh names for the impl methods are allocated: adding or removing lambdas in methods not named "foo" won't change the numbering of the `anonfun$foo$n` impl methods from methods named "foo". This is in line with user expectations about anonymous class and lambda serialization stability. Brian Goetz has described this tricky area well in: http://cr.openjdk.java.net/~briangoetz/eg-attachments/lambda-serialization.html This commit doesn't go as far a Javac, we don't use the hash of the lambda type info, param names, etc to map to a lambda impl method name. As such, we are more prone to the type-1 and -2 failures described there. However, our Scala 2.11.8 has similar characteristics, so we aren't going backwards. Special case in the naming: Use "new" rather than "<init>" for constructor enclosed lambdas, as javac does. I have also changed the way that "delambdafy target" methods are identifed. Rather than relying on the naming convention, I have switched to using a symbol attachment. The assumption is that we only need to identify them from within the same compilation unit. This means we can distinguish impl metbods for expanded functions (ones called from an `apply` method of an ahead-of-time expanded anonfun class), from those that truly end up as targets for lambda metafactory. Only the latter are translated to static methods in this patch.
* | | | Merge pull request #5209 from adriaanm/trait-no-native-methLukas Rytz2016-06-031-10/+18
|\ \ \ \ | | | | | | | | | | Prohibit @native method in trait
| * | | | Prohibit @native method in traitAdriaan Moors2016-06-021-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On the JVM, a @native interface method results in a VerifyError. Other platforms could decide to be more permissive, but it seems like allowing them in classes is enough.
* | | | | Merge pull request #5147 from som-snytt/issue/8667-too-many-argsAdriaan Moors2016-06-022-5/+43
|\ \ \ \ \ | |/ / / / |/| | | | SI-8667 Improve too-many-args message
| * | | | SI-8667 Caret at bad argSom Snytt2016-05-132-9/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Pick the first excessive positional arg for the caret. Note that erroring on named args doesn't do the obvious thing in this regard. If `k` was removed from the signature, then `f(k=1, i=2, j=3)` doesn't tell us much about the wrong arg, because naming takes the `k=1` as an assignment, `i` as duplicate naming. No arg is deemed extra, though further inspection of the conflicting args might get there. Since assignment syntax in parens is more|less deprecated (?), no more effort is done here.
| * | | | SI-8667 Improve too-many-args messageSom Snytt2016-05-132-5/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use removeNames to help diagnose the application. Supplement the error message with how many extra args and any other residual assignments that the user might have thought was a properly named arg. The error message is gradual: succinct for short arg lists, more verbose for longer applications. Very long arg lists are probably generated, so that message is the least colloquial.
* | | | | Merge pull request #5205 from adriaanm/misc-optAdriaan Moors2016-06-024-44/+50
|\ \ \ \ \ | | | | | | | | | | | | Small optimizations around use of Scopes.
| * | | | | Compute constrParamAccessors once. It's expensiveAdriaan Moors2016-06-011-22/+26
| | | | | |
| * | | | | opt: fuse some operations on `Scope`sAdriaan Moors2016-06-014-22/+24
| | |/ / / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | `Scope`'s `filter` is implemented using `toList`, so may as well start with `toList`ourselves. Also fused some `filter`/`foreach` combos.
* | | | | Merge pull request #5207 from lrytz/nan-compareAdriaan Moors2016-06-023-17/+14
|\ \ \ \ \ | | | | | | | | | | | | Fix comparisons involving NaN
| * | | | | Fix comparisons involving NaNLukas Rytz2016-06-023-17/+14
| |/ / / / | | | | | | | | | | | | | | | | | | | | Floating point comparisons involving NaN should always return false, except for !=. Fixes a regression introduced by #4963.
* | | | | Merge commit '90215ce' into merge-2.11-to-2.12-june-1Lukas Rytz2016-06-012-1/+8
|\ \ \ \ \ | | |_|/ / | |/| | |
| * | | | Merge pull request #4998 from som-snytt/issue/7898-iLukas Rytz2016-06-012-1/+8
| |\ \ \ \ | | | | | | | | | | | | SI-7898 Read user input during REPL warmup