summaryrefslogtreecommitdiff
path: root/src/compiler
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | | | | separation of concerns: eliding param-accessor fields in constructorsMiguel Garcia2013-08-081-115/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit modularizes TemplateTransformer by moving a few members from TemplateTransformer into the newly added OmittablesHelper. The members in question include - a few methods: # isParamCandidateForElision(Symbol) # isOuterCandidateForElision(Symbol) # mustbeKept(Symbol) - a few vals: # paramCandidatesForElision # outerCandidatesForElision # bodyOfOuterAccessor - class UsagesDetector That way, all trace of rewriting to elide param-accessor fields has vanished from TemplateTransformer and is encapsulated in OmittablesHelper.
| * | | | | | separation of concerns: delayed-init in constructorsMiguel Garcia2013-08-081-134/+137
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit modularizes TemplateTransformer by moving a few methods from TemplateTransformer into the newly added DelayedInitHelper. The methods in question - delayedInitCall() - delayedInitClosure() - delayedEndpointDef() build trees that rewriteDelayedInit() puts together. That way, all trace of rewriting related to delayed-init have vanished from TemplateTransformer and are encapsulated in DelayedInitHelper.
| * | | | | | method transformClassTemplate() turned into class TemplateTransformerMiguel Garcia2013-08-081-575/+579
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, each activation of transformClassTemplate() performed the rewriting that the constructors phase is well-known for. Lots of auxialiary objects were created in the process, with lifetime confined to said activation. The same auxiliary objects (having same lifetimes as before) also are in effect starting with this commit, but now it's an instance of TemplateTransformer that holds them together. In other words, there's a one-to-one correspondence between: - (what used to be) transformClassTemplate() activation - TemplateTransformer initialization After initialization, the result of TemplateTransformer can be found in its `transformed` member val. In fact, the refactoring to get here from the previous commit basically involves taking the body of method transformClassTemplate() as-is to become the template of TemplateTransformer. The TemplateTransformer in question will allow modularizing sub-transformations (e.g., DelayedInit) into dedicated traits (see upcoming commits).
| * | | | | | eliding what the constructor phase elides but with less effort (2 of 2)Miguel Garcia2013-08-081-63/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Removing the old implementation of elision in constructors in favor of the new one which is both faster, more readable.
| * | | | | | eliding what the constructor phase elides but with less effort (1 of 2)Miguel Garcia2013-08-081-2/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For now both old and new implementations of elision coexist, allowing cross-checking their results. In the next commit only the new one will remain.
| * | | | | | how stuff works: elision of param-accessor-fields and outer-accessorsMiguel Garcia2013-08-081-6/+64
| | | | | | |
| * | | | | | handling AnyVal special case early on to simplify logic afterwardsMiguel Garcia2013-08-081-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This way the contract of `transformClassTemplate()` can focus on non-AnyVal cases, which are more regular from the perspective of transforming their templates in the constructors phase.
| * | | | | | warn about uninitialized reads (in constructors), self-contained checkMiguel Garcia2013-08-081-37/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The check in question relies on helper maps and methods that don't belong outside that check. This commit encapsulates those helpers into the newly added `checkUninitializedReads()` , thus uncluttering `transformClassTemplate()`
* | | | | | | Merge pull request #2852 from retronym/ticket/1980-warningAdriaan Moors2013-08-211-0/+14
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | SI-1980 A lint warning for by-name parameters in right assoc methods
| * | | | | | | SI-1980 A lint warning for by-name parameters in right assoc methodsJason Zaugg2013-08-191-0/+14
| | |_|/ / / / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The desugaring of right associative calls happens in the parser. This eagerly evaluates the arguments (to preserve left-to-right evaluation order the arguments are evaluated before the qualifier). This is pretty surprising if the method being called has a by-name parameter in the first parameter section. This commit adds a warning under -Xlint when defining such a method. The relevent spec snippets: > SLS 4.6.1 says that call-by-name argument "is not evaluated at the point of function application, but instead is evaluated at each use within the function". > > But 6.12.3 offers: > "If op is right- associative, the same operation is interpreted as { val x=e1; e2.op(x ) }, where x is a fresh name."
* | | | | | | Merge pull request #2810 from xeno-by/topic/compile-time-onlyAdriaan Moors2013-08-211-0/+2
|\ \ \ \ \ \ \ | |_|_|/ / / / |/| | | | | | @compileTimeOnly: moved to scala-library.jar, got some fixes
| * | | | | | @compileTimeOnly now works for symbols from the empty packageEugene Burmako2013-08-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Looks like we've got the entire language covered now.
| * | | | | | @compileTimeOnly now works for annotationsEugene Burmako2013-08-151-0/+1
| | |/ / / / | |/| | | | | | | | | | | | | | | | | | | | | | http://docs.scala-lang.org/overviews/macros/annotations.html say sincere "thank you!".
* | | | | | Merge pull request #2824 from qerub/ticket/7740Adriaan Moors2013-08-201-0/+9
|\ \ \ \ \ \ | | | | | | | | | | | | | | SI-7740 Trim stack trace before printing in REPL
| * | | | | | SI-7740 Trim stack trace before printing in REPLChristoffer Sawicki2013-08-191-0/+9
| | | | | | |
* | | | | | | Merge branch 'master' into patmatPaul Phillips2013-08-2020-99/+84
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/compiler/scala/tools/nsc/Global.scala src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
| * | | | | | | No longer crash on NoSymbol.owner.Paul Phillips2013-08-1919-89/+55
| |/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Historically calling NoSymbol.owner has crashed the compiler. With this commit, NoSymbol owns itself. This is consistent with the way ownership chains are handled elsewhere in the compiler (e.g. NoContext.owner is NoContext, NoSymbol.enclClass is NoSymbol, and so on) and frees every call site which handles symbols from having to perform precondition tests against NoSymbol. Since calling NoSymbol.owner sometimes (not always) indicates a bug which we'd like to catch sooner than later, I have introduced a couple more methods for selected call sites. def owner: Symbol // NoSymbol.owner is self, log if -Xdev def safeOwner: Symbol // NoSymbol.owner is self, ignore def assertOwner: Symbol // NoSymbol.owner is fatal The idea is that everyone can call sym.owner without undue anxiety or paranoid null-like tests. When compiling under -Xdev calls to `owner` are logged with a stack trace, so any call sites for which that is an expected occurrence should call safeOwner instead to communicate the intention and stay out of the log. Conversely, any call site where crashing on the owner call was a desirable behavior can opt into calling assertOwner. This commit also includes all the safeOwner calls necessary to give us a silent log when compiling scala.
| * | | | | | Merge pull request #2840 from retronym/ticket/7756-2.11Adriaan Moors2013-08-191-8/+27
| |\ \ \ \ \ \ | | | | | | | | | | | | | | | | SI-7756 Uncripple refchecks in case bodies
| | * | | | | | SI-7756 Uncripple refchecks in case bodiesJason Zaugg2013-08-161-8/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 65340ed4ad2e, parts of RefChecks were disabled when we traversed into the results of the new pattern matcher. Similar logic existed for the old pattern matcher, but in that case the Match / CaseDef nodes still existed in the tree. The new approach was too broad: important checks no longer scrutinized the body of cases. This commit turns the checks back on when it finds the remnants of a case body, which appears as an application to a label def.
| * | | | | | | Merge pull request #2839 from densh/topic/si-7757Adriaan Moors2013-08-191-1/+1
| |\ \ \ \ \ \ \ | | |_|_|/ / / / | |/| | | | | | SI-7757 disallow constructor annotations on traits
| | * | | | | | SI-7757 disallow constructor annotations on traitsDen Shabalin2013-08-161-1/+1
| | |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously it was possible to define constructor annotations on traits with really weird side-effects (parser lost the body of the trait). Now constructor annotations on traits will cause appropriate syntax errors.
* | | | | | | Refinement of name-based unapplySeq.Paul Phillips2013-08-181-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Can't finnesse the drop method. Call it blindly for now, even though in the long run you won't have to write drop.
* | | | | | | An unapplySeq-via-String test.Paul Phillips2013-08-181-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are a lot of details yet to be ironed out when it comes to sequences, but at least here's a little evidence that the basic mechanisms work.
* | | | | | | Refined name-based patmat methods.Paul Phillips2013-08-184-77/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fleshes out some of the slightly unfinished corners of the adventure, especially for unapplySeq. There's still an unhealthy amount of duplication and a paucity of specification, but I think it's in eminently good shape for a milestone.
* | | | | | | Revert "Minor improvement in pattern typer inference."Paul Phillips2013-08-181-12/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 35122d6cda84bb2df69ca51c6b1b80e61693bf6f. It also includes a test case embodying the reversion reason: the test case no longer compiled. Parties interested in the surrounding details may want to look at SI-7472.
* | | | | | | Merge remote-tracking branch 'xeno-by/topic/patmat2' into patmat2Paul Phillips2013-08-172-0/+5
|\ \ \ \ \ \ \
| * | | | | | | SI-5903 extractor macrosEugene Burmako2013-08-182-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Establishes a pattern that can be used to implement extractor macros that give the programmer control over signatures of unapplications at compile-time. === The pattern === In a nutshell, given an unapply method (for simplicity, in this example the scrutinee is of a concrete type, but it's also possible to have the extractor be polymorphic, as demonstrated in the tests): ``` def unapply(x: SomeType) = ??? ``` One can write a macro that generates extraction signatures for unapply on per-call basis, using the target of the calls (c.prefix) and the type of the scrutinee (that comes with x), and then communicate these signatures to the typechecker. For example, here's how one can define a macro that simply passes the scrutinee back to the pattern match (for information on how to express signatures that involve multiple extractees, visit https://github.com/scala/scala/pull/2848). ``` def unapply(x: SomeType) = macro impl def impl(c: Context)(x: c.Tree) = { q""" new { class Match(x: SomeType) { def isEmpty = false def get = x } def unapply(x: SomeType) = new Match(x) }.unapply($x) """ } ``` In addition to the matcher, which implements domain-specific matching logic, there's quite a bit of boilerplate here, but every part of it looks necessary to arrange a non-frustrating dialogue with the typer. Maybe something better can be done in this department, but I can't see how, without introducing modifications to the typechecker. Even though the pattern uses structural types, somehow no reflective calls are being generated (as verified by -Xlog-reflective-calls and then by manual examination of the produced code). That's a mystery to me, but that's also good news, since that means that extractor macros aren't going to induce performance penalties. Almost. Unfortunately, I couldn't turn matchers into value classes because one can't declare value classes local. Nevertheless, I'm leaving a canary in place (neg/t5903e) that will let us know once this restriction is lifted. === Use cases === In particular, the pattern can be used to implement shapeshifting pattern matchers for string interpolators without resorting to dirty tricks. For example, quasiquote unapplications can be unhardcoded now: ``` def doTypedApply(tree: Tree, fun0: Tree, args: List[Tree], ...) = { ... fun.tpe match { case ExtractorType(unapply) if mode.inPatternMode => // this hardcode in Typers.scala is no longer necessary if (unapply == QuasiquoteClass_api_unapply) macroExpandUnapply(...) else doTypedUnapply(tree, fun0, fun, args, mode, pt) } } ``` Rough implementation strategy here would involve writing an extractor macro that destructures c.prefix, analyzes parts of StringContext and then generates an appropriate matcher as outlined above. === Implementation details === No modifications to core logic of typer or patmat are necessary, as we're just piggybacking on https://github.com/scala/scala/pull/2848. The only minor change I introduced is a guard against misbehaving extractor macros that don't conform to the pattern (e.g. expand into blocks or whatever else). Without the guard we'd crash with an NPE, with the guard we get a sane compilation error.
* | | | | | | | Finish segregating patmat cps hacks.Paul Phillips2013-08-173-30/+39
| | | | | | | |
* | | | | | | | Reworked MaybeTypedBound.Paul Phillips2013-08-174-121/+130
| | | | | | | |
* | | | | | | | Pull translatePattern entirely into BoundTree.Paul Phillips2013-08-171-102/+104
| | | | | | | |
* | | | | | | | Move more pattern logic into BoundTree.Paul Phillips2013-08-171-48/+75
| | | | | | | |
* | | | | | | | Introduced case class BoundTree.Paul Phillips2013-08-171-8/+10
|/ / / / / / / | | | | | | | | | | | | | | | | | | | | | The first step in improving the handling of (Symbol, Tree).
* | | | | | | Pattern matcher: extractors become name-based.Paul Phillips2013-08-179-433/+347
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An extractor is no longer required to return Option[T], and can instead return anything which directly contains methods with these signatures: def isEmpty: Boolean def get: T If the type of get contains methods with the names of product selectors (_1, _2, etc.) then the type and arity of the extraction is inferred from the type of get. If it does not contain _1, then it is a single value extractor analogous like Option[T]. This has significant benefits and opens new territory: - an AnyVal based Option-like class can be used which leverages null as None, and no allocations are necessary - for primitive types the benefit is squared (see below) - the performance difference between case classes and extractors should now be largely eliminated - this in turn allows us to recapture great swaths of memory which are currently squandered (e.g. every TypeRef has fields for pre and args, even though these are more than half the time NoPrefix and Nil) Here is a primitive example: final class OptInt(val x: Int) extends AnyVal { def get: Int = x def isEmpty = x == Int.MinValue // or whatever is appropriate } // This boxes TWICE: Int => Integer => Some(Integer) def unapply(x: Int): Option[Int] // This boxes NONCE def unapply(x: Int): OptInt As a multi-value example, after I contribute some methods to TypeRef: def isEmpty = false def get = this def _1 = pre def _2 = sym def _3 = args Then it's extractor becomes def unapply(x: TypeRef) = x Which, it need hardly be said, involves no allocations.
* | | | | | | Introduced classes to encapsulate extractor info.Paul Phillips2013-08-171-0/+123
| | | | | | | | | | | | | | | | | | | | | | | | | | | | To be put to use in a commit shortly to follow.
* | | | | | | Stylistic cleanups in patmat.Paul Phillips2013-08-175-40/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Should be behaviorally neutral.
* | | | | | | Simplify management of pattern vars.Paul Phillips2013-08-171-36/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Always set their info the same way, and when doing so always translate repeated types into sequence types.
* | | | | | | Cleanups in Typers.Paul Phillips2013-08-171-24/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Should be behaviorally neutral. A little more logging and a little better style.
* | | | | | | Add some logging to instantiateTypeVar.Paul Phillips2013-08-171-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This method is right at the center of ALL KINDS of bad. "this is quite nasty" begins the comment, and I credit its deadpan understatement. A little logging is the least we can offer the next guy.
* | | | | | | Expanded logic in formalTypes.Paul Phillips2013-08-171-8/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Made the super unusual move (for me) of making a method longer instead of shorter, because I had quite a time modifying the logic as it was. Ideally we wouldn't use this method because it is much less efficient than necessary. If one is typing a call like this: def f(xs: Int*) f(p1, p2, p3, ..., p500) Then it is not necessary to create a list with 500 IntTpes. Once you run out of non-varargs types, every argument which remains can be typed against the vararg type directly.
* | | | | | | SI-4425 do some validity checking on unapplies.Paul Phillips2013-08-172-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Filter out unapplies which can't be called (such as those with a second non-implicit parameter list) and report the error in a meaningful fashion.
* | | | | | | Move most of Typers#Typer#typedTyped into PatternTypers.Paul Phillips2013-08-172-54/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Again moving pattern-typing logic out of Typers. You can tell I like writing Typers#Typer#typedTyped.
* | | | | | | Turned TreeMaker into case class.Paul Phillips2013-08-171-9/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Type aliases are better than naked tuples, but only barely.
* | | | | | | Compressed central TreeMaker pattern match.Paul Phillips2013-08-171-79/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's easier to follow the logic when it can all be seen at once. I moved the specification excerpts down below for continued reference.
* | | | | | | Pulled pattern typing methods from Typers.Paul Phillips2013-08-172-274/+322
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To the extent possible this commit is purely the extraction of those methods into the newly created PatternTypers trait. The slicing and dicing of those methods will follow shortly.
* | | | | | | Broke up typed1's giant pattern match.Paul Phillips2013-08-171-45/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Another level of dispatch based on what trees on can expect to see during what mode. This should be beneficial for both performance (smaller methods, fewer type tests) and correctness (prevent trees from reaching inappropriate typing methods by construction rather than via ad hoc checks.) This work also revealed that UnApply trees never reach here, so I removed typedUnApply as dead code.
* | | | | | | Deduplicate mkZero in pattern matcher.Paul Phillips2013-08-171-19/+10
| | | | | | |
* | | | | | | Simplified the MaybeBoundTyped extractor a bit.Paul Phillips2013-08-171-6/+14
| | | | | | |
* | | | | | | Segreated CPS hacks in pattern matcher.Paul Phillips2013-08-171-21/+34
| | | | | | |
* | | | | | | Remedied glaring omission in error output.Paul Phillips2013-08-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Catching an assert and providing beautifully formatted contextual information is a questionable service if you forget to provide the error message from the assert.
* | | | | | | An Unapplied extractor.Paul Phillips2013-08-171-15/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes it a lot less error prone and redundant to find the part you need when unwrapping an UnApply tree.