summaryrefslogtreecommitdiff
path: root/src/reflect
Commit message (Collapse)AuthorAgeFilesLines
* Upgrade asm to 5.1Lukas Rytz2016-07-201-0/+1
| | | | | The constructor of scala.tools.asm.Handle now takes an additional boolean parameter to denote whether the owner is an interface.
* Constant print control in unicodeSom Snytt2016-06-161-2/+1
| | | | | Since octal escape is deprecated, use unicode escape for string representation of constants.
* Refactor triple quote quotingSom Snytt2016-06-161-15/+15
| | | | | | | | To quote a triple quote, only quote one quote. Refactors the code for legibility. Adds test for other inline cruft like control chars.
* Avoid triple-quoting triple quotesSom Snytt2016-06-161-1/+1
| | | | | | The boolean test for triples was inadvertently flipped. Adds test for pretty printed multiline strings
* Remove TopLevelCreationFlagsLukas Rytz2016-06-062-8/+3
|
* clear all flags when resetting a symbolLukas Rytz2016-06-062-2/+1
| | | | | | this change is a bit scary because it changes code that's not been changed in 11 years https://github.com/scala/scala/commit/7fa7c93#diff-d5789e5ae5061197d782d08324b260dbL214
* Merge pull request #5099 from retronym/ticket/9390Jason Zaugg2016-06-064-0/+10
|\ | | | | SI-9390 Emit local defs that don't capture this as static
| * SI-9390 Avoid needless outer capture with local classesJason Zaugg2016-06-034-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An existing optimization in `Constructors` elides the outer field in member and local classes, if the class doesn't use the outer reference. (Member classes also need to be final, which is a secret handshake to say we're also happy to weaken prefix matching in the pattern matcher.) That optimization leaves the constructor signature as is: the constructor still accepts the outer instance, but does not store it. For member classes, this means that we can separately compile code that calls the constructor. Local classes need not be hampered by this constraint, we could remove the outer instance from the constructor call too. Why would we want to do this? Let's look at the case before and after this commit. Before: ``` class C extends Object { def foo(): Function1 = $anonfun(); final <static> <artifact> def $anonfun$foo$1($this: C, x: Object): Object = new <$anon: Object>($this); def <init>(): C = { C.super.<init>(); () } }; final class anon$1 extends Object { def <init>($outer: C): <$anon: Object> = { anon$1.super.<init>(); () } } ``` After: ``` class C extends Object { def foo(): Function1 = $anonfun(); final <static> <artifact> def $anonfun$foo$1(x: Object): Object = new <$anon: Object>(null); def <init>(): C = { C.super.<init>(); () } }; final class anon$1 extends Object { def <init>($outer: C): <$anon: Object> = { anon$1.super.<init>(); () } } ``` However, the status quo means that a lambda that This in turn makes lambdas that refer to such classes serializable even when the outer class is not itself serialiable. I have not attempted to extend this to calls to secondary constructors.
* | Merge pull request #5157 from retronym/topic/lambda-staticsJason Zaugg2016-06-066-6/+9
|\| | | | | Lambda impl methods static and more stably named
| * Lambda impl methods static and more stably namedJason Zaugg2016-06-013-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The body of lambdas is compiled into a synthetic method in the enclosing class. Previously, this method was a public virtual method named `fully$qualified$Class$$anonfun$n`. For lambdas that didn't capture a `this` reference, a static method was used. This commit changes two aspects. Firstly, all lambda impl methods are now emitted static. An extra parameter is added to those that require a this reference. This is an improvement as it: - allows, shorter, more readable names for the lambda impl method - avoids pollution of the vtable of the class. Note that javac uses private instance methods, rather than public static methods. If we followed its lead, we would be unable to support important use cases in our inliner Secondly, the name of the enclosing method has been included in the name of the lambda impl method to improve debuggability and to improve serialization compatibility. The serialization improvement comes from the way that fresh names for the impl methods are allocated: adding or removing lambdas in methods not named "foo" won't change the numbering of the `anonfun$foo$n` impl methods from methods named "foo". This is in line with user expectations about anonymous class and lambda serialization stability. Brian Goetz has described this tricky area well in: http://cr.openjdk.java.net/~briangoetz/eg-attachments/lambda-serialization.html This commit doesn't go as far a Javac, we don't use the hash of the lambda type info, param names, etc to map to a lambda impl method name. As such, we are more prone to the type-1 and -2 failures described there. However, our Scala 2.11.8 has similar characteristics, so we aren't going backwards. Special case in the naming: Use "new" rather than "<init>" for constructor enclosed lambdas, as javac does. I have also changed the way that "delambdafy target" methods are identifed. Rather than relying on the naming convention, I have switched to using a symbol attachment. The assumption is that we only need to identify them from within the same compilation unit. This means we can distinguish impl metbods for expanded functions (ones called from an `apply` method of an ahead-of-time expanded anonfun class), from those that truly end up as targets for lambda metafactory. Only the latter are translated to static methods in this patch.
| * Avoid tree sharing with substituteThisJason Zaugg2016-05-313-5/+5
| | | | | | | | | | | | | | | | | | | | The underlying transformer has a by-name parameter for the to provide the `to` tree, but this was strict in the layers of API above. Tree sharing is frowned upon in general as it leads to cross talk when, e.g., the erasure typechecker mutates the `tpe` field of the shared tree in different context.
* | Merge pull request #5205 from adriaanm/misc-optAdriaan Moors2016-06-022-7/+6
|\ \ | | | | | | Small optimizations around use of Scopes.
| * | opt: fuse some operations on `Scope`sAdriaan Moors2016-06-012-7/+6
| |/ | | | | | | | | | | | | `Scope`'s `filter` is implemented using `toList`, so may as well start with `toList`ourselves. Also fused some `filter`/`foreach` combos.
* | Merge commit 'cba585d' into merge-2.11-to-2.12-june-1Lukas Rytz2016-06-011-0/+1
|\ \ | |/ |/|
| * SI-4625 App is a thingSom Snytt2016-05-161-0/+1
| | | | | | | | Scripting knows it by name.
| * Fix bold text in reflect API for 2.11.xFelix Mulder2016-02-271-1/+1
| | | | | | Same as #4999
* | Add since arg to deprecationWarning and use itSimon Ochsenreither2016-05-294-5/+5
| |
* | Lower-case spelling of @deprecated messagesSimon Ochsenreither2016-05-2828-223/+223
| |
* | SI-9084 Add `since` (if available) to deprecation warningsSimon Ochsenreither2016-05-281-11/+16
| |
* | SI-2712 Add support for higher order unificationMiles Sabin2016-05-243-5/+37
| |
* | Merge pull request #5042 from soc/SI-9539Jason Zaugg2016-05-051-2/+2
|\ \ | | | | | | SI-9539 Specify charset when reading ScalaSignatures, ...
| * | SI-9539 Specify charset when reading ScalaSignatures, ...Simon Ochsenreither2016-03-151-2/+2
| | | | | | | | | | | | ... without it we would use the platform's default charset.
* | | Merge pull request #5094 from lrytz/classOfUnitAdriaan Moors2016-04-271-2/+3
|\ \ \ | | | | | | | | Fix erasure for classOf[Unit], don't erase to classOf[BoxedUnit]
| * | | Fix erasure for classOf[Unit], don't erase to classOf[BoxedUnit]Lukas Rytz2016-04-201-2/+3
| | | |
* | | | More efficient code for deciding if a mixin forwarder is needed (#5116)Lukas Rytz2016-04-252-0/+2
| | | | | | | | | | | | | | | | Also adds a warning on junit test methods that compile as default methods.
* | | | SI-9684 Deprecate JavaConversionsSom Snytt2016-04-221-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implicit conversions are now in package convert as ImplicitConversions, ImplicitConversionsToScala and ImplicitConversionsToJava. Deprecated WrapAsJava, WrapAsScala and the values in package object. Improve documentation.
* | | | Remove the duplicate implem of hash codes for numbers.Sébastien Doeraene2016-04-211-1/+4
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, there were two separate implementations of hash code for boxed number classes: * One in Statics, used by the codegen of case class methods. * One in ScalaRunTime + BoxesRunTime, used by everything else. This commit removes the variant implemented in ScalaRunTime + BoxesRunTime, and always uses Statics instead. We use Statics because the one from ScalaRunTime causes an unnecessary module load. The entry point ScalaRunTime.hash() is kept, as deprecated, for bootstrapping reasons.
* | | Do not rely on ScalaRunTime.{inlineEquals,hash} in JavaMirrors.Sébastien Doeraene2016-04-131-3/+3
| | | | | | | | | | | | We can use the normal Scala language constructs instead.
* | | Inline ScalaRunTime.arrayElementClass at call sites.Sébastien Doeraene2016-04-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This method was awful. Not only it was using run-time type tests to essentially encode compile-time overloading. But it also did 2 slightly different things for the Class case and ClassTag case. All in all, it is much more readable to inline the appropriate implementation at every call site.
* | | Merge pull request #5082 from lrytz/inlineImplClassCleanupLukas Rytz2016-04-074-12/+3
|\ \ \ | | | | | | | | Cleanups related to the removal of trait impl classes
| * | | Remove references to trait impl classes, mostly in doc commentsLukas Rytz2016-04-074-12/+3
| | | |
* | | | General cleanups and less warnings during a Scala buildsoc2016-04-046-7/+8
|/ / /
* | | Merge pull request #5068 from retronym/topic/jdk8ism2v2.12.0-M4Lukas Rytz2016-04-012-9/+23
|\ \ \ | | | | | | | | Accomodate and exploit new library, lang features JDK 8
| * | | At the end of a run, close macro runtime's classloaderJason Zaugg2016-03-302-9/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We can only do this on 2.12.x, because URLClassLoader#close is new in JDK 7. Tested manually with the REPL and resident compilers. ``` % qscalac sandbox/macro.scala && (for i in 1 2; do echo sandbox/client.scala; done; printf '\n') | qscalac -Xresident -Ylog:all -Ydebug 2>&1 | grep "Closing macro runtime classloader" [log terminal] Closing macro runtime classloader [log terminal] Closing macro runtime classloader % qscalac sandbox/macro.scala && (for i in 1 2; do echo Macro.m; done; printf '\n') | qscala -Ylog:all -Ydebug 2>&1 | grep "Closing macro runtime classloader"; stty echo [log terminal] Closing macro runtime classloader [log terminal] Closing macro runtime classloader ``` Note: this doesn't close handles to JAR files held by the compiler classpath implementation, that will require changes elsewhere.
* | | | Merge pull request #5059 from lrytz/t9702Adriaan Moors2016-03-312-2/+4
|\ \ \ \ | | | | | | | | | | SI-9702 Fix backend crash with classOf[T] annotation argument
| * | | | SI-9702 Fix backend crash with classOf[T] annotation argumentLukas Rytz2016-03-302-2/+4
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes various issues with classOf literals and Java annotations. - Ensure that a Type within a ConstantType (i.e., a classOf literal) is erased, so `classOf[List[Int]]` becomes `classOf[List]`. - Ensure that no non-erased types are passed to `typeToBType` in the backend. This happens for Java annotations: the annotation type and `classOf` annotation arguments are not erased, the annotationInfos of a symbol are not touched in the compiler pipeline. - If T is an alias to a value class, ensure that `classOf[T]` erases to the value class by calling `dealiasWiden` in erasure.
* | | | Bring back AbstractFunction parentAdriaan Moors2016-03-301-0/+1
| | | | | | | | | | | | | | | | | | | | Jason points out we still need it for bytecode efficiency, due to mixin forwarders.
* | | | LMF cannot instantiate SAM of trait with non-trait superclassAdriaan Moors2016-03-292-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Target FunctionN, not scala/runtime/java8/JFunction.Adriaan Moors2016-03-281-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We compile FunctionN to Java 8's idea of a function now, so no need to target the artisanal JFunction and friends, except when the function is specialized, as I don't yet see how we can use LMF with the way specialization handles FunctionN: First, the working status quo -- the hand-crafted specialized versions of JFunction0. Notice how `apply$mcB$sp` is looking pretty SAMmy: ``` @FunctionalInterface public interface JFunction0$mcB$sp extends JFunction0 { @Override public byte apply$mcB$sp(); @Override default public Object apply() { return BoxesRunTime.boxToByte(this.apply$mcB$sp()); } } ``` Contrast this with our specialized standard FunctionN: ``` public interface Function0<R> { public R apply(); default public byte apply$mcB$sp() { return BoxesRunTime.unboxToByte(this.apply()); } } public interface Function0$mcB$sp extends Function0<Object> { } ``` The single abstract method in `Function0$mcB$sp` is `apply`, and the method that would let us avoid boxing, if it were abstract, is `apply$mcB$sp`... TODO (after M4): - do same for specialized functions (issues with boxing?) - remove scala/runtime/java8/JFunction* (need new STARR?)
* | | | SAM conversion can be disabled using `-Xsource:2.11`Adriaan Moors2016-03-263-1/+5
| | | | | | | | | | | | | | | | For completeness, `-Xsource:2.11 -Xexperimental` does enable it.
* | | | Refactor: simplify fallbackAfterVanillaAdapt.Adriaan Moors2016-03-261-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Soften sam restrictionsAdriaan Moors2016-03-262-16/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some of the earlier proposals were too strongly linked to the requirements of the Java 8 platform, which was problematic for scala.js & friends. Instead of ruling out SAM types that we can't compile to use LambdaMetaFactory, expand those during compilation to anonymous subclasses, instead of invokedynamic + LMF. Also, self types rear their ugly heads again. Align `hasSelfType` with the implementation suggested in `thisSym`'s docs.
* | | | Track Function's SAM symbol & target type using an attachmentAdriaan Moors2016-03-262-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Additional SAM restrictions identified by JasonAdriaan Moors2016-03-261-6/+19
| | | | | | | | | | | | | | | | | | | | Also test roundtripping serialization of a lambda that targets a SAM that's not FunctionN (it should make no difference).
* | | | Treat `Function` literals uniformly, expecting SAM or FunctionN.Adriaan Moors2016-03-261-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Set the scene for Sammy.Adriaan Moors2016-03-262-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Go beyond refactoring and introduce some hooks and patch some holes that will become acute when we set Sammy loose. Expanding sam requires class as first parent: `addObjectParent`. (Tested in pos/sam_ctor_arg.scala, coming next.)
* | | | Refactoring. Sweep Sammy's backyard.Adriaan Moors2016-03-261-0/+5
| | | |
* | | | Refactor typedFunction, rework synthesizeSAMFunction for sammyAdriaan Moors2016-03-262-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `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-9415 Turn on SAM by defaultJason Zaugg2016-03-261-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Initial work to change settings and test by Svyatoslav Ilinskiy Thanks! To avoid cycles during overload resolution (which showed up during bootstrapping), and to improve performance, I've guarded the detection of SAM types in `isCompatible` to cases when the LHS is potentially compatible.
* | | | Refactor. Extract mkLiteralUnit and mkUnitBlockAdriaan Moors2016-03-261-4/+7
| | | |