diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-02-10 11:46:15 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-02-10 11:46:15 -0800 |
commit | da3f7177232e7c0732d5b7d2929dbb8271d7b395 (patch) | |
tree | 71b1f31626991ed3b9cd92af6bd6605588866f8c /test/debug | |
parent | 78c378c97c51600cac1cf42edd050aceb2366026 (diff) | |
download | scala-da3f7177232e7c0732d5b7d2929dbb8271d7b395.tar.gz scala-da3f7177232e7c0732d5b7d2929dbb8271d7b395.tar.bz2 scala-da3f7177232e7c0732d5b7d2929dbb8271d7b395.zip |
Towards understanding `TypeRef`'s `transformInfo`/`baseType`
By reducing excessive factoring, we can save an extraneous call
to `asSeenFrom`, and hopefully in a following commit figure out
a bigger problem with `baseType` that is causing wrong subtyping results.
This commit is a pure refactoring, save for the dropped ASF call,
which is explained below.
To motivate the following change to `relativeInfo`:
```
private[Types] def relativeInfo = /*trace(s"relativeInfo(${safeToString}})")*/{
if (relativeInfoPeriod != currentPeriod) {
- val memberInfo = pre.memberInfo(sym)
- relativeInfoCache = transformInfo(memberInfo)
+ relativeInfoCache = memberInfoInstantiated
```
Let's consolidate the two removed line in this new method:
```
def memberInfoInstantiated = transformInfo(pre.memberInfo(sym))
```
To understand what `transformInfo` does, take these helpers spread over
various `*TypeRef` traits, and consolidate them:
```
- def asSeenFromOwner(tp: Type) = tp.asSeenFrom(pre, sym.owner)
// regular type refs:
- def transformInfo(tp: Type): Type = appliedType(asSeenFromOwner(tp), args)
// for no-args type refs:
- override def transformInfo(tp: Type): Type = appliedType(asSeenFromOwner(tp), dummyArgs)
```
By removing the dynamic dispatch, we get the following method
(given `require(args0 ne Nil, this)` in `ArgsTypeRef`,
and `args eq Nil` by construction in `NoArgsTypeRef` ):
```
def transformInfo(tp: Type) =
appliedType(tp.asSeenFrom(pre, sym.owner), if (args.isEmpty) dummyArgs else args)
```
Inlining `memberInfo`, which is defined as:
```
def memberInfo(sym: Symbol): Type = {
require(sym ne NoSymbol, this)
sym.info.asSeenFrom(this, sym.owner)
}
```
gives us:
```
def memberInfoInstantiated = transformInfo(sym.info.asSeenFrom(pre, sym.owner))
```
Inlining `transformInfo` as reworked above:
```
def memberInfoInstantiated =
appliedType(sym.info.asSeenFrom(pre, sym.owner).asSeenFrom(pre, sym.owner),
if (args.isEmpty) dummyArgs else args)
```
Whoops! One `asSeenFrom` should do...
```
+ final protected def memberInfoInstantiated: Type =
+ appliedType(sym.info.asSeenFrom(pre, sym.owner), if (args.isEmpty) dummyArgs else args)
```
Diffstat (limited to 'test/debug')
0 files changed, 0 insertions, 0 deletions