summaryrefslogtreecommitdiff
path: root/src/compiler
Commit message (Collapse)AuthorAgeFilesLines
* Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2016-02-251-1/+5
|\ | | | | | | | | | | | | | | | | | | | | merge/2.11.x-to-2.12.x-20160225 Conflicts: scripts/jobs/integrate/bootstrap src/build/maven/scala-actors-pom.xml test/files/pos/t3420.flags Conflicts were trivial to resolve.
| * Merge pull request #4928 from szeiger/wip/document-e-ncLukas Rytz2016-02-101-1/+5
| |\ | | | | | | Document that `scala -e` starts/uses a compilation daemon
| | * Document when the `scala` command starts/uses a compilation daemonStefan Zeiger2016-02-011-1/+5
| | |
* | | Merge pull request #4968 from lrytz/oldOptCleanupAdriaan Moors2016-02-2410-98/+36
|\ \ \ | | | | | | | | Remove -Y settings that are no longer used in 2.12
| * | | Remove -Y settings that are no longer used in 2.12Lukas Rytz2016-02-1610-98/+36
| | | | | | | | | | | | | | | | | | | | | | | | Added a deprecation warning for `-optimize`. Later we'll also graduate `-Yopt` to `-opt`, probably for 2.12.0-M5.
* | | | Merge pull request #4958 from adriaanm/typerefrefactorAdriaan Moors2016-02-242-5/+11
|\ \ \ \ | |/ / / |/| | | Simplify TypeRef hierarchy. baseType returns NoType, as needed for isSubtype. Also improves performance.
| * | | SI-9540 typedFunction is erasure awareAdriaan Moors2016-02-122-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When typer is running during erasure, must assign erased FunctionType in typedFunction. This removes a bunch of unneeded casts now we no longer assign a half-erased FunctionType. I poked around a bit, and it looks like erasure doesn't want typer to erase built-in types (like Unit/Any/Nothing). They are already treated specially during erasure.
* | | | SD-79 don't issue spurious inliner warnings under l:projectLukas Rytz2016-02-154-15/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When enabling `-Yopt:inline-project` (or `-Yopt:l:project`), the inliner would spuriously warn about callsites to methods marked `@inline` that are read from the classpath (not being compiled currently). This patch introduces yet another field to the `Callsite` class, which is growing a bit too large. But the call graph representation will get an overhaul when implementing the new inliner heuristics (2.12.0-M5), so this is just a temporary fix that would be nice to have in M4.
* | | | Avoid generating ACONST_NULL; POP; ACONST_NULL when loading nullLukas Rytz2016-02-142-11/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When loading a value of type scala.runtime.Null$ we need to add POP; ACONST_NULL, see comment in BCodeBodyBuilder.adapt. This is however not necessary if the null value is a simple ACONST_NULL. This patch eliminates that redundancy.
* | | | Generate leaner code for branchesLukas Rytz2016-02-132-87/+94
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GenBCode used to generate more bytecode for branching instructions than GenASM. A simple method def f(x: Int, b: Boolean) = if (b) 1 else 2 would generate ILOAD 2 IFNE L1 GOTO L2 L1 ICONST_1 GOTO L3 L2 ICONST_2 L3 IRETURN If the conditional branch is negated (IFEQ) the GOTO is unnecessary. While -Yopt:l:method would clean this up, it's also not too hard to generate the leaner bytecode in the first place.
* | | | Merge pull request #4944 from lrytz/stringBuilderNoBoxLukas Rytz2016-02-122-9/+20
|\ \ \ \ | | | | | | | | | | SI-9571 Avoid boxing primitives in string concatenation
| * | | | SI-9571 Avoid boxing primitives in string concatenationMarko Elezovic2016-02-062-9/+20
| | | | |
* | | | | Merge pull request #4896 from retronym/topic/indy-all-the-thingsJason Zaugg2016-02-126-165/+104
|\ \ \ \ \ | | | | | | | | | | | | Use invokedynamic for structural calls, symbol literals, lambda ser.
| * | | | | Use invokedynamic for structural calls, symbol literals, lamba ser.Jason Zaugg2016-01-296-165/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous encodings created static fields in the enclosing class to host caches. However, this isn't an option once emit code in default methods of interfaces, as Java interfaces don't allow private static fields. We could continue to emit fields, and make them public when added to traits. Or, as chosen in this commit, we can emulate a call-site specific static field by using invokedynamic: when the call site is linked, our bootstrap methid can perform one-time computation, and we can capture the result in the CallSite. To implement this, I've allowed encoding of arbitrary invokedynamic calls in ApplyDynamic. The encoding is: ApplyDynamic( NoSymbol.newTermSymbol(TermName("methodName")).setInfo(invokedType) Literal(Constant(bootstrapMethodSymbol)) :: ( Literal(Constant(staticArg0)) :: Literal(Constant(staticArgN)) :: Nil ) ::: (dynArg0 :: dynArgN :: Nil) ) So far, static args may be `MethodType`, numeric or string literals, or method symbols, all of which can be converted to constant pool entries. `MethodTypes` are transformed to the erased JVM type and are converted to descriptors as String constants. I've taken advantage of this for symbol literal caching and for the structural call site cache. I've also included a test case that shows how a macro could target this (albeit using private APIs) to cache compiled regexes. I haven't managed to use this for LambdaMetafactory yet, not sure if the facility is general enough.
* | | | | | SI-9650 Refchecks on case apply transformSom Snytt2016-02-101-1/+12
| |_|/ / / |/| | | | | | | | | | | | | | | | | | | Apply checks for unsavoriness when transforming a case apply.
* | | | | Merge pull request #4938 from retronym/ticket/9349Jason Zaugg2016-02-101-3/+3
|\ \ \ \ \ | | | | | | | | | | | | SI-9349 Fix use of patmat binder as prefix for new x.Inner
| * | | | | SI-9349 Fix use of patmat binder as prefix for new x.InnerJason Zaugg2016-02-021-3/+3
| |/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When substituting in references to the synthetic values representing pattern binders, we were replacing: Select(Ident(o).setType(o.type), TypeName("Inner")) with: Select(Ident(x2).setType(typeOf[Outer]), TypeName("Inner")) The post transform in uncurry would then run: else if (tree.isType) TypeTree(tree.tpe) setPos tree.pos Which would loses track of the outer term `o` and crashes the compiler in ExplicitOuter. This commit generates stable references to the binders. I made this change in the substitutions for all `TreeMakers`, however only one of seems like it triggers a crash in the test variations I tried. Here's how the trees for the first pattern in the test case change after this patch: ``` @@ -1,30 +1,30 @@ [[syntax trees at end of patmat]] // test.scala package <empty>{<empty>.type} { object Test extends scala.AnyRef { def <init>(): Test.type = { Test.super{Test.type}.<init>{()Object}(){Object}; (){Unit} }{Unit}; def main(args: Array[String]): Unit = { val o1: Outer = Outer.apply{(i: Int)Outer}(5{Int(5)}){Outer}; { case <synthetic> val x1: Outer = o1{Outer}; case5(){ if (x1.ne{(x$1: AnyRef)Boolean}(null{Null(null)}){Boolean}) matchEnd4{(x: Unit)Unit}({ - val i: Outer#Inner = new x1.Inner{Outer#Inner}{()Outer#Inner}(){Outer#Inner}; + val i: x1.Inner = new x1.Inner{x1.Inner}{()x1.Inner}(){x1.Inner}; (){Unit} }{Unit}){Unit} else case6{()Unit}(){Unit}{Unit} }{Unit}; case6(){ matchEnd4{(x: Unit)Unit}(throw new MatchError{MatchError}{(obj: Any)MatchError}(x1{Outer}){MatchError}{Nothing}){Unit} }{Unit}; matchEnd4(x: Unit){ x{Unit} }{Unit} }{Unit} }{Unit} } ```
* | | | | Merge pull request #4868 from retronym/ticket/9542-comboJason Zaugg2016-02-101-1/+4
|\ \ \ \ \ | | | | | | | | | | | | SI-9542 Fix regression in value classes (served two ways)
| * | | | | SI-9542 Fix regression in value classes with enclosing refsJason Zaugg2016-02-011-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In SI-9473 / e2653736, I changed `mkAttributedRef` to avoid prefixing references to statically owned symbols with a `ThisType`. Turns out there was one place that depended on the old behaviour. ``` object Outer { trait T class C(val value: Any) extends AnyVal { def foo(t: T) = expr } } ``` Is translated to: ``` object Outer { trait T class C(val value: Any) extends AnyVal { def foo(t: T) = Outer.this.C.foo$extension(C.this, t) } object C { def foo$extension($this: C, t: T) = expr } } ``` After the change, the forwarder was instead: ``` def foo(t: T) = Outer.C.foo$extension(C.this, t) ``` Note: this change is not actually necessary after the following commit that makes subtyping unify the different module class reference, that alone is enough to make the enclosed test pass.
* | | | | | SI-9574 Prevent illegal overrides of members with module typesStefan Zeiger2016-02-081-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit f32a32b1b33c9d7ccd62467e3e10cb69930023c8 introduced the ability to override objects with other objects. The exception that allows these overrides (where the usual subtyping check fails) was applied to all members whose type is a module class. This is too broad, however, because it not only applies to members of the form `object foo` but also `def foo: bar.type` (where `bar` is an `object`). The fix is to restrict the exception to those cases where both definitions actually are objects.
* | | | | | Merge remote-tracking branch 'origin/2.12.x' into ↵Jason Zaugg2016-02-045-145/+170
|\ \ \ \ \ \ | | |_|/ / / | |/| | | | | | | | | | merge/2.11.x-to-2.12.x-20160203
| * | | | | Merge pull request #4920 from lrytz/oldOptimizerTestsLukas Rytz2016-02-032-132/+151
| |\ \ \ \ \ | | | | | | | | | | | | | | restore / rewrite various tests
| | * | | | | rename -YoptTrace to -Yopt-traceLukas Rytz2016-02-031-1/+1
| | | | | | |
| | * | | | | Improve simplifyJumpsLukas Rytz2016-02-031-131/+150
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improve simplifyJumps to rewrite IFEQ L4 L5 GOTO L6 to IFNE L6 L5 This rewrite is only correct if L5 is not the target of any jump instruction (otherwise, removing the GOTO would change semantics). Previously we did not do the rewrite if there was any label between the conditional jump and the goto (like L5). Now we track which labels are jump targets.
| * | | | | | Merge pull request #4737 from soc/SI-9315Lukas Rytz2016-02-033-13/+19
| |\ \ \ \ \ \ | | | | | | | | | | | | | | | | SI-9315 Desugar string concat to java.lang.StringBuilder ...
| | * | | | | | SI-9315 Desugar string concat to java.lang.StringBuilder ...Simon Ochsenreither2016-02-033-13/+19
| | |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... instead of scala.collection.mutable.StringBuilder to benefit from JVM optimizations. Unfortunately primitives are already boxed in erasure when they end up in this part of the backend.
* | | | | | | Merge commit 'cc6fea6' into merge/2.11.x-to-2.12.x-20160203Jason Zaugg2016-02-043-35/+58
|\ \ \ \ \ \ \ | | |_|_|_|/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: build.sbt scripts/jobs/integrate/bootstrap
| * | | | | | SI-9572 Check for illegal tuple sizes in the parserStefan Zeiger2016-01-283-35/+58
| | |_|_|_|/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds explicit checks with syntax errors for tuple literals and types of more than 22 elements. An alternative approach to fixing SI-9572 would be to revert to the old failure mode of Scala 2.10 where references to arbitrary `scala.TupleXY` would be generated in the parser, which then leads to “type/object not found” errors in the typechecker. This fix here is more intrusive but arguably provides a better user experience. Methods `stripParens` and `makeBinop` are moved from `TreeBuilder` to `Parsers` because they can now generate syntax errors. New methods `makeSafeTupleType` and `makeSafeTupleTerm` implement the error checking on top of `makeTupleType` and `makeTupleTerm`. They are overridden with no-op versions in the quasiquotes parser because it also overrides `makeTupleType` and `makeTupleTerm` in a way that supports arbitrary tuple sizes.
| * | | | | Merge pull request #4899 from som-snytt/issue/9616Jason Zaugg2016-01-191-12/+15
| |\ \ \ \ \ | | | | | | | | | | | | | | [backport] SI-9616 False positive in unused import warning
| | * | | | | [backport] SI-9616 False positive in unused import warningSom Snytt2016-01-071-12/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a minimal backport of the fix for SI-9383.
* | | | | | | Merge commit 'bf599bc' into merge/2.11.x-to-2.12.x-20160203Jason Zaugg2016-02-036-8/+20
|\| | | | | | | |_|/ / / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/compiler/scala/tools/nsc/backend/opt/ConstantOptimization.scala src/compiler/scala/tools/nsc/transform/Constructors.scala src/compiler/scala/tools/nsc/typechecker/Contexts.scala src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala src/scaladoc/scala/tools/nsc/doc/html/resource/lib/jquery.layout.js
| * | | | | Fix some simple extra wordsEitan Adler2016-01-177-7/+7
| |/ / / / | | | | | | | | | | | | | | | The the word 'the' is often used twice. Fix that.
| * | | | SI-9567 Fix pattern match on 23+ param, method local case classJason Zaugg2015-11-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Typechecking constructor patterns of method local case classes was only working because of the existence of the unapply method in the companion, which is used if navigation to the case class companion object fails. We now support defintion of, and pattern matching on, case classes with more than 22 parameters. These have no `unapply` method in the companion, as we don't have a large enough tuple type to return. So for such case classes, the fallback that we inadvertently relied on would no longer save us, and we'd end up with a compile error advising that the identifier in the constructor pattern was neither a case class nor an extractor. This is due to the propensity of `Symbol#companionXxx` to return `NoSymbol` when in the midst of typechecking. That method should only be relied upon after typechecking. During typechecking, `Namers#companionSymbolOf` should be used instead, which looks in the scopes of enclosing contexts for symbol companionship. That's what I've done in this commit.
| * | | | SI-9567 Fix latent bugs in patmat's reasoning about mutabilityJason Zaugg2015-11-251-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Under -optimize, the pattern matcher tries to avoid local variables in favour of directly accessing to non-var case class accessors. However, the code that analysed the patterns failed to account properly for repeated parameters, which could either lead to a compiler crash (when assuming that the n-th subpattern must have a corresponding param accessor), or could lead to a correctness problem (when failing to eagerly the bound elements from the sequence.) The test case that tried to cover seems only to have been working because of a separate bug (the primary subject of SI-9567) related to method-local case classes: they were treated during typechecking as extractors, rather than native case classes. The subsequent commit will fix that problem, but first we must pave the way with this commit that emits local vals for bound elements of case class repeated params.
* | | | | Merge pull request #4926 from lrytz/scalaTreeMapJason Zaugg2016-02-011-6/+4
|\ \ \ \ \ | |_|_|/ / |/| | | | mutable.TreeMap instead of java.util.TreeMap in closure optimizer
| * | | | mutable.TreeMap instead of java.util.TreeMap in closure optimizerLukas Rytz2016-01-281-6/+4
| | |_|/ | |/| |
* | | | Merge pull request #4917 from retronym/ticket/9629Jason Zaugg2016-01-291-4/+4
|\ \ \ \ | | | | | | | | | | SI-9629 Emit missing 'pattern must be a value' error
| * | | | SI-9629 Emit missing 'pattern must be a value' errorJason Zaugg2016-01-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The error used to only be emitted for top-level patterns. This commit moves it into `typedInternal` so it works for nested patterns. It uses the typer mode to know when to fire.
* | | | | Merge pull request #4919 from retronym/ticket/9630Jason Zaugg2016-01-294-9/+16
|\ \ \ \ \ | |_|/ / / |/| | | | Pattern Matching analysis improvements
| * | | | Avoid exhaustivity warning in typedTemplateJason Zaugg2016-01-291-1/+1
| | | | |
| * | | | Fix non-exhaustive match in macro code parsingJason Zaugg2016-01-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ``` ⚡ qscala -deprecation Welcome to Scala 2.12.0-20160126-000825-1e302b76aa (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_66). Type in expressions for evaluation. Or try :help. scala> import reflect.macros.blackbox.Context; import language.experimental.macros import reflect.macros.blackbox.Context import language.experimental.macros scala> def impl(c: Context) = {println(c.universe.showRaw(c.parse("val then = 0"))); c.literalUnit}; def m: Unit = macro impl; <console>:13: warning: method literalUnit in trait ExprUtils is deprecated: Use quasiquotes instead def impl(c: Context) = {println(c.universe.showRaw(c.parse("val then = 0"))); c.literalUnit}; def m: Unit = macro impl; ^ impl: (c: scala.reflect.macros.blackbox.Context)c.Expr[Unit] defined term macro m: Unit scala> m <console>:16: error: exception during macro expansion: scala.MatchError: pos: source-<macro>,line-1,offset=4 then is now a reserved word; usage as an identifier is deprecated WARNING (of class scala.tools.nsc.reporters.StoreReporter$Info) at scala.reflect.macros.contexts.Parsers$class.scala$reflect$macros$contexts$Parsers$class$$$anonfun$1(Parsers.scala:17) ```
| * | | | SI-9398 Treat case classes as one-element ADTs for analysisJason Zaugg2016-01-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, exhaustivity analysis only runs for scrutinees with a sealed type. This commit treats any case class as a one-element, sealed type to enable additional analysis, such as in the new test case.
| * | | | SI-9630 Fix spurious warning related to same-named case accessorsJason Zaugg2016-01-292-7/+11
| | |_|/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hash consing of trees within pattern match analysis was broken, and considered `x1.foo#1` to be the same tree as `x1.foo#2`, even though the two `foo`-s referred to different symbols. The hash consing was based on `Tree#correspondsStructure`, but the predicate in that function cannot veto correspondance, it can only supplement the default structural comparison. I've instead created a custom tree comparison method for use in the pattern matcher that handles the tree shapes that we use.
* / | | Ensure bytecode stability in the closure optimizerLukas Rytz2016-01-271-38/+33
|/ / / | | | | | | | | | | | | | | | | | | | | | https://github.com/scala/scala-dev/issues/77 Previously, the order in which closure invocations were re-written depended on the callGraph's closureInstantiations map, which is not sorted / linked.
* | | Merge pull request #4735 from soc/SI-9437Lukas Rytz2016-01-263-6/+32
|\ \ \ | | | | | | | | SI-9437 Emit and support parameter names in class files
| * | | SI-9437 Emit and support parameter names in class filesSimon Ochsenreither2016-01-253-6/+32
| |/ / | | | | | | | | | | | | | | | | | | | | | JEP 118 added a MethodParameters attribute to the class file spec which holds the parameter names of methods when compiling Java code with `javac -parameters`. We emit parameter names by default now.
* | | -YoptTrace takes a package/Class.method parameterLukas Rytz2016-01-252-2/+3
| | |
* | | Merge remote-tracking branch 'upstream/2.12.x' into opt/elimBoxesLukas Rytz2016-01-24118-16484/+1376
|\| |
| * | Merge pull request #4903 from som-snytt/issue/9622Jason Zaugg2016-01-181-9/+10
| |\ \ | | | | | | | | SI-9622 Native method may be private
| | * | SI-9622 Native method may be privateSom Snytt2016-01-131-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | This was lost in a refactor. https://github.com/scala/scala/commit/290f687fb6ab91b6aef62d871036ddc3829f12b4