@@ -24,70 +24,23 @@ trait CompatComponent {
24
24
25
25
import global ._
26
26
27
- // unexpandedName replaces originalName
28
-
29
27
implicit final class SymbolCompat (self : Symbol ) {
30
- def unexpandedName : Name = self.originalName
31
- def originalName : Name = infiniteLoop()
32
-
33
28
def originalOwner : Symbol =
34
29
global.originalOwner.getOrElse(self, self.rawowner)
35
30
36
- def isPrivateThis : Boolean = self.hasAllFlags(PRIVATE | LOCAL )
37
- def isLocalToBlock : Boolean = self.isLocal
38
-
39
31
def implClass : Symbol = NoSymbol
40
32
41
33
def isTraitOrInterface : Boolean = self.isTrait || self.isInterface
42
-
43
- def tpe_* : Type = self.tpe // scalastyle:ignore
44
- }
45
-
46
- // enteringPhase/exitingPhase replace beforePhase/afterPhase
47
-
48
- @ inline final def enteringPhase [T ](ph : Phase )(op : => T ): T = {
49
- global.enteringPhase(ph)(op)
50
- }
51
-
52
- @ inline final def exitingPhase [T ](ph : Phase )(op : => T ): T = {
53
- global.exitingPhase(ph)(op)
54
34
}
55
35
56
36
implicit final class GlobalCompat (
57
37
self : CompatComponent .this .global.type ) {
58
38
59
- def enteringPhase [T ](ph : Phase )(op : => T ): T = self.beforePhase(ph)(op)
60
- def beforePhase [T ](ph : Phase )(op : => T ): T = infiniteLoop()
61
-
62
- def exitingPhase [T ](ph : Phase )(op : => T ): T = self.afterPhase(ph)(op)
63
- def afterPhase [T ](ph : Phase )(op : => T ): T = infiniteLoop()
64
-
65
- def delambdafy : DelambdafyCompat .type = DelambdafyCompat
66
-
67
- // Copied from internal/Trees.scala
68
- def NewFromConstructor (constructor : Symbol , args : Tree * ): Apply = {
69
- assert(constructor.isConstructor, constructor)
70
- val instance = New (TypeTree (constructor.owner.tpe))
71
- val init = Select (instance, nme.CONSTRUCTOR ).setSymbol(constructor)
72
- Apply (init, args.toList)
73
- }
74
-
75
39
object originalOwner {
76
40
def getOrElse (sym : Symbol , orElse : => Symbol ): Symbol = infiniteLoop()
77
41
}
78
42
}
79
43
80
- object DelambdafyCompat {
81
- object FreeVarTraverser {
82
- def freeVarsOf (function : Function ): mutable.LinkedHashSet [Symbol ] = {
83
- throw new AssertionError (
84
- " FreeVarTraverser should not be called on 2.10" )
85
- }
86
- }
87
- }
88
-
89
- // Impl classes disappeared in 2.12.0-M4
90
-
91
44
lazy val scalaUsesImplClasses : Boolean =
92
45
definitions.SeqClass .implClass != NoSymbol // a trait we know has an impl class
93
46
@@ -106,10 +59,7 @@ trait CompatComponent {
106
59
// SAMFunction was introduced in 2.12.0-M4 for LMF-capable SAM types
107
60
108
61
object SAMFunctionAttachCompatDef {
109
- /* Should extend PlainAttachment, but it does not exist in 2.10, and we
110
- * do not actually need this relationship.
111
- */
112
- case class SAMFunction (samTp : Type , sam : Symbol )
62
+ case class SAMFunction (samTp : Type , sam : Symbol ) extends PlainAttachment
113
63
}
114
64
115
65
object SAMFunctionAttachCompat {
@@ -129,13 +79,12 @@ trait CompatComponent {
129
79
/* global.genBCode.bTypes.initializeCoreBTypes()
130
80
*
131
81
* This one has a very particular history:
132
- * - in 2.10.x, no genBCode in global
133
- * - in 2.11.{0-1}, there is genBCode but it has no bTypes member
82
+ * - in 2.11.{0-1}, genBCode does not have a bTypes member
134
83
* - In 2.11.{2-5}, there is genBCode.bTypes, but it has no
135
84
* initializeCoreBTypes (it was actually typo'ed as intializeCoreBTypes!)
136
85
* - In 2.11.6+, including 2.12, we finally have
137
86
* genBCode.bTypes.initializeCoreBTypes
138
- * - As of 2.12.0-M4, it is mandatory to call that method from GenJSCode.run()
87
+ * - Since 2.12.0-M4, it is mandatory to call that method from GenJSCode.run()
139
88
*/
140
89
141
90
object LowPrioGenBCodeCompat {
@@ -147,139 +96,26 @@ trait CompatComponent {
147
96
}
148
97
149
98
def initializeCoreBTypesCompat (): Unit = {
150
- import LowPrioGenBCodeCompat ._
99
+ import LowPrioGenBCodeCompat .genBCode . _
151
100
152
101
{
153
- import global ._
102
+ import genBCode ._
154
103
155
- import LowPrioGenBCodeCompat .genBCode ._
104
+ import LowPrioGenBCodeCompat .genBCode .bTypes . _
156
105
157
106
{
158
- import genBCode ._
107
+ import bTypes ._
159
108
160
- import LowPrioGenBCodeCompat .genBCode .bTypes ._
161
-
162
- {
163
- import bTypes ._
164
-
165
- initializeCoreBTypes()
166
- }
109
+ initializeCoreBTypes()
167
110
}
168
111
}
169
112
}
170
-
171
- // Compat to support: new overridingPairs.Cursor(sym).iterator
172
-
173
- implicit class OverridingPairsCursor2Iterable (cursor : overridingPairs.Cursor ) {
174
- def iterator : Iterator [SymbolPair ] = new Iterator [SymbolPair ] {
175
- skipIgnoredEntries()
176
-
177
- def hasNext : Boolean = cursor.hasNext
178
-
179
- def next (): SymbolPair = {
180
- val symbolPair = new SymbolPair (cursor.overriding, cursor.overridden)
181
- cursor.next()
182
- skipIgnoredEntries()
183
- symbolPair
184
- }
185
-
186
- private def skipIgnoredEntries (): Unit = {
187
- while (cursor.hasNext && ignoreNextEntry)
188
- cursor.next()
189
- }
190
-
191
- /** In 2.10 the overridingPairs.Cursor returns some false positives
192
- * on overriding members. The known false positives are always trying to
193
- * override the `isInstanceOf` method.
194
- */
195
- private def ignoreNextEntry : Boolean =
196
- cursor.overriding.name == nme.isInstanceOf_
197
- }
198
-
199
- class SymbolPair (val low : Symbol , val high : Symbol )
200
-
201
- /** To make this compat code compile in 2.11 as the fields `overriding` and
202
- * `overridden` are only present in 2.10.
203
- */
204
- private implicit class Cursor210toCursor211 (cursor : overridingPairs.Cursor ) {
205
- def overriding : Symbol = infiniteLoop()
206
- def overridden : Symbol = infiniteLoop()
207
- }
208
- }
209
-
210
- // ErasedValueType has a different encoding
211
-
212
- implicit final class ErasedValueTypeCompat (self : global.ErasedValueType ) {
213
- def valueClazz : Symbol = self.original.typeSymbol
214
- def erasedUnderlying : Type =
215
- enteringPhase(currentRun.erasurePhase)(
216
- erasure.erasedValueClassArg(self.original))
217
- def original : TypeRef = infiniteLoop()
218
- }
219
-
220
- // Definitions
221
-
222
- @ inline final def repeatedToSingle (t : Type ): Type =
223
- global.definitions.repeatedToSingle(t)
224
-
225
- final def isFunctionSymbol (sym : Symbol ): Boolean =
226
- global.definitions.isFunctionSymbol(sym)
227
-
228
- private implicit final class DefinitionsCompat (
229
- self : CompatComponent .this .global.definitions.type ) {
230
-
231
- def repeatedToSingle (t : Type ): Type = t match {
232
- case TypeRef (_, self.RepeatedParamClass , arg :: Nil ) => arg
233
- case _ => t
234
- }
235
-
236
- def isFunctionSymbol (sym : Symbol ): Boolean =
237
- definitions.FunctionClass .seq.contains(definitions.unspecializedSymbol(sym))
238
-
239
- }
240
-
241
- // run.runDefinitions bundles methods and state related to the run
242
- // that were previously in definitions itself
243
-
244
- implicit final class RunCompat (self : Run ) {
245
- val runDefinitions : CompatComponent .this .global.definitions.type =
246
- global.definitions
247
- }
248
-
249
- // Mode.FUNmode replaces analyzer.FUNmode
250
-
251
- object Mode {
252
- import CompatComponent .AnalyzerCompat
253
- // No type ascription! Type is different in 2.10 / 2.11
254
- val FUNmode = analyzer.FUNmode
255
- }
256
113
}
257
114
258
115
object CompatComponent {
259
- private object LowPriorityMode {
260
- object Mode {
261
- def FUNmode : Nothing = infiniteLoop()
262
- }
263
- }
264
-
265
- private implicit final class AnalyzerCompat (self : scala.tools.nsc.typechecker.Analyzer ) {
266
- def FUNmode = { // scalastyle:ignore
267
- import CompatComponent .LowPriorityMode ._
268
- {
269
- import scala .reflect .internal ._
270
- Mode .FUNmode
271
- }
272
- }
273
- }
274
-
275
116
private def infiniteLoop (): Nothing =
276
117
throw new AssertionError (" Infinite loop in Compat" )
277
118
278
119
private def noImplClasses (): Nothing =
279
120
throw new AssertionError (" No impl classes in this version" )
280
121
}
281
-
282
- trait PluginComponentCompat extends CompatComponent {
283
- // Starting 2.11.x, we need to override the default description.
284
- def description : String
285
- }
0 commit comments