summaryrefslogtreecommitdiff
path: root/src/reflect
Commit message (Collapse)AuthorAgeFilesLines
* SI-7789 make quasiquotes deconstruct UnApply treesDen Shabalin2013-12-101-3/+5
|
* Introduce support for Unliftable for QuasiquotesDen Shabalin2013-12-106-0/+132
| | | | | | | | | | | | | | Unliftable is a type class similar to existing Liftable that lets users to extract custom data types out of trees with the help of straightforward type ascription syntax: val q“foo.bar(${baz: Baz})” = ... This will use Unliftable[Baz] to extract custom data type Baz out of a tree nested inside of the another tree. A simpler example would be extracting of constant values: val q”${x: Int} + ${y: Int}” = q”1 + 2”
* Provide a way for unapply macro to obtain a list of subpattensDen Shabalin2013-12-102-0/+4
| | | | | | | | | | | | | | | | | | This commit introduces internal attachment that allows unapply macros to be aware of their sub patterns and tweak their expansion depending on that info. At the moment this is not possible due to the way pattern macros are expanded: case MacroPat(inner1, inner2) => ... During type checking this will expand as MacroPat.unapply(<unapply-dummy>) Meaning that macro can’t see inner1 and inner2 in it’s macroApplication. To circumvent this we attach that info as an attachment to the dummy.
* Move Liftable into the Universe cake; add additional standard LiftablesDen Shabalin2013-12-106-58/+139
| | | | | | | | | | | | Previously we believed that having Liftable outside of the Universe will bring some advantages but it turned out this wasn’t worth it. Due to infectious nature of path dependent types inside of the universe one had to cast a lot. A nice example of what I’m talking about is a change in trait ArbitraryTreesAndNames. Additionally a number of standard Liftables is added for types that are available through Predef and/or default scala._ import: Array, Vector, List, Map, Set, Option, Either, TupleN.
* SI-7979 Fix quasiquotes crash on mismatch between fields and constructorDen Shabalin2013-12-101-4/+8
|
* SI-6842 Make splicing less sensitive to precise types of treesDen Shabalin2013-12-103-34/+79
| | | | | | | | | Previously trees that represent parameters, case clauses and type variables had strictly defined ValDef, TypeDef and CaseDef types which caused problems in compositionality. Now this checks are moved to runtime so it's possible to pass a tree that is CaseDef but has Tree type.
* SI-8009 Ensure that Idents preserve isBackquoted propertyDen Shabalin2013-12-103-2/+18
|
* SI-8008 Make q”f(..$xs)” only match trees with Apply nodeDen Shabalin2013-12-103-17/+0
| | | | | | | | | | Previously it also matched other nodes but returned Nil as value of xs. This behavior was added for sake of consistentcy with q”f[..$ts]”. On the other hand q”f[..$Nil]” == q”f” but q”f(..$Nil)” == q”f()” not q”f”. Due to this deconstruction/construction symmetry was broken. On the other hand applications also have q"f(...$xss)" option which is infact similar to q"f[..$ts]". Splicing Nil into it also results in q"f".
* undeprecates c.parseEugene Burmako2013-12-061-3/+0
| | | | | | | | | We never thought that c.parse is going to be completely subsumed by quasiquotes, but hoped that the use cases that are going to be lost aren’t going to be noticed by anyone. Unfortunately, this isn’t the case, so I’m undeprecating c.parse until we get a better story for those for whom quasiquotes are not enough.
* Merge pull request #3202 from retronym/topic/function1-tuplenAdriaan Moors2013-12-031-0/+5
|\ | | | | Diminished Tuple Confusion
| * Better error messages for common Function/Tuple mistakesJason Zaugg2013-12-011-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Firstly, for `((a, b) => c): (Tuple2[A, B] => C)`, we currently just offer "missing parameter type." Is something of a rite of passage to know that you need `{ case (...)}` This commit stops short DWIM, but does offer a diagnostic to guide the user towards the supported way of destructuring a `Tuple` in the sole argument of a `Function1`. Secondly, another (less common?) way one might try to write a function to destructure a single tuple argument is: (((a, b)) => c) The parser now matches offers a specific error message for this, and points out the alternatives. In both cases, we avoid offering syntactically invalid alternatives, by detecting names that aren't valid as variable-patterns, and falling back to generic "paramN" in the error message. A handly utility function to sequence a list of options is liberated from the pattern matcher for broader use.
* | SI-8023 Address review comments around typedHigherKindedTypeJason Zaugg2013-12-031-0/+2
|/ | | | | | | | | | | | | | | - Make `WildCardType` kind polymorphic - Factory methods for expected kinds. They are still just `Type`-s, though. - Check if the type parameter is initialized, rather than its owner. - Take advantage of these to cleanup `typedAppliedTypeTree` TODO: is this comment totally accurate? If so, should we refactor `Kind.FromParams(tparams)` to `Kind.Arity(tparams.length)`? // @M: kind-arity checking is done here and in adapt, // full kind-checking is in checkKindBounds (in Infer)
* Merge pull request #3178 from retronym/ticket/7872Adriaan Moors2013-11-251-0/+10
|\ | | | | SI-7872 Plug a variance exploit in refinement types
| * SI-7872 Plug a variance exploit in refinement typesJason Zaugg2013-11-231-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refinement types are collapsed to a TypeTree with an original during type checking; this was enough to evade variance validation in refchecks. This commit: - validates the original of `TypeTree`s in refchecks - changes VarianceValidator to recurse into: - the originals of `TypeTree`s - `TypTree` (to cover, e.g. `CompoundTypeTree` / `SelectFromTypeTree`) It also finds an unreported variance violation in an existing test case, variances.scala. This looks to be legitimate.
* | Merge pull request #3183 from xeno-by/topic/pure-expression-does-nothingAdriaan Moors2013-11-251-1/+2
|\ \ | | | | | | SI-8001 spurious "pure expression does nothing" warning
| * | SI-8001 spurious "pure expression does nothing" warningEugene Burmako2013-11-231-1/+2
| |/ | | | | | | | | | | | | | | | | | | | | `isPureExprForWarningPurposes` doesn’t warn on `()`, but `(): Unit` leaves it confused. This patch fixes the problem. The fix is important in the context of the recent split between blackbox and whitebox macros. Macro engines wrap expansions of blackbox macros in type ascriptions, so a macro that expands into `()` would actually produce `(): Unit`, which would trigger a spurious warning. Thanks @milessabin for spotting this problem!
* | Merge pull request #3165 from retronym/ticket/uncurry-tidy-2Adriaan Moors2013-11-252-1/+13
|\ \ | | | | | | Unifying -Ydelambdafy:{inline, method}
| * | Special treatment for local symbols in TypeTreeMemberTypeJason Zaugg2013-11-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Avoids calling `thisType` on the owner if it is a term symbol, which doesn't make much sense. This method is used internally in tree factory methods that create, e.g, a `DefDef` based on the info of a `Symbol`.
| * | Symbol substutition must consider ClassInfoType#parentsJason Zaugg2013-11-231-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An upcoming change to uncurry, in which I plan to make substitution of `lambda params -> apply method params` requires that I first to fix a problem in symbol substition. This situation can arise when the body of this definition: def owner1(a: A) = { class C extends M[a.B] } is transplanted into a new owner that has a different symbol for `a`. I speculated that value classes might also be prone to the fact that symbol substitution neglected `ClassInfoType#parents`. We can test change with Value Classes: Partial Functions that are dependent on value class param type used to fail with a spurious overriding error, now they work correctly.
| * | Tidy up the Uncurry component of delambdafyJason Zaugg2013-11-171-0/+6
| |/ | | | | | | | | | | | | | | | | - Use tree factories that accept symbols and encapsulate ValDef creation - Use `gen.mkForwarder` to handle the conditional addition of `: _*` for varargs functions. We don't need to predicate this on `etaExpandKeepsStar`; the only place that need to do that is EtaExpansion.
* | Merge pull request #3134 from xeno-by/topic/is-term-macroJason Zaugg2013-11-221-1/+1
|\ \ | | | | | | more precise isMacroApplication check
| * | more precise isMacroApplication checkEugene Burmako2013-11-131-1/+1
| | | | | | | | | | | | | | | Replaces the `symbol.isMacro` check with `symbol.isTermMacro`. Doesn’t make any difference to trunk but helps a lot with macro annotations.
* | | Merge pull request #3138 from densh/pr/fresh-name-extractorJason Zaugg2013-11-224-8/+41
|\ \ \ | | | | | | | | Refactor out fresh name prefix extraction logic
| * | | use more specific cake dependenciesDen Shabalin2013-11-201-1/+1
| | | |
| * | | refactor out fresh name prefix extraction logicDen Shabalin2013-11-174-8/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. refactor out FreshNameExtractor out of Quasiquotes cake into SymbolTable (can’t put it outside due to the fact that names are path-dependent) 2. add optional parameter to the fresh name creator to cover additional qq$ prefix needed for quasiquotes 3. add unit tests
* | | | Removing deprecated code.Paul Phillips2013-11-184-49/+5
| |_|/ |/| | | | | | | | | | | Code which has been deprecated since 2.10.0 and which allowed for straightforward removal.
* | | Revert "temporarily disables run/reflection-sync-subtypes"Jason Zaugg2013-11-141-2/+9
|/ / | | | | | | | | | | | | | | | | This reverts commit 04e2dbb29830d0e511cdfa8c132a9fad91d657ed, by avoiding the ill-fated attempt to short-circuit the global reflection lock. I think we can do better performance wise, but lets at least get something correct to start with.
* | Merge pull request #3129 from adriaanm/pr-rebase-3001Adriaan Moors2013-11-1323-109/+243
|\ \ | | | | | | [rebase] blackbox and whitebox macros
| * | blackbox restriction #3: can't affect implicit searchEugene Burmako2013-11-123-33/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | When an application of a blackbox macro is used as an implicit candidate, no expansion is performed until the macro is selected as the result of the implicit search. This makes it impossible to dynamically calculate availability of implicit macros.
| * | blackbox and whitebox macrosEugene Burmako2013-11-1223-76/+210
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the first commit in the series. This commit only: 1) Splits Context into BlackboxContext and WhiteboxContext 2) Splits Macro into BlackboxMacro and WhiteboxMacro 3) Introduces the isBundle property in the macro impl binding Here we just teach the compiler that macros can now be blackbox and whitebox, without actually imposing any restrictions on blackbox macros. These restrictions will come in subsequent commits. For description and documentation of the blackbox/whitebox separation see the official macro guide at the scaladoc website: http://docs.scala-lang.org/overviews/macros/blackbox-whitebox.html Some infrastructure work to make evolving macros easier: compile partest-extras with quick so they can use latest library/reflect/...
* | add comments that explain new for loop enumerator encodingDen Shabalin2013-11-121-0/+28
| |
* | re-implement hasAttachment directly in raw attachmentsDen Shabalin2013-11-122-1/+5
| |
* | add support for for loops and for enumerators to quasiquotesDen Shabalin2013-11-122-1/+8
| | | | | | | | | | | | 1. q"for (..$enums) $body", q"for (..$enums) yield $body" 2. fq"..." quote to construct/deconstruct enumerators
* | implement inverse transformation to mkForDen Shabalin2013-11-123-9/+166
| | | | | | | | | | | | | | | | | | | | | | This effectively reconstructs a sequence of enumerators and body from the tree produced by mkFor. This lets to define bi-directional SyntacticFor and SyntacticForYield constructors/extractors to work with for loops. Correctness of the transformation is tested by a scalacheck test that generates a sequence of random enumerators, sugars them into maps/flatMaps/foreach/withFilter calls and reconstructs them back.
* | add syntactic combinators that represent enumeratorsDen Shabalin2013-11-122-0/+95
| |
* | move for loop desugaring into tree genDen Shabalin2013-11-121-0/+369
| |
* | change intermidiate representation of for loop enumeratorsDen Shabalin2013-11-124-7/+22
| | | | | | | | | | | | Encode values into real trees rather than non-tree case classes. This is needed for re-usability of desugaring code between quasiquotes and parser.
* | add support for importable attachmentsDen Shabalin2013-11-123-5/+19
| | | | | | | | | | | | | | Previously attachments weren't imported by importTree. Now a new marker trait has been added that lets attachments to import themselves to the new universe together with all their innards. Additionally a simpler subtrait is defined to mark attachments that can be imported as-is.
* | add some post-typecheck tests for quasiquotesDen Shabalin2013-11-121-5/+25
| | | | | | | | | | | | Typecheck trees with toolbox and check that they are still matched by corresponding quasiquote. Fix tuples and function types matchers to account for different shape of trees after typing.
* | add hasAttachment utility method to the internal apiDen Shabalin2013-11-122-1/+2
| |
* | make internal implementation of universe.build less restrictiveDen Shabalin2013-11-121-26/+16
| | | | | | | | | | | | | | 1. Use protected instead of private to avoid needless lock-in 2. Use BuildImpl field type to expose non-protected members to the compiler (user-facing side in the reflection api stays the same)
* | deduplicate tuple tree creation codeDen Shabalin2013-11-122-15/+23
|/ | | | | | Previously tuple tree generation code has been implemented in three place: tree builder, tree gen, build utils. Now it's just defined once in tree gen.
* Merge pull request #3100 from som-snytt/paulp/reductionJason Zaugg2013-11-081-0/+38
|\ | | | | Paulper stack reduction
| * A value class for Precedence.Paul Phillips2013-11-081-0/+38
| | | | | | | | | | One fewer Int to be whizzing around the parser hoping to be confused with other Ints.
* | Address review commentsJason Zaugg2013-11-081-1/+1
| | | | | | | | | | - anonymize unused pattern binder - avoid negations
* | Avoid needless TypeRef allocation during erasure.Jason Zaugg2013-11-082-12/+18
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - ThisType(some.package) need not be erased, we can let that prefix through unchanged and avoid churning through allocations. - Sharpen the condition in `rebindInnerClass`. The answer to the deleted comment in the code, is "anonymous and local classes", which are specifically excluded in the new formulation. - Finally, detect if erasure of the TypeRef is an identity and reuse the original. Waste not, want not. To expand on the first point, here is what used to happen during erasure: scala> val scalaPack = typeOf[Predef.type].prefix scalaPack: $r.intp.global.Type = scala.type scala> typeDeconstruct.show(scalaPack) res19: String = ThisType(package scala) scala> typeDeconstruct.show(erasure.scalaErasure(scalaPack)) res20: String = TypeRef(TypeSymbol(final class scala extends )) Showing one step of the erasure type map: scala> typeDeconstruct.show(scalaPack.asInstanceOf[SubType].underlying.typeOfThis) res21: String = SingleType(pre = ThisType(package <root>), package scala)
* SI-7678 Don't cache member symbols of TypeTags in Definitions.Jason Zaugg2013-11-084-105/+116
| | | | | | | | | | | | | | | | | | | | | | | It we can only safely use vals in Definitions for top-level symbols. Otherwise, when the IDE switches to loading the symbol from source, we can hold on to a stale symbol, which in turn impedes implicit materialization of TypeTags. This commit moves (most) of the accessors for member symbols into RunDefinitions, and changes calling code accordingly. This is a win for presentation compiler correctness, and might even shave of a few cycles. In a few cases, I have had to leave a `def` to a member symbol in Definitions so we can get to it from the SymbolTable cake, which doesn't see RunDefinitions. The macro FastTrack facility now correctly recreates the mapping from Symbol to macro implementation each run, using a new facility in perRunCaches to create a run-indexed cache. The enclosed test recreates the situation reported in the ticket, in which TypeTags.scala is loaded from source.
* Add a per-run cache for member symbolsJason Zaugg2013-11-082-8/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We are all used to calls to `definitions.PredefModule`, or `defintions.Predef_???` to grab the symbol of some well known entity. But you'll notice that some of these are lazy vals, and others are defs. Why is this so? In the presentation compiler, a member like `Predef.???` will be assigned a new symbol after the user browses into `Predef.scala`. Mistakenly using vals in definitions leads to subtle IDE bugs like SI-7678. We are able to trigger these situations in tests, as noted in the comments of that issue. Changing the vals to defs, on the other hand, has a performance penalty. Some schemes to workaround this have shown up: cache them per-implicit search, or compare method names and owners rather than symbols on hot paths in the type checker. This commit introduces a facility to cache these sort of symbols per-run, and uses it to check for `Predef.conforms` and and for the class/type tag materializers. A followup pull request (WIP: https://github.com/retronym/scala/compare/ticket/7678-2) will expand the use of to address the widespread and unsafe caching of member symbols that I found while investigating SI-7678.
* Merge pull request #3081 from JamesIry/wip_delayed_delambdafy_cleanupAdriaan Moors2013-11-074-4/+26
|\ | | | | Delay delambdafication and put the lambda's body into the containing class
| * Flesh out the Delambdafy phase.James Iry2013-11-062-1/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit puts a real body on the Delambdafy phase. From a lambda, Delambdafy will create 1) a static forwarder at the top level of the class that contained the lambda 2) a new top level class that a) has fields and a constructor taking the captured environment (including possbily the "this" reference) b) an apply method that calls the static forwarder c) if needed a bridge method for the apply method 3) an instantiation of the newly created class which replaces the lambda Trees.scala is modified to add two more convenient factories for templates and classdefs. A few basic tests are included to verify that it works as expected. Further commits will have additional tests.