summaryrefslogtreecommitdiff
path: root/src/compiler
Commit message (Collapse)AuthorAgeFilesLines
* SI-9415 Turn on SAM by defaultJason Zaugg2016-03-262-2/+2
| | | | | | | | | | Initial work to change settings and test by Svyatoslav Ilinskiy Thanks! To avoid cycles during overload resolution (which showed up during bootstrapping), and to improve performance, I've guarded the detection of SAM types in `isCompatible` to cases when the LHS is potentially compatible.
* Refactor. Extract mkLiteralUnit and mkUnitBlockAdriaan Moors2016-03-261-1/+1
|
* Remove dead code now that `genBCodeActive` is always true.Adriaan Moors2016-03-265-343/+57
|
* Merge pull request #5053 from som-snytt/issue/9314Lukas Rytz2016-03-231-7/+13
|\ | | | | SI-9314 Marginal edge case to warn-missing-interp
| * SI-9314 No warn on ${nonid}Som Snytt2016-03-231-7/+11
| | | | | | | | | | Use the sym test on an expr that happens to be a subset of idents and is not in scope. Other `${ operator_* }` warn.
| * SI-9314 Ignore "${}"Som Snytt2016-03-201-3/+5
| | | | | | | | | | | | | | As an Easter egg, let "${} $x" forego the check on `x`. In other words, empty expression interpolation looks too degenerate to check.
| * SI-9314 Don't warn on "$pkg"Som Snytt2016-03-201-1/+1
| | | | | | | | | | Edge cases of things not to warn about include package names.
* | Merge pull request #5057 from lrytz/flatClasspathLukas Rytz2016-03-2314-191/+334
|\ \ | | | | | | Enable -YclasspathImpl:flat by default
| * | Support :require when using the flat classpath representation.Lukas Rytz2016-03-226-80/+196
| | | | | | | | | | | | | | | | | | :require was re-incarnated in https://github.com/scala/scala/pull/4051, it seems to be used by the spark repl. This commit makes it work when using the flat classpath representation.
| * | Enable flat classpath by defaultLukas Rytz2016-03-229-111/+138
| | | | | | | | | | | | | | | | | | | | | Implements VirtualDirectoryFlatClassPath, which is required for the presentation compiler created for the repl's tab-completion. Various minor cleanups in the flat classpath implementation.
* | | Merge pull request #5047 from kmizu/resolve-several-warningsAdriaan Moors2016-03-221-1/+1
|\ \ \ | |/ / |/| | Resolve several deprecation warnings
| * | * Replace isPackage with hasPackageFlagKota Mizushima2016-03-171-1/+1
| |/
* | Merge pull request #5043 from dongjoon-hyun/fix_typos_in_spec_and_commentsJason Zaugg2016-03-2113-18/+18
|\ \ | | | | | | Fix some typos in `spec` documents and comments.
| * | Fix some typos in `spec` documents and comments.Dongjoon Hyun2016-03-1513-18/+18
| |/
* | Remove manual mixins in JFunctionN.v2.12.0-M3-dc9effeJason Zaugg2016-03-182-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These manual mixins were forwarding to the impl classes have just been removed. We can now rely on default methods instead. Update Tests: - Fix test/files/pos/t1237.scala, we can't have an outer field in an interface, always use the outer method. - Don't crash on meaningless trait early init fields test/files/neg/t2796.scala - Remove impl class relate parts of inner class test - Remove impl class relate parts of elidable test - Remove impl class related reflection test. - Remove test solely about trait impl classes renaming - Update check file with additional stub symbol error - Disable unstable parts of serialization test. - TODO explain, and reset the expectation
* | New trait encoding: use default methods, jettison impl classesJason Zaugg2016-03-1820-726/+170
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Until now, concrete methods in traits were encoded with "trait implementation classes". - Such a trait would compile to two class files - the trait interface, a Java interface, and - the implementation class, containing "trait implementation methods" - trait implementation methods are static methods has an explicit self parameter. - some methods don't require addition of an interface method, such as private methods. Calls to these directly call the implementation method - classes that mixin a trait install "trait forwarders", which implement the abstract method in the interface by forwarding to the trait implementation method. The new encoding: - no longer emits trait implementation classes or trait implementation methods. - instead, concrete methods are simply retained in the interface, as JVM 8 default interface methods (the JVM spec changes in [JSR-335](http://download.oracle.com/otndocs/jcp/lambda-0_9_3-fr-eval-spec/index.html) pave the way) - use `invokespecial` to call private or particular super implementations of a method (rather `invokestatic`) - in cases when we `invokespecial` to a method in an indirect ancestor, we add that ancestor redundantly as a direct parent. We are investigating alternatives approaches here. - we still emit trait fowrarders, although we are [investigating](https://github.com/scala/scala-dev/issues/98) ways to only do this when the JVM would be unable to resolve the correct method using its rules for default method resolution. Here's an example: ``` trait T { println("T") def m1 = m2 private def m2 = "m2" } trait U extends T { println("T") override def m1 = super[T].m1 } class C extends U { println("C") def test = m1 } ``` The old and new encodings are displayed and diffed here: https://gist.github.com/retronym/f174d23f859f0e053580 Some notes in the implementation: - No need to filter members from class decls at all in AddInterfaces (although we do have to trigger side effecting info transformers) - We can now emit an EnclosingMethod attribute for classes nested in private trait methods - Created a factory method for an AST shape that is used in a number of places to symbolically bind to a particular super method without needed to specify the qualifier of the `Super` tree (which is too limiting, as it only allows you to refer to direct parents.) - I also found a similar tree shape created in Delambdafy, that is better expressed with an existing tree creation factory method, mkSuperInit.
* Merge pull request #4974 from szeiger/wip/patmat-outertestAdriaan Moors2016-03-143-23/+31
|\ | | | | More conservative optimization for unnecessary outer ref checks
| * Improved outer ref checking in pattern matches:Adriaan Moors2016-03-073-23/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The old algorithm omitted necessary outer ref checks in some places. This new one is more conservative. It only omits outer ref checks when the expected type and the scrutinee type match up, or when the expected type is defined in a static location. For this specific purpose the top level of a method or other code block (which is not a trait or class definition) is also considered static because it does not have a prefix. This change comes with a spec update to clarify the prefix rule for type patterns. The new wording makes it clear that the presence of a prefix is to be interpreted in a *semantic* way, i.e. the existence of a prefix determines the necessity for an outer ref check, no matter if the prefix is actually spelled out *syntactically*. Note that the old outer ref check implementation did not use the alternative interpretation of requiring prefixes to be given syntactically. It never created an outer ref check for a local class `C`, no matter if the pattern was `_: C` or `_: this.C`, thus violating both interpretations of the spec. There is now explicit support for unchecked matches (like `case _: (T @unchecked) =>`) to suppress warnings for unchecked outer refs. `@unchecked` worked before and was used for this purpose in `neg/t7721` but never actually existed as a feature. It was a result of a bug that prevented an outer ref check from being generated in the first place if *any* annotation was used on an expected type in a type pattern. This new version will still generate the outer ref check if an outer ref is available but suppress the warning otherwise. Other annotations on type patterns are ignored. New tests are in `neg/outer-ref-checks`. The expected results of tests `neg/t7171` and `neg/t7171b` have changed because the compiler now tries to generate additional outer ref checks that were not present before (which was a bug).
* | Merge 2.11.x into 2.12.xAdriaan Moors2016-03-141-38/+47
|\ \ | | | | | | | | | Resolved conflicts as in b0e05b67c7
| * | SI-9425 Fix a residual bug with multi-param-list case classesJason Zaugg2016-03-041-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | During code review for the fix for SI-9546, we found a corner case in the SI-9425 that remained broken. Using `finalResultType` peels off all the constructor param lists, and solves that problem.
| * | SI-9546 Fix regression in rewrite of case apply to constructor callJason Zaugg2016-03-021-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In SI-9425, I disabled the rewrite of `CaseClass.apply(x)` to `new CaseClass(x)` if the constructor was was less accessible than the apply method. This solved a problem with spurious "constructor cannot be accessed" errors during refchecks for case classes with non-public constructors. However, for polymorphic case classes, refchecks was persistent, and even after refusing to transform the `TypeApply` within: CaseClass.apply[String]("") It *would* try again to transform the enclosing `Select`, a code path only intended for monomorphic case classes. The tree has a `PolyType`, which foiled the newly added accessibility check. I've modified the call to `isSimpleCaseApply` from the transform of `Select` nodes to exclude polymorphic apply's from being considered twice.
| * | Refactor transform of case apply in refchecksJason Zaugg2016-03-021-28/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I've identified a dead call to `transformCaseApply` that seems to date back to Scala 2.6 vintages, in which case factory methods were a fictional companion method, rather than a real apply method in a companion module. This commit adds an abort in that code path to aide code review (if our test suite still passes, we know that I've removed dead code, rather than silently changing behaviour.) The following commit will remove it altogether I then inlined a slightly clunky abstraction in the two remaining calls to `transformCaseApply`. It was getting in the way of a clean fix to SI-9546, the topic of the next commit.
* | | SI-9658 Fix crosstalk between partial fun. and GADT matchJason Zaugg2016-03-041-2/+2
| |/ |/| | | | | | | | | | | | | | | | | | | | | When typechecking the synthetic default case of a pattern matching anonymous partial function, we failed to create a new `Context`. This led to crosstalk with the management of the saved type bounds of an enclosing GADT pattern match. This commit avoids the direct call to `typeCase` and instead indirects through `typedCases`, which spawns a new nested typer context, and hence avoids the crosstalk when `restoreSavedTypeBounds` runs.
* | 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