@@ -1128,11 +1128,21 @@ object Types {
1128
1128
1129
1129
/** The type <this . name> , reduced if possible */
1130
1130
def select (name : Name )(implicit ctx : Context ): Type =
1131
- NamedType (this , name).reduceProjection
1131
+ if (Config .newScheme) NamedType .withDenot(this , member(name)).reduceProjection
1132
+ else NamedType .applyOLD(this , name).reduceProjection
1133
+
1134
+ def select (name : TermName )(implicit ctx : Context ): TermRef =
1135
+ if (Config .newScheme) TermRef .withDenot(this , member(name))
1136
+ else TermRef .applyOLD(this , name)
1137
+
1138
+ def select (name : TermName , sig : Signature )(implicit ctx : Context ): TermRef = {
1139
+ assert(Config .newScheme)
1140
+ TermRef .withDenot(this , member(name).atSignature(sig))
1141
+ }
1132
1142
1133
1143
/** The type <this . name> , reduced if possible, with given denotation if unreduced */
1134
- def select (name : Name , denot : Denotation )(implicit ctx : Context ): Type =
1135
- NamedType (this , name, denot).reduceProjection
1144
+ def select (name : Name , denot : Denotation )(implicit ctx : Context ): Type = // ### drop name
1145
+ NamedType .apply (this , name, denot).reduceProjection
1136
1146
1137
1147
/** The type <this . name> with either `sym` or its signed name as designator, reduced if possible */
1138
1148
def select (sym : Symbol )(implicit ctx : Context ): Type =
@@ -1616,7 +1626,11 @@ object Types {
1616
1626
val d = lastDenotation match {
1617
1627
case null =>
1618
1628
val sym = lastSymbol
1619
- if (sym != null && sym.isValidInCurrentRun) denotOfSym(sym) else loadDenot
1629
+ if (sym != null && sym.isValidInCurrentRun &&
1630
+ (! Config .newScheme ||
1631
+ (prefix eq NoPrefix ) || (prefix eq sym.owner.thisType) || sym.isReferencedSymbolically))
1632
+ denotOfSym(sym)
1633
+ else loadDenot
1620
1634
case d : SymDenotation =>
1621
1635
if (d.validFor.runId == ctx.runId || ctx.stillValid(d))
1622
1636
if (hasFixedSym)
@@ -1724,8 +1738,10 @@ object Types {
1724
1738
this
1725
1739
else if (signature != denot.signature)
1726
1740
withSig(denot.signature)
1727
- else if (denot.symbol.isPrivate)
1728
- withNameSpace(denot.symbol.owner.typeRef)
1741
+ else if (denot.symbol.isPrivate) {
1742
+ assert(! Config .newScheme)
1743
+ withNameSpaceOLD(denot.symbol.owner.typeRef)
1744
+ }
1729
1745
else
1730
1746
this
1731
1747
if (adapted ne this ) adapted.withDenot(denot).asInstanceOf [ThisType ]
@@ -1766,11 +1782,13 @@ object Types {
1766
1782
checkedPeriod = Nowhere
1767
1783
}
1768
1784
1769
- private def withSig (sig : Signature )(implicit ctx : Context ): NamedType =
1770
- TermRef (prefix, designator.withSig(sig))
1785
+ private def withSig (sig : Signature )(implicit ctx : Context ): NamedType = {
1786
+ assert(! Config .newScheme)
1787
+ TermRef .applyOLD(prefix, designator.withSig(sig))
1788
+ }
1771
1789
1772
1790
protected def loadDenot (implicit ctx : Context ): Denotation = {
1773
- val d = asMemberOf(prefix, allowPrivate = false )
1791
+ val d = asMemberOf(prefix, allowPrivate = Config .newScheme && hasFixedSym )
1774
1792
def atSig (sig : Signature ): Denotation =
1775
1793
if (sig.ne(Signature .OverloadedSignature )) d.atSignature(sig).checkUnique
1776
1794
else d
@@ -1945,9 +1963,9 @@ object Types {
1945
1963
1946
1964
/** Create a NamedType of the same kind as this type, but with a new namespace.
1947
1965
*/
1948
- def withNameSpace (nameSpace : NameSpace )(implicit ctx : Context ): NamedType =
1966
+ def withNameSpaceOLD (nameSpace : NameSpace )(implicit ctx : Context ): NamedType =
1949
1967
if (nameSpace == this .nameSpace) this
1950
- else NamedType (prefix, designator.withNameSpace(nameSpace))
1968
+ else NamedType .applyOLD (prefix, designator.withNameSpace(nameSpace))
1951
1969
1952
1970
override def equals (that : Any ) = that match {
1953
1971
case that : NamedType =>
@@ -1985,7 +2003,8 @@ object Types {
1985
2003
override def isOverloaded (implicit ctx : Context ) = denot.isOverloaded
1986
2004
1987
2005
private def rewrap (sd : SingleDenotation )(implicit ctx : Context ) =
1988
- TermRef (prefix, name, sd)
2006
+ if (Config .newScheme) TermRef .withDenot(prefix, sd)
2007
+ else TermRef .apply(prefix, name, sd)
1989
2008
1990
2009
def alternatives (implicit ctx : Context ): List [TermRef ] =
1991
2010
denot.alternatives map rewrap
@@ -2019,7 +2038,8 @@ object Types {
2019
2038
designator.withSig(newSig)
2020
2039
}
2021
2040
else designator
2022
- fixDenot(TermRef (prefix, designator1), prefix)
2041
+ assert(! Config .newScheme)
2042
+ fixDenot(TermRef .applyOLD(prefix, designator1), prefix)
2023
2043
}
2024
2044
}
2025
2045
@@ -2031,7 +2051,8 @@ object Types {
2031
2051
override def underlying (implicit ctx : Context ): Type = info
2032
2052
2033
2053
def withPrefix (prefix : Type )(implicit ctx : Context ): NamedType =
2034
- TypeRef (prefix, designator)
2054
+ if (Config .newScheme) TypeRef (prefix, designator.asInstanceOf [TypeSymbol ])
2055
+ else TypeRef .applyOLD(prefix, designator)
2035
2056
}
2036
2057
2037
2058
final class CachedTermRef (prefix : Type , designator : TermDesignator , hc : Int ) extends TermRef (prefix, designator) {
@@ -2049,12 +2070,19 @@ object Types {
2049
2070
if (Config .checkUnerased) assert(! ctx.phase.erasedTypes)
2050
2071
2051
2072
object NamedType {
2052
- def apply (prefix : Type , designator : Designator )(implicit ctx : Context ) =
2073
+ def applyOLD (prefix : Type , designator : Designator )(implicit ctx : Context ) =
2074
+ if (designator.isType) TypeRef .applyOLD(prefix, designator.asType)
2075
+ else TermRef .applyOLD(prefix, designator.asTerm)
2076
+ def apply (prefix : Type , designator : Symbol )(implicit ctx : Context ) =
2053
2077
if (designator.isType) TypeRef (prefix, designator.asType)
2054
2078
else TermRef (prefix, designator.asTerm)
2079
+ def withDenot (prefix : Type , denot : Denotation )(implicit ctx : Context ) =
2080
+ if (denot.isTerm) TermRef .withDenot(prefix, denot)
2081
+ else TypeRef .withDenot(prefix, denot)
2055
2082
def apply (prefix : Type , designator : Name , denot : Denotation )(implicit ctx : Context ) =
2056
- if (designator.isTermName) TermRef (prefix, designator.asTermName, denot)
2057
- else TypeRef (prefix, designator.asTypeName, denot)
2083
+ if (Config .newScheme) withDenot(prefix, denot)
2084
+ else if (designator.isTermName) TermRef .apply(prefix, designator.asTermName, denot)
2085
+ else TypeRef .apply(prefix, designator.asTypeName, denot)
2058
2086
def withSym (prefix : Type , sym : Symbol )(implicit ctx : Context ): NamedType =
2059
2087
if (sym.isType) TypeRef .withSym(prefix, sym.asType)
2060
2088
else TermRef .withSym(prefix, sym.asTerm)
@@ -2066,58 +2094,73 @@ object Types {
2066
2094
* Its meaning is the (potentially multi-) denotation of the member(s)
2067
2095
* of prefix with given name.
2068
2096
*/
2069
- def apply (prefix : Type , designator : TermDesignator )(implicit ctx : Context ): TermRef =
2097
+ def applyOLD (prefix : Type , designator : TermDesignator )(implicit ctx : Context ): TermRef =
2098
+ ctx.uniqueNamedTypes.enterIfNew(prefix, designator, isTerm = true ).asInstanceOf [TermRef ]
2099
+
2100
+ def apply (prefix : Type , designator : TermSymbol )(implicit ctx : Context ): TermRef =
2070
2101
ctx.uniqueNamedTypes.enterIfNew(prefix, designator, isTerm = true ).asInstanceOf [TermRef ]
2071
2102
2072
2103
/** Create term ref to given initial denotation, taking the signature
2073
2104
* from the denotation if it is completed, or creating a term ref without
2074
2105
* signature, if denotation is not yet completed.
2075
2106
*/
2076
2107
def apply (prefix : Type , name : TermName , denot : Denotation )(implicit ctx : Context ): TermRef = {
2077
- if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically) apply(prefix, denot.symbol.asTerm)
2108
+ if (Config .newScheme) withDenot(prefix, denot)
2109
+ else if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically) apply(prefix, denot.symbol.asTerm)
2078
2110
else denot match {
2079
2111
case denot : SingleDenotation =>
2080
- apply (prefix, name.withSig(denot.signature).localizeIfPrivate(denot.symbol))
2081
- case _ => apply (prefix, name)
2112
+ applyOLD (prefix, name.withSig(denot.signature).localizeIfPrivate(denot.symbol))
2113
+ case _ => applyOLD (prefix, name)
2082
2114
}
2083
2115
} withDenot denot
2084
2116
2117
+ def withDenot (prefix : Type , denot : Denotation )(implicit ctx : Context ): TermRef =
2118
+ apply(prefix, denot.symbol.asTerm).withDenot(denot)
2119
+
2085
2120
/** Create a term ref referring to given symbol with given name.
2086
2121
* This is similar to TermRef(Type, Symbol), except:
2087
2122
* (1) the symbol might not yet have a denotation, so the name needs to be given explicitly.
2088
2123
* (2) the designator of the TermRef is either the symbol or its name & unforced signature.
2089
2124
*/
2090
- def withSym (prefix : Type , sym : TermSymbol , name : TermName )(implicit ctx : Context ): TermRef =
2125
+ def withSymOLD (prefix : Type , sym : TermSymbol , name : TermName )(implicit ctx : Context ): TermRef =
2091
2126
if ((prefix eq NoPrefix ) || sym.isReferencedSymbolically) apply(prefix, sym)
2092
- else apply (prefix, name.withSig(sym.signature).localizeIfPrivate(sym)).withSym(sym)
2127
+ else applyOLD (prefix, name.withSig(sym.signature).localizeIfPrivate(sym)).withSym(sym)
2093
2128
2094
2129
def withSym (prefix : Type , sym : TermSymbol )(implicit ctx : Context ): TermRef =
2095
- withSym (prefix, sym, sym.name)
2130
+ if ( Config .newScheme) apply(prefix, sym) else withSymOLD (prefix, sym, sym.name)
2096
2131
}
2097
2132
2098
2133
object TypeRef {
2099
2134
2100
2135
/** Create type ref with given prefix and name */
2101
- def apply (prefix : Type , desig : TypeDesignator )(implicit ctx : Context ): TypeRef =
2136
+ def applyOLD (prefix : Type , desig : TypeDesignator )(implicit ctx : Context ): TypeRef =
2137
+ ctx.uniqueNamedTypes.enterIfNew(prefix, desig, isTerm = false ).asInstanceOf [TypeRef ]
2138
+
2139
+ /** Create type ref with given prefix and name */
2140
+ def apply (prefix : Type , desig : TypeSymbol )(implicit ctx : Context ): TypeRef =
2102
2141
ctx.uniqueNamedTypes.enterIfNew(prefix, desig, isTerm = false ).asInstanceOf [TypeRef ]
2103
2142
2104
2143
/** Create a type ref with given name and initial denotation */
2105
2144
def apply (prefix : Type , name : TypeName , denot : Denotation )(implicit ctx : Context ): TypeRef = {
2106
- if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically) apply(prefix, denot.symbol.asType)
2107
- else apply(prefix, name.localizeIfPrivate(denot.symbol))
2145
+ if (Config .newScheme) withDenot(prefix, denot)
2146
+ else if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically) apply(prefix, denot.symbol.asType)
2147
+ else applyOLD(prefix, name.localizeIfPrivate(denot.symbol))
2108
2148
} withDenot denot
2109
2149
2150
+ def withDenot (prefix : Type , denot : Denotation )(implicit ctx : Context ): TypeRef =
2151
+ apply(prefix, denot.symbol.asType).withDenot(denot)
2152
+
2110
2153
/** Create a type ref referring to either a given symbol or its name.
2111
2154
* This is similar to TypeRef(prefix, sym), except:
2112
2155
* (1) the symbol might not yet have a denotation, so the name needs to be given explicitly.
2113
2156
* (2) the designator of the TypeRef is either the symbol or its name
2114
2157
*/
2115
- def withSym (prefix : Type , sym : TypeSymbol , name : TypeName )(implicit ctx : Context ): TypeRef =
2158
+ def withSymOLD (prefix : Type , sym : TypeSymbol , name : TypeName )(implicit ctx : Context ): TypeRef =
2116
2159
if ((prefix eq NoPrefix ) || sym.isReferencedSymbolically) apply(prefix, sym)
2117
- else apply (prefix, name.localizeIfPrivate(sym)).withSym(sym)
2160
+ else applyOLD (prefix, name.localizeIfPrivate(sym)).withSym(sym)
2118
2161
2119
2162
def withSym (prefix : Type , sym : TypeSymbol )(implicit ctx : Context ): TypeRef =
2120
- withSym (prefix, sym, sym.name)
2163
+ if ( Config .newScheme) apply(prefix, sym) else withSymOLD (prefix, sym, sym.name)
2121
2164
}
2122
2165
2123
2166
// --- Other SingletonTypes: ThisType/SuperType/ConstantType ---------------------------
@@ -3445,7 +3488,8 @@ object Types {
3445
3488
if (appliedRefCache == null ) {
3446
3489
val tref =
3447
3490
if ((cls is PackageClass ) || cls.owner.isTerm) symbolicTypeRef // ??? not always symbolicRef
3448
- else TypeRef (prefix, cls.name, clsDenot)
3491
+ else if (Config .newScheme) TypeRef .withDenot(prefix, clsDenot)
3492
+ else TypeRef .apply(prefix, cls.name, clsDenot)
3449
3493
appliedRefCache =
3450
3494
tref.appliedTo(cls.typeParams.map(_.typeRef))
3451
3495
}
@@ -3527,7 +3571,20 @@ object Types {
3527
3571
case tp : ClassInfo =>
3528
3572
// Note: Taking a normal typeRef does not work here. A normal ref might contain
3529
3573
// also other information about the named type (e.g. bounds).
3530
- contains(tp.symbolicTypeRef) // ??? not clear
3574
+ if (Config .newScheme) {
3575
+ val loOK =
3576
+ lo.isRef(tp.cls) ||
3577
+ lo.isRef(defn.NothingClass ) ||
3578
+ lo.isRef(defn.NullClass ) && ! tp.cls.isValueClass
3579
+ val hiOK =
3580
+ hi.isRef(tp.cls) ||
3581
+ tp.parents.exists(p => p <:< hi)
3582
+ loOK && hiOK || {
3583
+ println(i " NOT CONTAINS: $this / $tp" )
3584
+ false
3585
+ }
3586
+ }
3587
+ else contains(tp.symbolicTypeRef)
3531
3588
case _ => lo <:< tp && tp <:< hi
3532
3589
}
3533
3590
0 commit comments