summaryrefslogtreecommitdiff
path: root/src/compiler
Commit message (Collapse)AuthorAgeFilesLines
* 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
| | * | | SI-7898 Read user input during REPL warmupSom Snytt2016-05-202-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The compiler is created on main thread and user input is read on an aux thread (opposite to currently). Fixes completion when `-i` is supplied. Now `-i` means pasted and new option `-I` means line-by-line. The temporary reader uses postInit to swap in the underlying reader. Completion is disabled for the temporary reader, rather than blocking while it waits for a compiler. But manically hitting tab is one way of knowing exactly when completion is live.
* | | | | Merge commit 'cba585d' into merge-2.11-to-2.12-june-1Lukas Rytz2016-06-011-44/+64
|\| | | |
| * | | | Merge pull request #5169 from som-snytt/issue/4625Lukas Rytz2016-05-231-44/+64
| |\ \ \ \ | | |/ / / | |/| | | SI-4625 Recognize App in script
| | * | | SI-4625 Warn on first non-toplevel onlySom Snytt2016-05-171-42/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixed the warning when main module is accompanied by snippets. Minor clean-up so even I can follow what is returned.
| | * | | SI-4625 Warn when discarding script objectSom Snytt2016-05-171-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's pretty confusing when your script object becomes a local and then nothing happens. Such as when you're writing a test and it takes forever to figure out what's going on.
| | * | | SI-4625 Permit arbitrary top-level in scriptSom Snytt2016-05-161-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In an unwrapped script, where a `main` entry point is discovered in a top-level object, retain all top-level classes. Everything winds up in the default package.
| | * | | SI-4625 App is a thingSom Snytt2016-05-161-1/+4
| | | | | | | | | | | | | | | | | | | | Scripting knows it by name.
| | * | | SI-4625 Recognize App in scriptSom Snytt2016-05-161-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cheap name test: if the script object extends "App", take it for a main-bearing parent. Note that if `-Xscript` is not `Main`, the default, then the source is taken as a snippet and there is no attempt to locate an existing `main` method.
* | | | | Merge commit '90706b0' into merge-2.11-to-2.12-june-1Lukas Rytz2016-06-011-2/+0
|\| | | | | |_|/ / |/| | |
| * | | Remove default value for sourcepath in scalac (ant version). (#5166)Krzysztof Romanowski2016-05-171-2/+0
| |/ /
* | | Merge pull request #5076 from soc/topic/deprecations-sinceLukas Rytz2016-05-3014-57/+81
|\ \ \ | | | | | | | | Improvements to deprecations related to `since` parameter
| * | | Add since arg to deprecationWarning and use itSimon Ochsenreither2016-05-2914-59/+79
| | | |
| * | | Lower-case spelling of @deprecated messagesSimon Ochsenreither2016-05-281-1/+1
| | | |
| * | | SI-9084 Add `since` (if available) to deprecation warningsSimon Ochsenreither2016-05-285-11/+15
| | | |
* | | | Merge pull request #5193 from som-snytt/issue/9794Lukas Rytz2016-05-301-1/+1
|\ \ \ \ | |/ / / |/| | | SI-9794 Error advice uses decoded method name
| * | | SI-9794 Error advice uses decoded method nameSom Snytt2016-05-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | So much work went into polishing this error message, it's worth buffing the method name when it's an operator. The message now says `+` instead of `$plus`.
* | | | Merge pull request #5102 from milessabin/2.12.xJason Zaugg2016-05-271-1/+2
|\ \ \ \ | | | | | | | | | | SI-2712 Add support for partial unification of type constructors
| * | | | -Xexperimental mode now only includes -Ypartial-unificationMiles Sabin2016-05-241-1/+1
| | | | |
| * | | | SI-2712 Add support for higher order unificationMiles Sabin2016-05-241-0/+1
| | | | |
* | | | | Merge pull request #5186 from lrytz/inlinerM5Jason Zaugg2016-05-275-13/+82
|\ \ \ \ \ | |_|/ / / |/| | | | Debug flag to print a summary of the inliner's work
| * | | | Debug flag to print a summary of the inliner's workLukas Rytz2016-05-245-13/+82
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Example output below. Note that inlining List.map fails because the trait forwarder uses `INVOKESPECIAL` for now, will change with pr 5177. $ cat Test.scala class C { def foo = Map(1 -> 'a', 2 -> 'b') def bar(l: List[Int]) = l.map(_ + 1) } $ qsc -Yopt-log-inline _ -Yopt:l:classpath Test.scala Inlining into C.foo (initially 36 instructions, ultimately 72): - Inlined scala/Predef$ArrowAssoc$.$minus$greater$extension (8 instructions) 2 times: the callee is annotated `@inline` Inlining into C.bar (initially 12 instructions, ultimately 12): - Failed to inline scala/collection/immutable/List.map (the callee is a higher-order method, the argument for parameter (bf: Function1) is a function literal): The callee scala/collection/immutable/List::map(Lscala/Function1;Lscala/collection/generic/CanBuildFrom;)Ljava/lang/Object; contains the instruction INVOKESPECIAL scala/collection/TraversableLike.map (Lscala/Function1;Lscala/collection/generic/CanBuildFrom;)Ljava/lang/Object; that would cause an IllegalAccessError when inlined into class C.
* | | | Rename -Yopt to -opt, -Yopt-warnings to -opt-warningsLukas Rytz2016-05-2512-85/+85
| | | | | | | | | | | | | | | | Keep -Yopt-inline-heuristics and -Yopt-trace unchanged
* | | | Merge pull request #4935 from som-snytt/issue/8044-tickvarAdriaan Moors2016-05-241-8/+8
|\ \ \ \ | |/ / / |/| | | SI-8044 Allow binding backquoted varid in patterns