summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform
Commit message (Collapse)AuthorAgeFilesLines
* SI-8040 Heeding -Ywarn-unusedSom Snytt2017-03-111-1/+1
| | | | | | | Polish notation, as in shoe-shine, as recommended by the warning. Minor clean-ups as advocated by `Ywarn-unused` and `Xlint`.
* Revert "Fix erasure of the qualifier of ##"Adriaan Moors2017-02-221-7/+6
|
* Merge pull request #5658 from retronym/topic/hashhashLukas Rytz2017-02-211-6/+7
|\ | | | | Fix erasure of the qualifier of ##
| * Fix erasure of the qualifier of ##Jason Zaugg2017-01-241-6/+7
| |
* | Merge pull request #5704 from som-snytt/issue/10190-elide-stringLukas Rytz2017-02-211-2/+6
|\ \ | | | | | | SI-10190 Elide string to empty instead of null
| * | SI-10190 Elide string to empty instead of nullSom Snytt2017-02-151-2/+6
| |/ | | | | | | | | | | | | | | Avoid NPE when eliding string-valued functions. For example, `log(s"$cheap$expensive")` needn't print null. This is a natural and inexpensive way to elide strings.
* | Merge branch '2.12.x' into merge-2.11.x-to-2.12.x-20170214Seth Tisue2017-02-1710-15/+15
|\ \
| * | Fix typos in compiler and reflectJanek Bogucki2017-02-1310-15/+15
| |/ | | | | | | | | | | | | | | | | | | | | | | Miscellania: Miscellania is a small island off the northernmost part of the Fremennik Isles - RunScape Wiki Miscellanea: A collection of miscellaneous objects or writings - Merriam-Webster
* | Merge commit '0965028809' into merge-2.11.x-to-2.12.x-20170214Seth Tisue2017-02-161-17/+21
|\ \
| * | SI-1459 two bridges for impl of java generic vararg methodAdriaan Moors2017-01-241-17/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A Scala method that implements a generic, Java-defined varargs method, needs two bridges: - to convert the collections for the repeated parameters (VBRIDGE) - to bridge the generics gap (BRIDGE) Refchecks emits the varargs "bridges", and erasure takes care of the other gap. Because a VBRIDGE was also an ARTIFACT, it was wrongly considered inert with respect to erasure, because `OverridingPairs` by default excluded artifacts. Removed the artifact flag from those VBRIDGES, so that they qualify for a real bridge. It would also work to include VBRIDGE methods that are artifacts in BridgesCursor.
| * | SI-10071 Separate compilation for varargs methodsIulian Dragos2017-01-092-64/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make sure that methods annotated with varargs are properly mixed-in. This commit splits the transformation into an info transformer (that works on all symbols, whether they come from source or binary) and a tree transformer. The gist of this is that the symbol-creation part of the code was moved to the UnCurry info transformer, while tree operations remained in the tree transformer. The newly created symbol is attached to the original method so that the tree transformer can still retrieve the symbol. A few fall outs: - I removed a local map that was identical to TypeParamsVarargsAttachment - moved the said attachment to StdAttachments so it’s visible between reflect.internal and nsc.transform - a couple more comments in UnCurry to honour the boy-scout rule
| * | SI-8786 fix generic signature for @varargs forwarder methodsLukas Rytz2017-01-092-52/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When generating a varargs forwarder for def foo[T](a: T*) the parameter type of the forwarder needs to be Array[Object]. If we generate Array[T] in UnCurry, that would be erased to plain Object, and the method would not be a valid varargs. Unfortunately, setting the parameter type to Array[Object] lead to an invalid generic signature - the generic signature should reflect the real signature. This change adds an attachment to the parameter symbol in the varargs forwarder method and special-cases signature generation. Also cleans up the code to produce the varargs forwarder. For example, type parameter and parameter symbols in the forwarder's method type were not clones, but the same symbols from the original method were re-used. Backported from 0d2760dce189cdcb363e54868381175af4b2646f, with a small tweak (checkVarargs) to make the test work on Java 6, as well as later versions.
| * | SI-9630 Fix spurious warning related to same-named case accessors [backport]Jason Zaugg2016-12-212-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. (cherry picked from commit 79a52e6807d2797dee12bab1730765441a0e222d)
| * | More robust outer test for patmatAdriaan Moors2016-12-211-10/+8
| | | | | | | | | | | | While investigating https://github.com/scala/scala-dev/issues/251
* | | Merge commit '014ebc4' into merge-2.11.x-to-2.12.x-20170214Seth Tisue2017-02-162-15/+19
|\| | | |/ |/|
| * Small cleanups to pattern matcherAdriaan Moors2016-12-212-15/+19
| | | | | | | | While investigating https://github.com/scala/scala-dev/issues/251
* | Merge pull request #5583 from lrytz/t10093Adriaan Moors2016-12-211-5/+5
|\ \ | | | | | | SI-10093 don't move member traits to constructor body in constructors
| * | SI-10093 don't move member traits to constructor body in constructorsLukas Rytz2016-12-061-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes a regression introduced in c8e6050. Member traits with only abstract definitions (`isInterface`) were moved into the primary constructor by mistake. (Flatten moved the classes back.) The member trait was duplicated into the constructor of specialized subclasses, causing it to be generated multiple times. Also removes some unnecessary `isMixinConstructor` checks: the mixin constructor is always the primary constructor. This commit also clarifies (and tests) what `isInterface` means: for scala-defined traits, it means there are only abstract members. For java-defined interfaces, it is always true.
* | | Merge pull request #5539 from som-snytt/issue/10068Adriaan Moors2016-12-191-1/+10
|\ \ \ | | | | | | | | SI-10068 Only permit elidable methods
| * | | SI-10068 Only permit elidable methodsSom Snytt2016-12-141-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In refchecks, check that symbol with `@elidable` is a method. When eliding in uncurry, doublecheck. The check is enabled under `-Xsource:2.13`.
* | | | Merge pull request #5541 from retronym/ticket/10067Adriaan Moors2016-12-192-1/+2
|\ \ \ \ | |/ / / |/| | | SI-10067 Avoid linkage errors with type patterns, Java inner classes
| * | | SI-10067 Don't speculatively emit outer tests for inner Java classesJason Zaugg2016-11-181-0/+1
| | | | | | | | | | | | | | | | | | | | Followup to the previous commit to remove the unchecked warning when the speculative outer test is dropped in explicitouter.
| * | | SI-10067 Java defined inner classes don't have outer accessorsJason Zaugg2016-11-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we pretend they do, we can walk into NoSuchMethodErrors when translating type patterns path dependent types. This commit avoids this symptom by changing the explicitouter info transformer. A following commit will change the pattern matcher itself to avoid speculatively adding this outer check that will be always dropped in explicitouter.
* | | | SI-10075 annotations go to lazy val's underlying fieldAdriaan Moors2016-12-052-14/+33
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This likely regressed in #5294. Review feedback from retronym: - Tie annotation triaging a bit closer together durban kindly provided initial version of test/files/run/t10075.scala And pointed out you must force `lazy val`, since `null`-valued field is serializable regardless of its type. Test test/files/run/t10075b courtesy of retronym
* | | Merge pull request #5536 from retronym/ticket/SD-268Adriaan Moors2016-11-292-15/+16
|\ \ \ | | | | | | | | Fix more compiler crashes with fields, refinement types
| * | | Fix more compiler crashes with fields, refinement typesJason Zaugg2016-11-212-15/+16
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the same manner as scala/scala-dev#219, the placement of the fields phase after uncurry is presenting some challenges in keeping our trees type correct. This commit whacks a few more moles by adding a casts in the body of synthetic methods. Fixes scala/scala-dev#268
* | | Merge pull request #5506 from retronym/topic/existential-idsAdriaan Moors2016-11-291-1/+1
|\ \ \ | | | | | | | | Avoid name table pollution with fresh existentials
| * | | Avoid name table pollution with fresh existentialsJason Zaugg2016-11-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During large compilations runs, the large numbers of globally unique fresh names for existentials captured from prefixes of `asSeenFrom`. is a) somewhat wasteful (all these names are interned in the name table) , and, b) form a pathological case for the current implementation of `Names#hashValue`, which leads to overfull hash-buckets in the name table. `hashValue` should probably be improved, but my attempts to do so have shown a small performance degradation in some benchmarks. So this commit starts by being more frugal with these names, only uniquely naming within an `asSeenFrom` operation. References scala/scala-dev#246
* | | | Merge pull request #5556 from dragos/ticket/10071Iulian Dragos2016-11-252-62/+34
|\ \ \ \ | | | | | | | | | | SI-10071 Separate compilation for varargs methods
| * | | | SI-10071 Separate compilation for varargs methodsIulian Dragos2016-11-252-62/+34
| | |/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make sure that methods annotated with varargs are properly mixed-in. This commit splits the transformation into an info transformer (that works on all symbols, whether they come from source or binary) and a tree transformer. The gist of this is that the symbol-creation part of the code was moved to the UnCurry info transformer, while tree operations remained in the tree transformer. The newly created symbol is attached to the original method so that the tree transformer can still retrieve the symbol. A few fall outs: - I removed a local map that was identical to TypeParamsVarargsAttachment - moved the said attachment to StdAttachments so it’s visible between reflect.internal and nsc.transform - a couple more comments in UnCurry to honour the boy-scout rule
* / | | SI-9814 Fix synchronized in specialized overridesJason Zaugg2016-11-251-1/+2
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specialization creates a subclasses of a specializd class for each type parameter combination. These contains copies of the methods from the superclass. However, before this transform, the pattern of self-synchronization in a method body had been replace by flag Flag.SYNCHRONIZED on the method symbol. This was not being propagated to the override, and hence no locking occured. This commit modifies the creation of the specialized overload symbol to copy the SYNCHRONIZED flag, as was already done for ASBOVERRIDE. I have also done the same for the `@strictfp` annotation.
* | | Merge pull request #5534 from lrytz/t10059Lukas Rytz2016-11-161-1/+1
|\ \ \ | | | | | | | | SI-10059 reset the `DEFERRED` flag for Java varargs forwarders
| * | | SI-10059 reset the `DEFERRED` flag for Java varargs forwardersLukas Rytz2016-11-161-1/+1
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an abstract method is annotated `@varargs`, make sure that the generated synthetic Java varargs method does not have the `DEFERRED` flag (`ACC_ABSTRACT` in bytecode). The flag lead to an NPE in the code generator, because the ASM framework leaves certain fields `null` for abstract methods (`localVariables` in this case). Interestingly this did not crash in 2.11.x: the reason is that the test whether to emit a method body or not has changed in the 2.12 backend (in c8e6050). val isAbstractMethod = [..] methSymbol.isDeferred [..] // 2.11 val isAbstractMethod = rhs == EmptyTree // 2.12 So in 2.11, the varargs forwarder method was actually left abstract in bytecode, leading to an `AbstractMethodError: T.m([I)I` at run-time.
* / / Typo and spelling correctionsJanek Bogucki2016-11-112-2/+2
|/ /
* | assorted typo fixes, cleanup, updating of commentsSeth Tisue2016-10-241-2/+2
| | | | | | | | | | | | just in time for Halloween. "boostrap" is definitely the most adorable typo evah -- and one of the most common, too. but we don't want to scare anybody.
* | Detect clash of mixedin val and existing member.Adriaan Moors2016-10-122-14/+20
| | | | | | | | | | | | | | | | | | Before, we looked only at the result type, which was silly. This was originally motivated by a hack to get to the error about conflicting paramaccessors. The error detection for that can now be formulated more directly. Fixes scala/scala-dev#244
* | Merge pull request #5429 from lrytz/sd224Adriaan Moors2016-10-111-4/+5
|\ \ | | | | | | Default -Xmixin-force-forwarders to true
| * | Default -Xmixin-force-forwarders to trueLukas Rytz2016-09-301-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also eliminates the warning when a mixin forwarder cannot be implemented because the target method is a java-defined default method in an interface that is not a direct parent of the class. The test t5148 is moved to neg, as expected: It was moved to pos when disabling mixin forwarders in 33e7106. Same for the changed error message in t4749.
* | | SI-9946 don't null field in lazy accessors that turn out to be liveJason Zaugg2016-10-073-72/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a non-transient lazy val is the only user of a private field in a class, the field is nulled out at the end of the lazy initializer. This is tested in the existing test `run/lazy-leaks.scala`. The analysis of which fields could be nulled out was recently moved from `mixin` to the new `fields` phase. This introduced a regression as a reference from an inner- or companion-classes had not yet been processed by `explicitouter` to publicise private fields. This commit delays the analysis to mixin (after explicit outer has done its work.) Navigating from `foo$lzycompute()` to `foo()` to `foo` is a little dirty now. I'm not sure whether there is a more robust way to structure things.
* | | SI-9946 make nullification of lazy val dependencies module awareJason Zaugg2016-10-071-1/+1
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a non-transient lazy val is the only user of a private field in a class, the field is nulled out at the end of the lazy initializer. This is tested in the existing test `run/lazy-leaks.scala`. The analysis of which fields could be nulled out was recently moved from `mixin` to the new `fields` phase. This introduced a regression as a it didn't account for the richer pallete of trees and symbols at that juncture. This commit excludes references to private member modules from collection of private fields, thus avoiding a later compiler crash in the backend due to a nonsense tree trying to null out the module symbol. It might make sense to null out the module var, but I've opted to limit the scope of this analysis to paramaccessors and regular fields.
* | Merge pull request #5430 from adriaanm/dev235Adriaan Moors2016-09-291-30/+29
|\ \ | | | | | | Emit local module like lazy val
| * | Clarify docs, variable nameAdriaan Moors2016-09-291-11/+12
| | | | | | | | | | | | A local lazy val and a local object are expanded in the same way.
| * | Emit local module like lazy valAdriaan Moors2016-09-291-22/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | The motivation is to use the new fine-grained lock scoping that local lazies have since #5294. Fixes scala/scala-dev#235 Co-Authored-By: Jason Zaugg <jzaugg@gmail.com>
* | | Merge pull request #5423 from lrytz/sd229Adriaan Moors2016-09-282-11/+35
|\ \ \ | | | | | | | | | | | | | | | | Fixes for DelayedInit classes capturing values Fix scala/scala-dev#229
| * | | SI-4683 fix $outer accesses in class bodies extending DelayedInitLukas Rytz2016-09-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Constructors rewrites references to parameter accessor methods in the constructor to references to parameters. It avoids doing so for subclasses of DelayedInit. This commit makes sure the rewrite does not happen for the $outer paramter, a case that was simply forgotten.
| * | | SI-9697 / SD-229 Fix DelayedInit subclass capturing local valueLukas Rytz2016-09-281-10/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a class captures an outer value, a field for that value is created in the class. The class also gets a constructor parameter for the captured value, the constructor will assign the field. LambdaLift re-writes accesses to the local value (Ident trees) to the field. However, if the statement accessing the local value will end up inside the constructor, the access is re-written to the constructor parameter instead. This is the case for constructor statements: class C { { println(capturedLocal) } } If C extends DelayedInit, the statement does not end up in C's constructor, but into a new synthetic method. The access to `capturedLocal` needs to be re-written to the field instead of the constructor parameter. LambdaLift takes the decision (field or constructor parameter) based on the owner chain of `currentOwner`. For the constructor statement block, the owner is a local dummy, for which `logicallyEnclosingMember` returns the constructor symbol. This commit introduces a special case in LambdaLift for local dummies of DelayedInit subclasses: instead of the constructor, we use a temporary symbol representing the synthetic method holding the initializer statements.
* | | | Merge pull request #5397 from retronym/ticket/9920Adriaan Moors2016-09-282-2/+9
|\ \ \ \ | |_|/ / |/| | | SI-9920 Avoid linkage errors with captured local objects + self types
| * | | SI-9920 Avoid linkage errors with captured local objects + self typesJason Zaugg2016-09-272-2/+9
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An outer parameter of a nested class is typed with the self type of the enclosing class: ``` class C; trait T { _: C => def x = 42; class D { x } } ``` leads to: ``` class D extends Object { def <init>($outer: C): T.this.D = { D.super.<init>(); () }; D.this.$outer().$asInstanceOf[T]().x(); ``` Note that a cast is inserted before the call to `x`. If we modify that a little, to instead capture a local module: ``` class C; trait T { _: C => def y { object O; class D { O } } } ``` Scala 2.11 used to generate (after lambdalift): ``` class D$1 extends Object { def <init>($outer: C, O$module$1: runtime.VolatileObjectRef): C#D$1 = { D$1.super.<init>(); () }; D$1.this.$outer().O$1(O$module$1); ``` That isn't type correct, `D$1.this.$outer() : C` does not have a member `O$1`. However, the old trait encoding would rewrite this in mixin to: ``` T$class.O$1($outer, O$module$1); ``` Trait implementation methods also used to accept the self type: ``` trait T$class { final <stable> def O$1($this: C, O$module$1: runtime.VolatileObjectRef): T$O$2.type } ``` So the problem was hidden. This commit changes replaces manual typecheckin of the selection in LambdaLift with a use of the local (erasure) typer, which will add casts as needed. For `run/t9220.scala`, this changes the post LambdaLift AST as follows: ``` class C1$1 extends Object { def <init>($outer: C0, Local$module$1: runtime.VolatileObjectRef): T#C1$1 = { C1$1.super.<init>(); () }; - C1$1.this.$outer.Local$1(Local$module$1); + C1$1.this.$outer.$asInstanceOf[T]().Local$1(Local$module$1); <synthetic> <paramaccessor> <artifact> private[this] val $outer: C0 = _; <synthetic> <stable> <artifact> def $outer(): C0 = C1$1.this.$outer } ```
* | | Merge pull request #5412 from retronym/ticket/SD-226Adriaan Moors2016-09-281-1/+8
|\ \ \ | | | | | | | | | | | | | | | | Be lazier in Fields info transform for better performance Fix scala-dev#226
| * | | Make isSeparateCompiled... robust against rogue phase time travelJason Zaugg2016-09-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We don't hit this code path during bootstrapping, but we could conceivably hit it with macros or compiler plugins peering into the future through atPhase before refchecks as run. Also rename a method to reflect the generality of the info transform (it does more than mixin, now.)