summaryrefslogtreecommitdiff
path: root/src/compiler
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #5482 from lrytz/sd248-frontendLukas Rytz2016-10-282-136/+135
|\ | | | | Frontend fixes for scala-dev#248
| * Address review commentsLukas Rytz2016-10-282-34/+34
| | | | | | | | | | | | | | | | Tighten some types (Symbol -> ClassSymbol / ModuleSymbol), use NonFatal instead of catching Throwable. Also don't run the classfile parser enteringPhase(phaseBeforeRefchecks) anymore. This was added in 0ccdb15 but seems no longer required.
| * For scala classfiles, only parse the scala signature annotationLukas Rytz2016-10-281-24/+45
| | | | | | | | | | | | Skipping other annotations not only saves some cycles / GC, but also prevents some spurious warnings / errors related to cyclic dependencies when parsing annotation arguments refering to members of the class.
| * Minor style cleanups, no changes in logicLukas Rytz2016-10-271-4/+4
| |
| * Classfile parser and unpickler require class and module symbol argumentsLukas Rytz2016-10-272-30/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In SymbolLoaders, when seeing a classfile `Foo.class`, we always (unconditionally) create 3 symbols: a class, a module and a module class. Some symbols get invalidated later (`.exists`). Until now, the classfile parser (and unpickler) received the "root" symbol as argument, which is the symbol whose type is being completed. This is either the class symbol or the module symbol. The classfile parser would then try to lookup the other symbol through `root.companionClass` or `root.companionModule`. Howver, this lookup can fail. One example is scala-dev#248: when a type alias (in a package object) shadows a class symbol, `companionClass` will fail. The implementations of the classfile parser / unpickler assume that both the `clazz` and the `staticModule` symbols are available. This change makes sure that they are always passed in explicitly. Before this patch, in the example of scala-dev#248, the `classRoot` of the unpickler was NoSymbol. This caused a bug when unpickling the module class symbol, causing a second module class symbol to be created mistakingly. The next commit cleans up this logic, more details there. This second symbol would then cause the crash in the backend because it doesn't have an `associatedFile`, therefore `isCoDefinedWith` would spuriously return `true`.
| * Clean up cross-check in classfile parser, remove unnecessary assignmentLukas Rytz2016-10-271-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | One of the first entries in the classfile is the class name. The classfile parser performs a cross-check by looking up the class sybmol corresponding to that name and ensures it's the same as `clazz`, the class symbol that the parser currently populates. Since 322c980 ("Another massive IDE checkin"), if at the time of the check `clazz` but the lookup returns some class, the `clazz` field is assigned. The commit following this one makes sure `clazz` is never NoSymbol, so the assignment can safely be removed.
| * Clean up lookup class by name in the classfile parserLukas Rytz2016-10-271-46/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There was a piece of logic essentially duplicating getClassByName in Mirrors (split up a fully qualified class name by ".", look up pieces). That piece of code was added in 0ce0ad5 to fix one example in SI-2464. However, since 020053c (2012, 2.10) that code was broken: the line ss = name.subName(0, start) should be ss = name.subName(start, name.length).toTypeName As a result, the code would always create a stub symbol. Returning a stub seems to be the right thing to do anyway, and the fact that we were doing so during two major releases is a good proof.
* | Merge pull request #5276 from som-snytt/issue/9750Seth Tisue2016-10-261-27/+17
|\ \ | |/ |/| SI-9750 scala.util.Properties.isJavaAtLeast works with JDK9
| * SI-9750 Remove isJavaAtLeast from util.StackTracingSom Snytt2016-07-291-27/+17
| | | | | | | | | | Formatting suppressed exceptions required reflection for platform compatibility. No longer, since Java 8 is assumed. Minor tidying.
* | assorted typo fixes, cleanup, updating of commentsSeth Tisue2016-10-244-9/+9
| | | | | | | | | | | | 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.
* | SI-9516 remove now-unneeded codeSeth Tisue2016-10-241-3/+3
| | | | | | | | now that STARR includes the relevant fix
* | Merge pull request #5466 from dragos/issue/remove-println-SI-8717Lukas Rytz2016-10-211-4/+4
|\ \ | | | | | | Replace println with log calls in BrowsingLoaders
| * | Replace println with log calls in BrowsingLoadersIulian Dragos2016-10-191-4/+4
| | | | | | | | | | | | | | | | | | | | | This alternative symbol loader is used in the presentation compiler and may generate output even when the compiler should be silent. See SI-8717 for more context, even though this does not really fix the ticket.
* | | Merge pull request #5393 from som-snytt/issue/nowarn-thistype-discardLukas Rytz2016-10-213-16/+10
|\ \ \ | | | | | | | | No warn when discarding r.f(): r.type
| * | | No warn when discarding r.f(): r.typeSom Snytt2016-09-103-16/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The paradigm is `def add(x: X): Unit = listBuffer += x`. The value that is discarded is not new information. Also cleans up the recent tweaks to help messaging. Adds newlines in case they ask for multiple helps.
* | | | Merge pull request #5439 from som-snytt/issue/fields-fieldwidthSeth Tisue2016-10-201-7/+7
|\ \ \ \ | | | | | | | | | | Shorten fields phase description
| * | | | Don't clip descrip when -YdebugSom Snytt2016-09-301-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -Ydebug is supposed to show everything about the phases, including full description (if otherwise clipped) and any phases that are not "enabled" by options.
| * | | | Shorten fields phase descriptionSom Snytt2016-09-301-1/+1
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Makes fields fit the field width, which is fitting. `s/including/add` seems sufficient. Possibly, "synthesize" is an extravagance for "add", but "add" is used previously in that column. Resolve, load, translate, add, synthesize, replace, erase, move, eliminate, remove, generate. Would love to learn a word that says what typer does, if the word "type" is too redundant or overloaded, besides the food metaphor. Also "meat-and-potatoes" implies basic, simple, not fussy or fancy. There are many devices, like the heart or a Ferrari engine, that are fundamental without being unfussy.
* | | | Merge 2.11.x into 2.12.xAdriaan Moors2016-10-181-5/+13
|\ \ \ \ | |_|/ / |/| | | | | | | | | | | | | | | | | | | | | | | Fix conflict in #5453: ``` - def help: String = { + override def help: String = { ```
| * | | Merge pull request #5453 from som-snytt/issue/9832-2.11Adriaan Moors2016-10-181-5/+13
| |\ \ \ | | | | | | | | | | SI-9832 -Xlint:help shows default
| | * | | SI-9832 -Xlint:help shows defaultSom Snytt2016-10-111-5/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conclude help method with the default list. Extra words are supplied for underscore.
| * | | | Merge pull request #5345 from milessabin/topic/si-7046-backportAdriaan Moors2016-10-184-11/+48
| |\ \ \ \ | | | | | | | | | | | | [nomerge] Partial fix for SI-7046
| | * | | | Partial fix for SI-7046Miles Sabin2016-08-154-11/+48
| | |/ / /
| * | | | Merge pull request #5341 from milessabin/topci/si-9760-backportAdriaan Moors2016-10-181-1/+0
| |\ \ \ \ | | | | | | | | | | | | SI-9760 Fix for higher-kinded GADT refinement
| | * | | | SI-9760 Fix for higher-kinded GADT refinementMiles Sabin2016-08-151-1/+0
| | |/ / /
| * | | | Merge pull request #5218 from retronym/ticket/9806Jason Zaugg2016-10-181-2/+2
| |\ \ \ \ | | |/ / / | |/| | | SI-9806 Fix incorrect codegen with optimizer, constants, try/catch
| | * | | SI-9806 Fix incorrect codegen with optimizer, constants, try/catchJason Zaugg2016-06-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The constant optimizer phase performs abstract interpretation of the icode representation of the progam in order to eliminate dead code. For each basic block, the possible and impossible states of each local variable is computed for both a normal and an exceptional exit. A bug in this code incorrectly tracked state for exception exits. This appears to have been an oversight: the new state was computed at each instruction, but it was discarded rather than folded through the intepreter.
* | | | | 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-113-8/+9
|\ \ \ \ \ | | | | | | | | | | | | Default -Xmixin-force-forwarders to true
| * | | | | Default -Xmixin-force-forwarders to trueLukas Rytz2016-09-302-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | | | | Error message for super calls to indirect java parent interfacesLukas Rytz2016-09-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Super calls to indirect java parent interfaces cannot be emitted, an error message is emitted during SuperAccessors. The error message was missing if the super call was non-qualified, resulting in an assertion failure in the backend.
* | | | | | Merge pull request #5452 from lrytz/sd242Adriaan Moors2016-10-101-2/+1
|\ \ \ \ \ \ | | | | | | | | | | | | | | Fix the interface flag when re-writing a closure call to the body method
| * | | | | | Fix the interface flag when re-writing a closure call to the body methodLukas Rytz2016-10-091-2/+1
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When re-writing a closure invocation to the body method, the `itf` flag of the invocation instruction was incorrect: it needs to be true if the method is defined in an interface (including static methdos), not if the method is invoked through `INVOKEINTERFACE`. JDK 8 doesn't flag this inconsistency and executes the bytecode, but the verifier in JDK 9 throws an `IncompatibleClassChangeError`. Similar fixes went into e619b03.
* | | | | | 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-282-1/+19
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Be lazier in Fields info transform for better performance Fix scala-dev#226
| * | | | | | Make isSeparateCompiled... robust against rogue phase time travelJason Zaugg2016-09-272-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.)
| * | | | | | SD-226 Be lazier in Fields info transform for better performanceJason Zaugg2016-09-212-1/+13
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Only mixin fields + accessors into class infos of classes that are either in the current run, or appear in a superclass chain of a class in the current run. This is analagous to what happens in the mixin phase.
* | | | | | Merge pull request #5388 from adriaanm/issue-219Adriaan Moors2016-09-281-42/+66
|\ \ \ \ \ \ | | | | | | | | | | | | | | Avoid mismatched symbols in fields phase
| * | | | | | Cast more pro-actively in synthetic accessor trees.Adriaan Moors2016-09-261-51/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Also narrow scope of afterOwnPhase.
| * | | | | | Avoid mismatched symbols in fields phaseAdriaan Moors2016-09-261-2/+15
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The info of the var that stores a trait's lazy val's computed value is expressed in terms of symbols that exist before the fields phase. When we're implementing the lazy val in a subclass of that trait, we now see symbols created by the fields phase, which results in mismatches between the types of the lhs and rhs in the assignment of `lazyVar = super.lazyImpl`. So, type check the super-call to the trait's lazy accessor before our own phase. If the lazy var's info depends on a val that is now implemented by an accessor synthesize by our info transformer, we'll get a mismatch when assigning `rhs` to `lazyVarOf(getter)`, unless we also run before our own phase (like when we were creating the info for the lazy var). This was revealed by Hanns Holger Rutz's efforts in compiling scala-refactoring's test suite (reported on scala-internals). Fixes scala/scala-dev#219
* | | | | | Merge pull request #5417 from retronym/ticket/SD-233Jason Zaugg2016-09-271-1/+3
|\ \ \ \ \ \ | | | | | | | | | | | | | | SD-233 synchronized blocks are JIT-friendly again