summaryrefslogtreecommitdiff
path: root/src/reflect
Commit message (Collapse)AuthorAgeFilesLines
* SI-4700 Add `@infix` annotation for type printingVlad Ureche2016-09-193-0/+17
| | | | | | | | | | | | | ``` scala> import scala.annotation.infix import scala.annotation.infix scala> @infix class &&[T, U] defined class $amp$amp scala> def foo: Int && Boolean = ??? foo: Int && Boolean ```
* Merge pull request #5141 from adriaanm/fieldsAdriaan Moors2016-08-1116-216/+170
|\ | | | | Introducing: the fields phase [ci: last-only]
| * Drive accessor synthesis from info transformerAdriaan Moors2016-08-112-10/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Derive/filter/propagate annotations in info transformer, don't rely on having type checked the derived trees in order to see the annotations. Use synthetics mechanism for bean accessors -- the others will soon follow. Propagate inferred tpt from valdef to accessors by setting type in right spot of synthetic tree during the info completer. No need to add trees in derivedTrees, and get rid of some overfactoring in method synthesis, now that we have joined symbol and tree creation. Preserve symbol order because tests are sensitive to it. Drop warning on potentially discarded annotations, I don't think this warrants a warning. Motivated by breaking the scala-js compiler, which relied on annotations appearing when trees are type checked. Now that ordering constraint is gone in the new encoding, we may as well finally fix annotation assignment.
| * Simplify erasure + mixinAdriaan Moors2016-08-112-7/+13
| | | | | | | | | | | | | | | | | | | | | | Remove some old, obsolete & untested hacks from ExplicitOuter. Added a test for one of them to show this is now fine. There are a lot of `makeNotPrivate` invocations sprinkled around the codebase. Lets see if we can centralize the ones dealing with trait methods that need implementations in the phase that emits them. For example Fields (accessors for fields/modules) or SuperAccessors.
| * Reduce flag fiddlingAdriaan Moors2016-08-112-38/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There isn't much point to the late* flags in a world where we're mutating flags left and right in tree and info transformers... So, lets get rid of the indirection until we can include flags in a symbol's type history, like we do for its info. This retires lateDEFERRED (redundant with SYNTHESIZE_IMPL_IN_SUBCLASS). Since it's introduced so late, it makes little sense to have these synthetic members go back to DEFERRED. Instead, just set DEFERRED directly. Also remove unused late* and not* flags. notPRIVATE subsumes lateFINAL for effective finality (scala/scala-dev#126)
| * Uncurry's info transform: non-static module --> methodAdriaan Moors2016-08-115-23/+13
| | | | | | | | | | | | | | We do this during uncurry so we can insert the necessary applications to the empty argument list. Fields is too late. Refchecks is no longer an info transform.
| * Don't cache `MethodSymbol`'s `memberType`.Adriaan Moors2016-08-113-38/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | Correct caching is impossible because `sym.tpeHK.asSeenFrom(pre, sym.owner)` may have different results even for reference-identical `sym.tpeHK` and `pre` (even in the same period). For example, `pre` could be a `ThisType`. For such a type, `tpThen eq tpNow` does not imply `tpThen` and `tpNow` mean the same thing, because `tpThen.typeSymbol.info` could have been different from what it is now, and the cache won't know simply by looking at `pre`. Somehow this distinction never caused trouble, but when starting to desugar module definitions during the fields phase, it causes several test failures. I tried keying the cache on the current period to no avail.
| * Fields phase synthesizes modulesAdriaan Moors2016-08-112-13/+4
| | | | | | | | | | | | | | | | | | For now, keep the info transform in refchecks. Ultimately, refchecks should only check, not transform trees/infos. Fixes https://github.com/scala/scala-dev/issues/126: the accessor for a module in a trait is correctly marked non-final (it's deferred).
| * Fields phaseAdriaan Moors2016-08-117-86/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | One step towards teasing apart the mixin phase, making each phase that adds members to traits responsible for mixing in those members into subclasses of said traits. Another design tenet is to not emit symbols or trees only to later remove them. Therefore, we model a val in a trait as its accessor. The underlying field is an implementation detail. It must be mixed into subclasses, but has no business in a trait (an interface). Also trying to reduce tree creation by changing less in subtrees during tree transforms. A lot of nice fixes fall out from this rework: - Correct bridges and more precise generic signatures for mixed in accessors, since they are now created before erasure. - Correct enclosing method attribute for classes nested in trait fields. Trait fields are now created as MethodSymbol (no longer TermSymbol). This symbol shows up in the `originalOwner` chain of a class declared within the field initializer. This promoted the field getter to being the enclosing method of the nested class, which it is not (the EnclosingMethod attribute is a source-level property). - Signature inference is now more similar between vals and defs - No more field for constant-typed vals, or mixed in accessors for subclasses. A constant val can be fully implemented in a trait. TODO: - give same treatment to trait lazy vals (only accessors, no fields) - remove support for presuper vals in traits (they don't have the right init semantics in traits anyway) - lambdalift should emit accessors for captured vals in traits, not a field Assorted notes from the full git history before squashing below. Unit-typed vals: don't suppress field it affects the memory model -- even a write of unit to a field is relevant... unit-typed lazy vals should never receive a field this need was unmasked by test/files/run/t7843-jsr223-service.scala, which no longer printed the output expected from the `0 to 10 foreach` Use getter.referenced to track traitsetter reify's toolbox compiler changes the name of the trait that owns the accessor between fields and constructors (`$` suffix), so that the trait setter cannot be found when doing mkAssign in constructors this could be solved by creating the mkAssign tree immediately during fields anyway, first experiment: use `referenced` now that fields runs closer to the constructors phase (I tried this before and something broke) Infer result type for `val`s, like we do for `def`s The lack of result type inference caused pos/t6780 to fail in the new field encoding for traits, as there is no separate accessor, and method synthesis computes the type signature based on the ValDef tree. This caused a cyclic error in implicit search, because now the implicit val's result type was not inferred from the super member, and inferring it from the RHS would cause implicit search to consider the member in question, so that a cycle is detected and type checking fails... Regardless of the new encoding, we should consistently infer result types for `def`s and `val`s. Removed test/files/run/t4287inferredMethodTypes.scala and test/files/presentation/t4287c, since they were relying on inferring argument types from "overridden" constructors in a test for range positions of default arguments. Constructors don't override, so that was a mis-feature of -Yinfer-argument-types. Had to slightly refactor test/files/presentation/doc, as it was relying on scalac inferring a big intersection type to approximate the anonymous class that's instantiated for `override lazy val analyzer`. Now that we infer `Global` as the expected type based on the overridden val, we make `getComment` private in navigating between good old Skylla and Charybdis. I'm not sure why we need this restriction for anonymous classes though; only structural calls are restricted in the way that we're trying to avoid. The old behavior is maintained nder -Xsource:2.11. Tests: - test/files/{pos,neg}/val_infer.scala - test/files/neg/val_sig_infer_match.scala - test/files/neg/val_sig_infer_struct.scala need NMT when inferring sig for accessor Q: why are we calling valDefSig and not methodSig? A: traits use defs for vals, but still use valDefSig... keep accessor and field info in synch
| * Do not add `@TraitSetter` -- not sure what it's forAdriaan Moors2016-08-092-2/+1
| | | | | | | | Also deprecate the TraitSetter annotation.
* | Merge pull request #5272 from som-snytt/issue/8829Adriaan Moors2016-08-111-0/+9
|\ \ | |/ |/| SI-8829 Defaultly scala -feature -deprecation
| * SI-8829 Let reporter customize retry messageSom Snytt2016-07-091-0/+9
| | | | | | | | | | | | | | | | "Re-run with -deprecation" is not always appropriate. REPL gets to customize the message. The API includes the setting and its name, because reflect Settings do not have names. (!)
* | Merge pull request #5279 from retronym/ticket/SD-183Adriaan Moors2016-07-261-2/+2
|\ \ | | | | | | SD-183 Make refinement classes ineligible as SAMs
| * | SD-183 Make refinement classes ineligible as SAMsJason Zaugg2016-07-141-2/+2
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Only non-refinement class types need apply, which is the same restriction that we levy on parent types of a class. ``` scala> class C; class D extends C; type CD = C with D; class E extends CD <console>:11: error: class type required but C with D found class C; class D extends C; type CD = C with D; class E extends CD ^ scala> class C; class D extends C; type DC = D with C; class E extends DC <console>:11: error: class type required but D with C found class C; class D extends C; type DC = D with C; class E extends DC ^ ``` Prior to this change: ``` scala> trait T { def t(a: Any): Any }; trait U; abstract class C extends T defined trait T defined trait U defined class C ```` For indy-based lambdas: ``` scala> val tu: T with U = x => x tu: T with U = $$Lambda$1812/317644782@3c3c4a71 scala> tu: U java.lang.ClassCastException: $$Lambda$1812/317644782 cannot be cast to U ... 30 elided ``` For anon class based lambdas: ``` scala> ((x => x): C with U) <console>:14: error: class type required but C with U found ((x => x): C with U) ^ scala> implicit def anyToCWithU(a: Any): C with U = new C with U { def t(a: Any) = a } warning: there was one feature warning; re-run with -feature for details anyToCWithU: (a: Any)C with U scala> (((x: Any) => x): C with U) // SAM chosen but fails to typecheck the expansion uncurry <console>:17: error: class type required but C with U found (((x: Any) => x): C with U) // SAM chosen but fails to typecheck the expansion uncurry ^ ``` Fixes https://github.com/scala/scala-dev/issues/183 While it is tempting to special case refinement classes with no decls by flattening their parents into the parents of the lambda. But there are some subtle issues at play with lineriazation order, as Martin pointed out when I brought this up before: http://www.scala-lang.org/old/node/6817.html
* | 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.