| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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”
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
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".
|
|
|
|
|
|
|
|
|
| |
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.
|
|\
| |
| | |
Diminished Tuple Confusion
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- 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)
|
|\
| |
| | |
SI-7872 Plug a variance exploit in refinement types
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
|\ \
| | |
| | | |
SI-8001 spurious "pure expression does nothing" warning
|
| |/
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
`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!
|
|\ \
| | |
| | | |
Unifying -Ydelambdafy:{inline, method}
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
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`.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
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.
|
| |/
| |
| |
| |
| |
| |
| |
| |
| | |
- 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.
|
|\ \
| | |
| | | |
more precise isMacroApplication check
|
| | |
| | |
| | |
| | |
| | | |
Replaces the `symbol.isMacro` check with `symbol.isTermMacro`.
Doesn’t make any difference to trunk but helps a lot with macro annotations.
|
|\ \ \
| | | |
| | | | |
Refactor out fresh name prefix extraction logic
|
| | | | |
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
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
|
| |_|/
|/| |
| | |
| | |
| | | |
Code which has been deprecated since 2.10.0 and which allowed
for straightforward removal.
|
|/ /
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
|\ \
| | |
| | | |
[rebase] blackbox and whitebox macros
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
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.
|
| |/
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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/...
|
| | |
|
| | |
|
| |
| |
| |
| |
| |
| | |
1. q"for (..$enums) $body", q"for (..$enums) yield $body"
2. fq"..." quote to construct/deconstruct enumerators
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| | |
|
| | |
|
| |
| |
| |
| |
| |
| | |
Encode values into real trees rather than non-tree case classes.
This is needed for re-usability of desugaring code between quasiquotes
and parser.
|
| |
| |
| |
| |
| |
| |
| | |
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.
|
| |
| |
| |
| |
| |
| | |
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.
|
| | |
|
| |
| |
| |
| |
| |
| |
| | |
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)
|
|/
|
|
|
|
| |
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.
|
|\
| |
| | |
Paulper stack reduction
|
| |
| |
| |
| |
| | |
One fewer Int to be whizzing around the parser hoping to
be confused with other Ints.
|
| |
| |
| |
| |
| | |
- anonymize unused pattern binder
- avoid negations
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|\
| |
| | |
Delay delambdafication and put the lambda's body into the containing class
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|