summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/Types.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-01-31 13:23:33 +0100
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-02-10 14:34:35 -0800
commitdb9fd559ec70f033b475b0d91c6049b68955e095 (patch)
tree45d7fcaf69c92b5cd16c9e7b6f52a6162db4b819 /src/reflect/scala/reflect/internal/Types.scala
parent59fc37ade773f66eb05c7b2cfebe03abaf767c51 (diff)
downloadscala-db9fd559ec70f033b475b0d91c6049b68955e095.tar.gz
scala-db9fd559ec70f033b475b0d91c6049b68955e095.tar.bz2
scala-db9fd559ec70f033b475b0d91c6049b68955e095.zip
SI-7475 Refactor findMember computation into a class
This affords us: - a better chance to share code with `findMembers` again - the ability to break up the logic into smaller methods for scrutability and JIT-tability. The cost is the use of the heap rather than the stack for the working area of the computation. But I didn't notice a difference between `locker.lib` and `quick.lib` after this change. I've left the old implementation in place with an assertion to verify identical results. In the next commit, this stepping stone will be removed, and we'll update `findMembers` to share the code. Some problem areas have been highlighted and will be addressed after the refactoring phase is complete.
Diffstat (limited to 'src/reflect/scala/reflect/internal/Types.scala')
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 17a58d79f6..b7cf8d2197 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -82,6 +82,7 @@ trait Types
with tpe.GlbLubs
with tpe.TypeMaps
with tpe.TypeConstraints
+ with tpe.FindMembers
with util.Collections { self: SymbolTable =>
import definitions._
@@ -248,7 +249,7 @@ trait Types
* type instead of the proxy. This gives buried existentials a
* chance to make peace with the other types. See SI-5330.
*/
- private def narrowForFindMember(tp: Type): Type = {
+ private[internal] def narrowForFindMember(tp: Type): Type = {
val w = tp.widen
// Only narrow on widened type when we have to -- narrow is expensive unless the target is a singleton type.
if ((tp ne w) && containsExistential(w)) w.narrow
@@ -989,6 +990,7 @@ trait Types
*
*/
def findMembers(excludedFlags: Long, requiredFlags: Long): Scope = {
+ // TODO refactor to use `FindMemberBase`
def findMembersInternal: Scope = {
var members: Scope = null
if (Statistics.canEnable) Statistics.incCounter(findMembersCount)
@@ -1055,14 +1057,25 @@ trait Types
* Find member(s) in this type. If several members matching criteria are found, they are
* returned in an OverloadedSymbol
*
- * @param name The member's name, where nme.ANYNAME means `unspecified`
+ * @param name The member's name
* @param excludedFlags Returned members do not have these flags
* @param requiredFlags Returned members do have these flags
* @param stableOnly If set, return only members that are types or stable values
*/
- //TODO: use narrow only for modules? (correct? efficiency gain?)
def findMember(name: Name, excludedFlags: Long, requiredFlags: Long, stableOnly: Boolean): Symbol = {
- def findMemberInternal: Symbol = {
+ def findMemberInternal = {
+ // TODO delete `findMemberInternalOld`
+ val resultOld = findMemberInternalOld
+ val resultNew = findMemberInternalNew
+ if (resultOld.alternatives != resultNew.alternatives) {
+ findMemberInternalOld
+ findMemberInternalNew
+ }
+ assert(resultOld.alternatives == resultNew.alternatives, s"\nOLD:${resultOld.alternatives}\nNEW${resultNew.alternatives}")
+ resultNew
+ }
+ def findMemberInternalNew = new FindMember(this, name, excludedFlags, requiredFlags, stableOnly).apply()
+ def findMemberInternalOld: Symbol = {
var member: Symbol = NoSymbol
var members: List[Symbol] = null
var lastM: ::[Symbol] = null