| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
| |
| |
| |
| |
| |
| |
| | |
Jason points out the recursion will be okay if
type checking the function inside the eta-expansion provides
fully determined argument types, as the result type is
not relevant for this phase of typedFunction.
|
| |
| |
| |
| |
| |
| | |
When recovering missing argument types for an
eta-expanded method value, rework the expected type
to a method type.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The body of `def delay[T](v: => T) = (v _): F0[T]`
becomes `() => v` during `typedEta`, and then uncurry
considers whether to strip the function wrapper since
`v` is known to be a `Function0` thunk. Stripping is sound
when the expected type is `Function0` for this expression,
but that's no longer a given, since we could be expecting any
nullary SAM.
Also sweep up a bit around `typedEta`.
Encapsulate the, erm, creative encoding of
`m _` as `Typed(m, Function(Nil, EmptyTree))`.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Also, drop AbstractFunction for parent of anonymous subclass of
function type that must have its class spun up at compile time
(rather than at linkage time by LambdaMetaFactory).
This revealed an old problem with typedTemplate, in which
parent types may be normalized at the level of trees,
while this change does not get propagated to the class's info
in time for the constructor to be located when we type check
the primary constructor.
|
| |
| |
| |
| | |
For completeness, `-Xsource:2.11 -Xexperimental` does enable it.
|
| |
| |
| |
| |
| |
| |
| |
| | |
Trying to figure out if we can avoid adapting to SAM, and just
type them once and for all in typedFunction. Looks like overload
resolution requires SAM adaptation to happen in adapt.
Cleaned up while I was in the area.
|
| |
| |
| |
| |
| |
| |
| |
| | |
This reflects the majority vote on the PR.
DSLs that need their implicit conversions to kick in instead of
SAM conversion, will have to make their target types not be SAM
types (e.g., by adding a second abstract method to them).
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
We cannot use the expected type to track whether a Function node
targets a SAM type, as the expected type may be erased (see test
for an example).
Thus, the type checker attaches a SAMFunction attachment to a
Function node when SAM conversion is performed in adapt. Ideally,
we'd move to Dotty's Closure AST, but that will need a
deprecation cycle.
Thanks to Jason for catching my mistake, suggesting the fix and
providing the test.
Both the sam method symbol and sam target type must be tracked,
as their relationship can be complicated (due to inheritance).
For example, the sam method could be defined in a superclass (T)
of the Function's target type (U).
```
trait T { def foo(a: Any): Any }
trait U extends T { def apply = ??? }
(((x: Any) => x) : U).foo("")
```
This removes some of the duplication in deriving the sam method
from the expected type, but some grossness (see TODO) remains.
|
| |
| |
| |
| |
| |
| | |
Do not report second error. Go straight to the exit.
Based on review by Jason.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
- Re-simplify logging;
- Remove unused method valueTypeToObject;
- Limit ThisReferringMethodTraverser to material parts
of the AST
Limit ThisReferringMethodTraverser's analysis to only look at
template-owned anonfun method bodies, to make sure it's fairly
low overhead.
AFAICT, part of the complexity of this analysis stems from the
desire to make all the lambda impl methods static in
`() => () => 42`: https://gist.github.com/062181846c13e65490cc.
It would possible to accumulate the knowledge we need during the
main transform, rather than in an additional pass. We'd need to
transform template bodies in such a way that we we process
definitions of anonfun methods before usages, which would
currently amount to transforming the stats in reverse.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Crucially, the fully-defined expected type must be checked for
conformance to the original expected type!!
The logic in adaptToSam that checks whether pt is fully defined
probably needs some more thought. See pos/t8310 for a good test
case. Argument type checking is a challenge, as we first check
against a lenient pt (this lenient expected type has wildcards,
and thus is not fully defined, but we should still consider sam
adaptation a success even if we end up with wildcards for some
unknown type parameters, they should be determined later).
|
| | |
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
They both compile to INDY/MetaLambdaFactory, except when they
occur in a constructor call. (TODO: can we lift the ctor arg
expression to a method and avoid statically synthesizing
anonymous subclass altogether?)
Typers:
- no longer synthesize SAMs -- *adapt* a Function literal
to the expected (SAM/FunctionN) type
- Deal with polymorphic/existential sams (relevant tests:
pos/t8310, pos/t5099.scala, pos/t4869.scala) We know where
to find the result type, as all Function nodes have a
FunctionN-shaped type during erasure. (Including function
literals targeting a SAM type -- the sam type is tracked as
the *expected* type.)
Lift restriction on sam types being class types. It's enough
that they dealias to one, like regular instance creation
expressions.
Contexts:
- No longer need encl method hack for return in sam.
Erasure:
- erasure preserves SAM type for function nodes
- Normalize sam to erased function type during erasure,
otherwise we may box the function body from `$anonfun(args)`
to `{$anonfun(args); ()}` because the expected type for the
body is now `Object`, and thus `Unit` does not conform.
Delambdafy:
- must set static flag before calling createBoxingBridgeMethod
- Refactored `createBoxingBridgeMethod` to wrap my head around
boxing, reworked it to generalize from FunctionN's boxing
needs to arbitrary LMF targets.
Other refactorings: ThisReferringMethodsTraverser, TreeGen.
|
| | |
|
| | |
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
`typedFunction` uniformly recognizes Single Abstract Method types
and built-in `FunctionN` types, type checking literals regardless
of expected type.
`adapt` synthesizes an anonymous subclass of the SAM type, if
needed to meet the expected (non-`FunctionN`) type.
(Later, we may want to carry `Function` AST nodes with SAM types
through the whole pipeline until the back-end, and treat them
uniformly with built-in function types there too, emitting the
corresponding `invokedynamic` & `LambdaMetaFactory` bytecode.
Would be faster to avoid synthesizing all this code during type
checking...)
Refactor `typedFunction` for performance and clarity to avoid
non-local returns. A nice perk is that the error message for missing
argument types now indicates with `<error>` where they are missing
(see updated check file).
Allow pattern matching function literals when SAM type is expected
(SI-8429).
Support `return` in function body of SAM target type, by making the
synthetic `sam$body` method transparent to the `enclMethod` chain, so
that the `return` is interpreted in its original context.
A cleaner approach to inferring unknown type params of the SAM
method. Now that `synthesizeSAMFunction` operates on typed `Function`
nodes, we can take the types of the parameters and the body and
compare them against the function type that corresponds to the SAM
method's signature. Since we are reusing the typed body, we do need
to change owners for the symbols, and substitute the new method
argument symbols for the function's vparam syms.
Impl Notes:
- The shift from typing as a regular Function for SAM types was
triggered by limitation of the old approach, which deferred type
checking the body until it was in the synthetic SAM type
subclass, which would break if the expression was subsequently
retypechecked for implicit search. Other problems related to SAM
expansion in ctor args also are dodged now.
- Using `<:<`, not `=:=`, in comparing `pt`, as `=:=` causes
`NoInstance` exceptions when `WildcardType`s are encountered.
- Can't use method type subtyping: method arguments are in
invariant pos.
- Can't use STATIC yet, results in illegal bytecode. It would be a
better encoding, since the function body should not see members
of SAM class.
- This is all battle tested by running `synthesizeSAMFunction` on
all `Function` nodes while bootstrapping, including those where a
regular function type is expected. The only thing that didn't
work was regarding Function0 and the CBN transform, which breaks
outer path creation in lambdalift.
|
| | |
|
|\ \
| | |
| | | |
SI-9314 Marginal edge case to warn-missing-interp
|
| | |
| | |
| | |
| | |
| | | |
Use the sym test on an expr that happens to be a subset of
idents and is not in scope. Other `${ operator_* }` warn.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
As an Easter egg, let "${} $x" forego the check on `x`.
In other words, empty expression interpolation looks too
degenerate to check.
|
| | |
| | |
| | |
| | |
| | | |
Edge cases of things not to warn about
include package names.
|
|\ \ \
| | | |
| | | | |
Fix some typos in `spec` documents and comments.
|
| |/ / |
|
|/ /
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Until now, concrete methods in traits were encoded with
"trait implementation classes".
- Such a trait would compile to two class files
- the trait interface, a Java interface, and
- the implementation class, containing "trait implementation methods"
- trait implementation methods are static methods has an explicit self
parameter.
- some methods don't require addition of an interface method, such as
private methods. Calls to these directly call the implementation method
- classes that mixin a trait install "trait forwarders", which implement
the abstract method in the interface by forwarding to the trait
implementation method.
The new encoding:
- no longer emits trait implementation classes or trait implementation
methods.
- instead, concrete methods are simply retained in the interface, as JVM 8
default interface methods (the JVM spec changes in
[JSR-335](http://download.oracle.com/otndocs/jcp/lambda-0_9_3-fr-eval-spec/index.html)
pave the way)
- use `invokespecial` to call private or particular super implementations
of a method (rather `invokestatic`)
- in cases when we `invokespecial` to a method in an indirect ancestor, we add
that ancestor redundantly as a direct parent. We are investigating alternatives
approaches here.
- we still emit trait fowrarders, although we are
[investigating](https://github.com/scala/scala-dev/issues/98) ways to only do
this when the JVM would be unable to resolve the correct method using its rules
for default method resolution.
Here's an example:
```
trait T {
println("T")
def m1 = m2
private def m2 = "m2"
}
trait U extends T {
println("T")
override def m1 = super[T].m1
}
class C extends U {
println("C")
def test = m1
}
```
The old and new encodings are displayed and diffed here: https://gist.github.com/retronym/f174d23f859f0e053580
Some notes in the implementation:
- No need to filter members from class decls at all in AddInterfaces
(although we do have to trigger side effecting info transformers)
- We can now emit an EnclosingMethod attribute for classes nested
in private trait methods
- Created a factory method for an AST shape that is used in
a number of places to symbolically bind to a particular
super method without needed to specify the qualifier of
the `Super` tree (which is too limiting, as it only allows
you to refer to direct parents.)
- I also found a similar tree shape created in Delambdafy,
that is better expressed with an existing tree creation
factory method, mkSuperInit.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When typechecking the synthetic default case of a pattern matching
anonymous partial function, we failed to create a new `Context`.
This led to crosstalk with the management of the saved type bounds
of an enclosing GADT pattern match.
This commit avoids the direct call to `typeCase` and instead
indirects through `typedCases`, which spawns a new nested typer
context, and hence avoids the crosstalk when `restoreSavedTypeBounds`
runs.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When typer is running during erasure, must assign erased FunctionType
in typedFunction. This removes a bunch of unneeded casts now we no longer
assign a half-erased FunctionType.
I poked around a bit, and it looks like erasure doesn't want typer
to erase built-in types (like Unit/Any/Nothing).
They are already treated specially during erasure.
|
|\ \
| | |
| | | |
SI-9629 Emit missing 'pattern must be a value' error
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
The error used to only be emitted for top-level patterns.
This commit moves it into `typedInternal` so it works
for nested patterns. It uses the typer mode to know
when to fire.
|
|/ / |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
- Language imports are preceding other imports
- Deleted empty file: InlineErasure
- Removed some unused private[parallel] methods in
scala/collection/parallel/package.scala
This removes hundreds of warnings when compiling with
"-Xlint -Ywarn-dead-code -Ywarn-unused -Ywarn-unused-import".
|
|\ \
| | |
| | | |
SI-9178 Don't eta expand to an Function0-like SAM expected type
|
| | |
| | |
| | |
| | |
| | |
| | | |
Otherwise, we can end up with a subtle source incompatibility with
the pre-SAM regime. Arguably we should phase out eta expansion to
Function0 as well, but I'll leave that for another day.
|
|/ /
| |
| |
| |
| |
| |
| | |
For @throws[E] where E is not a class type, GenASM incorrectly writes
the non-class type to the classfile. GenBCode used to crash before
this commit. Now GenBCode correctly emits the erased type (like
javac) and adds a generic signature.
|
| |
| |
| |
| |
| |
| |
| | |
Allow annotating individual callsites @inline / @noinline using an
annotation ascription
c.foo(): @inline
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
A trio of problems were hampering autocompletion of annotations.
First, given that that annotation is written before the annotated
member, it is very common to end parse incomplete code that has a
floating annotation without an anotatee.
The parser was discarding the annotations (ie, the modifiers) and
emitting an `EmptyTree`.
Second, the presetation compiler was only looking for annotations
in the Modifiers of a member def, but after typechecking annotations
are moved into the symbol.
Third, if an annotation failed to typecheck, it was being discarded
in place of `ErroneousAnnotation`.
This commit:
- modifies the parser to uses a dummy class- or type-def tree,
instead of EmptyTree, which can carry the annotations.
- updates the locator to look in the symbol annotations of the
modifiers contains no annotations.
- uses a separate instance of `ErroneousAnnotation` for each
erroneous annotation, and stores the original tree in its
`original` tree.
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
One shouldn't base any decisions of the owner of an overloaded
symbol. Instead, the owner of each of the alternatives should
be considered.
This gotcha is super easy to forget, as I did with my change to
simplify the way we detect whether we need to add the `.package`
prefix to a tree.
|
| |
| |
| |
| |
| |
| |
| |
| | |
only trivial merge conflicts here.
not dealing with PR #4333 in this merge because there is a substantial
conflict there -- so that's why I stopped at
63daba33ae99471175e9d7b20792324615f5999b for now
|
|\|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
all conflicts were because the changes changed code that
doesn't exist anymore in 2.12; they were resolved with
`git checkout --ours`
c201eac changed bincompat-forward.whitelist.conf but
I dropped the change in this merge because it refers
to AbstractPromise which no longer exists in 2.12
|
| | |
|
|\ \
| | |
| | | |
SI-9408 Avoid capturing outer class in local classes.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Using the same facility that we use to record subclasses of
sealed classes, record the subclasses of term-owned ("local")
classes.
I have changed existing callers of `children` to use `sealedChildren`
so we don't start using this new information in pattern matching
and type pattern checkability analysis.
The following commit will build on this to infer finality of local
classes in the context of outer pointer elision in the constructors
phase.
|
|\ \ \
| |/ /
|/| /
| |/ |
merge/2.11.x-to-2.12.x-20152307
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The implicit classtags required by the Array constructor are not
expressed in the type signature of its constructor, and instead
are summoned by a special case in the typechecker.
This special case entails replacing the `new Array` tree with
`implicitly[T].newArray(size)`, handled in `ArrayInstantiation`.
This tree is recursively typechecked.
However, if the implicit materialization/search fails, an error
is issued to the current reporter and the original tree is marked
with an error type. As above, this is recursively typechecked.
In the normal course of affairs, the recursive typecheck of the
erroneous tree would be a noop (the tree already has a type!).
However, if we are both in silent mode (in which errors are buffered)
and in retyping mode (in which the typer clears the type and symbols
of trees), we were getting into an cycle.
In the enclosed test, retyping mode was trying to recover
from:
Resetting.this.gencastarray_=(new Array[T](0).<ERROR>)
By inserting a suitable a view:
implicitly[Resetting => { def gencastarray_=(AT)}](
Resetting.this
).gencastarray_=(new Array[T](0))
Where AT is the type found by retypechecking the argument.
It is during the argument retypechecking that we fell into cycle.
Crazily enough, in 2.11.0, the ensuing `StackOverflowError` was
being caught and treated as a failure. We would then back out of
the retyping mode, and issue the error from the the very first attempt
at the implicit search.
This fragile state of affairs was disrupted by a refactoring to
the error reporting system in 725c5c9, after which the SOE crashed
the compiler.
This commit avoids recursively typechecking error typed trees.
|
|\| |
|
| |
| |
| |
| |
| |
| | |
I just used text search to check whether there are no more typos like
these corrected by janekdb, and by the way fixed also some other ones
which I saw.
|
| | |
|