Skip to content

Commit c844809

Browse files
authored
Merge pull request #2062 from dotty-staging/fix/scala-reflect-dep
Remove most uses of scala-reflect jar
2 parents 3c4d29e + a2b3bc1 commit c844809

39 files changed

+388
-71
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package dotty.tools
2+
3+
case class FatalError(msg: String) extends Exception(msg)

compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import java.io.{File => JFile}
1515
import scala.collection.generic.Clearable
1616
import scala.collection.mutable
1717
import scala.reflect.ClassTag
18-
import scala.reflect.internal.util.WeakHashSet
1918
import scala.reflect.io.{Directory, PlainDirectory, AbstractFile}
2019
import scala.tools.asm.{ClassVisitor, FieldVisitor, MethodVisitor}
2120
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}

compiler/src/dotty/tools/backend/jvm/LabelDefs.scala

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import scala.collection.generic.Clearable
1616
import scala.collection.mutable
1717
import scala.collection.mutable.{ListBuffer, ArrayBuffer}
1818
import scala.reflect.ClassTag
19-
import scala.reflect.internal.util.WeakHashSet
2019
import scala.reflect.io.{Directory, PlainDirectory, AbstractFile}
2120
import scala.tools.asm.{ClassVisitor, FieldVisitor, MethodVisitor}
2221
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

+10-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
3131
* Does tree contain an initialization part when seen as a member of a class or trait?
3232
*/
3333
def defKind(tree: Tree): FlagSet = unsplice(tree) match {
34-
case EmptyTree | _: Import => NoInitsInterface
35-
case tree: TypeDef => if (tree.isClassDef) NoInits else NoInitsInterface
36-
case tree: DefDef => if (tree.unforcedRhs == EmptyTree) NoInitsInterface else NoInits
37-
case tree: ValDef => if (tree.unforcedRhs == EmptyTree) NoInitsInterface else EmptyFlags
38-
case _ => EmptyFlags
34+
case EmptyTree | _: Import =>
35+
NoInitsInterface
36+
case tree: TypeDef =>
37+
if (tree.isClassDef) NoInits else NoInitsInterface
38+
case tree: DefDef =>
39+
if (tree.unforcedRhs == EmptyTree && tree.vparamss.forall(_.forall(_.unforcedRhs == EmptyTree))) NoInitsInterface else NoInits
40+
case tree: ValDef =>
41+
if (tree.unforcedRhs == EmptyTree) NoInitsInterface else EmptyFlags
42+
case _ =>
43+
EmptyFlags
3944
}
4045

4146
def isOpAssign(tree: Tree) = unsplice(tree) match {

compiler/src/dotty/tools/dotc/config/Settings.scala

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package config
33

44
import collection.mutable.{ ArrayBuffer }
55
import scala.util.{ Try, Success, Failure }
6-
import scala.reflect.internal.util.StringOps
76
import reflect.ClassTag
87
import core.Contexts._
98
// import annotation.unchecked

compiler/src/dotty/tools/dotc/core/Decorators.scala

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ import printing.Formatting._
1515
object Decorators {
1616

1717
/** Turns Strings into PreNames, adding toType/TermName methods */
18-
implicit class StringDecorator(val s: String) extends AnyVal with PreName {
18+
implicit class PreNamedString(val s: String) extends AnyVal with PreName {
1919
def toTypeName: TypeName = typeName(s)
2020
def toTermName: TermName = termName(s)
2121
def toText(printer: Printer): Text = Str(s)
2222
}
2323

24+
implicit class StringDecorator(val s: String) extends AnyVal {
25+
def splitWhere(f: Char => Boolean, doDropIndex: Boolean): Option[(String, String)] = {
26+
def splitAt(idx: Int, doDropIndex: Boolean): Option[(String, String)] =
27+
if (idx == -1) None
28+
else Some((s.take(idx), s.drop(if (doDropIndex) idx + 1 else idx)))
29+
30+
splitAt(s.indexWhere(f), doDropIndex)
31+
}
32+
}
33+
2434
/** Implements a findSymbol method on iterators of Symbols that
2535
* works like find but avoids Option, replacing None with NoSymbol.
2636
*/

compiler/src/dotty/tools/dotc/core/Definitions.scala

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import scala.collection.{ mutable, immutable }
1010
import PartialFunction._
1111
import collection.mutable
1212
import util.common.alwaysZero
13-
import scala.reflect.api.{ Universe => ApiUniverse }
1413

1514
object Definitions {
1615

compiler/src/dotty/tools/dotc/core/NameOps.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.security.MessageDigest
55
import scala.annotation.switch
66
import scala.io.Codec
77
import Names._, StdNames._, Contexts._, Symbols._, Flags._
8-
import Decorators.StringDecorator
8+
import Decorators.PreNamedString
99
import util.{Chars, NameTransformer}
1010
import Chars.isOperatorPart
1111
import Definitions._

compiler/src/dotty/tools/dotc/core/StdNames.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.annotation.switch
77
import Names._
88
import Symbols._
99
import Contexts._
10-
import Decorators.StringDecorator
10+
import Decorators.PreNamedString
1111
import util.NameTransformer
1212
import scala.collection.breakOut
1313

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import scala.compat.Platform.currentTime
1212
import dotty.tools.io.{ ClassPath, AbstractFile }
1313
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, util.Positions._, Names._
1414
import StdNames._, NameOps._
15-
import Decorators.{StringDecorator, StringInterpolators}
15+
import Decorators.{PreNamedString, StringInterpolators}
1616
import classfile.ClassfileParser
1717
import scala.util.control.NonFatal
1818

compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala

+1-18
Original file line numberDiff line numberDiff line change
@@ -193,24 +193,7 @@ object PickleBuffer {
193193
private type FlagMap = Array[Array[Long]]
194194

195195
private val (scalaTermFlagMap, scalaTypeFlagMap) = {
196-
import scala.reflect.internal.Flags._
197-
198-
// The following vals are copy-pasted from reflect.internal.Flags.
199-
// They are unfortunately private there, so we cannot get at them directly.
200-
// Using the public method pickledToRawFlags instead looks unattractive
201-
// because of performance.
202-
val IMPLICIT_PKL = (1 << 0)
203-
val FINAL_PKL = (1 << 1)
204-
val PRIVATE_PKL = (1 << 2)
205-
val PROTECTED_PKL = (1 << 3)
206-
val SEALED_PKL = (1 << 4)
207-
val OVERRIDE_PKL = (1 << 5)
208-
val CASE_PKL = (1 << 6)
209-
val ABSTRACT_PKL = (1 << 7)
210-
val DEFERRED_PKL = (1 << 8)
211-
val METHOD_PKL = (1 << 9)
212-
val MODULE_PKL = (1 << 10)
213-
val INTERFACE_PKL = (1 << 11)
196+
import Scala2Flags._
214197

215198
val corr = Map(
216199
PROTECTED_PKL -> Protected,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
package dotty.tools
2+
package dotc
3+
package core
4+
package unpickleScala2
5+
6+
/** This object provides constants for pickling attributes.
7+
*
8+
* If you extend the format, be sure to increase the
9+
* version minor number.
10+
*
11+
* This was adapted from https://github.com/scala/scala/blob/2.11.x/src/reflect/scala/reflect/internal/pickling/PickleFormat.scala
12+
*
13+
* @author Martin Odersky
14+
* @version 1.0
15+
*/
16+
object PickleFormat {
17+
18+
/***************************************************
19+
* Symbol table attribute format:
20+
* Symtab = nentries_Nat {Entry}
21+
* Entry = 1 TERMNAME len_Nat NameInfo
22+
* | 2 TYPENAME len_Nat NameInfo
23+
* | 3 NONEsym len_Nat
24+
* | 4 TYPEsym len_Nat SymbolInfo
25+
* | 5 ALIASsym len_Nat SymbolInfo
26+
* | 6 CLASSsym len_Nat SymbolInfo [thistype_Ref]
27+
* | 7 MODULEsym len_Nat SymbolInfo
28+
* | 8 VALsym len_Nat [defaultGetter_Ref /* no longer needed*/] SymbolInfo [alias_Ref]
29+
* | 9 EXTref len_Nat name_Ref [owner_Ref]
30+
* | 10 EXTMODCLASSref len_Nat name_Ref [owner_Ref]
31+
* | 11 NOtpe len_Nat
32+
* | 12 NOPREFIXtpe len_Nat
33+
* | 13 THIStpe len_Nat sym_Ref
34+
* | 14 SINGLEtpe len_Nat type_Ref sym_Ref
35+
* | 15 CONSTANTtpe len_Nat constant_Ref
36+
* | 16 TYPEREFtpe len_Nat type_Ref sym_Ref {targ_Ref}
37+
* | 17 TYPEBOUNDStpe len_Nat tpe_Ref tpe_Ref
38+
* | 18 REFINEDtpe len_Nat classsym_Ref {tpe_Ref}
39+
* | 19 CLASSINFOtpe len_Nat classsym_Ref {tpe_Ref}
40+
* | 20 METHODtpe len_Nat tpe_Ref {sym_Ref}
41+
* | 21 POLYTtpe len_Nat tpe_Ref {sym_Ref}
42+
* | 22 IMPLICITMETHODtpe len_Nat tpe_Ref {sym_Ref} /* no longer needed */
43+
* | 52 SUPERtpe len_Nat tpe_Ref tpe_Ref
44+
* | 24 LITERALunit len_Nat
45+
* | 25 LITERALboolean len_Nat value_Long
46+
* | 26 LITERALbyte len_Nat value_Long
47+
* | 27 LITERALshort len_Nat value_Long
48+
* | 28 LITERALchar len_Nat value_Long
49+
* | 29 LITERALint len_Nat value_Long
50+
* | 30 LITERALlong len_Nat value_Long
51+
* | 31 LITERALfloat len_Nat value_Long
52+
* | 32 LITERALdouble len_Nat value_Long
53+
* | 33 LITERALstring len_Nat name_Ref
54+
* | 34 LITERALnull len_Nat
55+
* | 35 LITERALclass len_Nat tpe_Ref
56+
* | 36 LITERALenum len_Nat sym_Ref
57+
* | 40 SYMANNOT len_Nat sym_Ref AnnotInfoBody
58+
* | 41 CHILDREN len_Nat sym_Ref {sym_Ref}
59+
* | 42 ANNOTATEDtpe len_Nat [sym_Ref /* no longer needed */] tpe_Ref {annotinfo_Ref}
60+
* | 43 ANNOTINFO len_Nat AnnotInfoBody
61+
* | 44 ANNOTARGARRAY len_Nat {constAnnotArg_Ref}
62+
* | 47 DEBRUIJNINDEXtpe len_Nat level_Nat index_Nat /* no longer needed */
63+
* | 48 EXISTENTIALtpe len_Nat type_Ref {symbol_Ref}
64+
* | 49 TREE len_Nat 1 EMPTYtree
65+
* | 49 TREE len_Nat 2 PACKAGEtree type_Ref sym_Ref mods_Ref name_Ref {tree_Ref}
66+
* | 49 TREE len_Nat 3 CLASStree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref}
67+
* | 49 TREE len_Nat 4 MODULEtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref
68+
* | 49 TREE len_Nat 5 VALDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref tree_Ref
69+
* | 49 TREE len_Nat 6 DEFDEFtree type_Ref sym_Ref mods_Ref name_Ref numtparams_Nat {tree_Ref} numparamss_Nat {numparams_Nat {tree_Ref}} tree_Ref tree_Ref
70+
* | 49 TREE len_Nat 7 TYPEDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref}
71+
* | 49 TREE len_Nat 8 LABELtree type_Ref sym_Ref tree_Ref {tree_Ref}
72+
* | 49 TREE len_Nat 9 IMPORTtree type_Ref sym_Ref tree_Ref {name_Ref name_Ref}
73+
* | 49 TREE len_Nat 11 DOCDEFtree type_Ref sym_Ref string_Ref tree_Ref
74+
* | 49 TREE len_Nat 12 TEMPLATEtree type_Ref sym_Ref numparents_Nat {tree_Ref} tree_Ref {tree_Ref}
75+
* | 49 TREE len_Nat 13 BLOCKtree type_Ref tree_Ref {tree_Ref}
76+
* | 49 TREE len_Nat 14 CASEtree type_Ref tree_Ref tree_Ref tree_Ref
77+
* | 49 TREE len_Nat 15 SEQUENCEtree type_Ref {tree_Ref}
78+
* | 49 TREE len_Nat 16 ALTERNATIVEtree type_Ref {tree_Ref}
79+
* | 49 TREE len_Nat 17 STARtree type_Ref {tree_Ref}
80+
* | 49 TREE len_Nat 18 BINDtree type_Ref sym_Ref name_Ref tree_Ref
81+
* | 49 TREE len_Nat 19 UNAPPLYtree type_Ref tree_Ref {tree_Ref}
82+
* | 49 TREE len_Nat 20 ARRAYVALUEtree type_Ref tree_Ref {tree_Ref}
83+
* | 49 TREE len_Nat 21 FUNCTIONtree type_Ref sym_Ref tree_Ref {tree_Ref}
84+
* | 49 TREE len_Nat 22 ASSIGNtree type_Ref tree_Ref tree_Ref
85+
* | 49 TREE len_Nat 23 IFtree type_Ref tree_Ref tree_Ref tree_Ref
86+
* | 49 TREE len_Nat 24 MATCHtree type_Ref tree_Ref {tree_Ref}
87+
* | 49 TREE len_Nat 25 RETURNtree type_Ref sym_Ref tree_Ref
88+
* | 49 TREE len_Nat 26 TREtree type_Ref tree_Ref tree_Ref {tree_Ref}
89+
* | 49 TREE len_Nat 27 THROWtree type_Ref tree_Ref
90+
* | 49 TREE len_Nat 28 NEWtree type_Ref tree_Ref
91+
* | 49 TREE len_Nat 29 TYPEDtree type_Ref tree_Ref tree_Ref
92+
* | 49 TREE len_Nat 30 TYPEAPPLYtree type_Ref tree_Ref {tree_Ref}
93+
* | 49 TREE len_Nat 31 APPLYtree type_Ref tree_Ref {tree_Ref}
94+
* | 49 TREE len_Nat 32 APPLYDYNAMICtree type_Ref sym_Ref tree_Ref {tree_Ref}
95+
* | 49 TREE len_Nat 33 SUPERtree type_Ref sym_Ref tree_Ref name_Ref
96+
* | 49 TREE len_Nat 34 THIStree type_Ref sym_Ref name_Ref
97+
* | 49 TREE len_Nat 35 SELECTtree type_Ref sym_Ref tree_Ref name_Ref
98+
* | 49 TREE len_Nat 36 IDENTtree type_Ref sym_Ref name_Ref
99+
* | 49 TREE len_Nat 37 LITERALtree type_Ref constant_Ref
100+
* | 49 TREE len_Nat 38 TYPEtree type_Ref
101+
* | 49 TREE len_Nat 39 ANNOTATEDtree type_Ref tree_Ref tree_Ref
102+
* | 49 TREE len_Nat 40 SINGLETONTYPEtree type_Ref tree_Ref
103+
* | 49 TREE len_Nat 41 SELECTFROMTYPEtree type_Ref tree_Ref name_Ref
104+
* | 49 TREE len_Nat 42 COMPOUNDTYPEtree type_Ref tree_Ref
105+
* | 49 TREE len_Nat 43 APPLIEDTYPEtree type_Ref tree_Ref {tree_Ref}
106+
* | 49 TREE len_Nat 44 TYPEBOUNDStree type_Ref tree_Ref tree_Ref
107+
* | 49 TREE len_Nat 45 EXISTENTIALTYPEtree type_Ref tree_Ref {tree_Ref}
108+
* | 50 MODIFIERS len_Nat flags_Long privateWithin_Ref
109+
* SymbolInfo = name_Ref owner_Ref flags_LongNat [privateWithin_Ref] info_Ref
110+
* NameInfo = <character sequence of length len_Nat in Utf8 format>
111+
* NumInfo = <len_Nat-byte signed number in big endian format>
112+
* Ref = Nat
113+
* AnnotInfoBody = info_Ref {annotArg_Ref} {name_Ref constAnnotArg_Ref}
114+
* AnnotArg = Tree | Constant
115+
* ConstAnnotArg = Constant | AnnotInfo | AnnotArgArray
116+
*
117+
* len is remaining length after `len`.
118+
*/
119+
val MajorVersion = 5
120+
val MinorVersion = 0
121+
122+
final val TERMname = 1
123+
final val TYPEname = 2
124+
final val NONEsym = 3
125+
final val TYPEsym = 4
126+
final val ALIASsym = 5
127+
final val CLASSsym = 6
128+
final val MODULEsym = 7
129+
final val VALsym = 8
130+
final val EXTref = 9
131+
final val EXTMODCLASSref = 10
132+
final val NOtpe = 11
133+
final val NOPREFIXtpe = 12
134+
final val THIStpe = 13
135+
final val SINGLEtpe = 14
136+
final val CONSTANTtpe = 15
137+
final val TYPEREFtpe = 16
138+
final val TYPEBOUNDStpe = 17
139+
final val REFINEDtpe = 18
140+
final val CLASSINFOtpe = 19
141+
final val METHODtpe = 20
142+
final val POLYtpe = 21
143+
final val IMPLICITMETHODtpe = 22 // no longer generated
144+
145+
final val LITERAL = 23 // base line for literals
146+
final val LITERALunit = 24
147+
final val LITERALboolean = 25
148+
final val LITERALbyte = 26
149+
final val LITERALshort = 27
150+
final val LITERALchar = 28
151+
final val LITERALint = 29
152+
final val LITERALlong = 30
153+
final val LITERALfloat = 31
154+
final val LITERALdouble = 32
155+
final val LITERALstring = 33
156+
final val LITERALnull = 34
157+
final val LITERALclass = 35
158+
final val LITERALenum = 36
159+
final val SYMANNOT = 40
160+
final val CHILDREN = 41
161+
final val ANNOTATEDtpe = 42
162+
final val ANNOTINFO = 43
163+
final val ANNOTARGARRAY = 44
164+
165+
final val SUPERtpe = 46
166+
final val DEBRUIJNINDEXtpe = 47 // no longer generated
167+
final val EXISTENTIALtpe = 48
168+
169+
final val TREE = 49 // prefix code that means a tree is coming
170+
final val EMPTYtree = 1
171+
final val PACKAGEtree = 2
172+
final val CLASStree = 3
173+
final val MODULEtree = 4
174+
final val VALDEFtree = 5
175+
final val DEFDEFtree = 6
176+
final val TYPEDEFtree = 7
177+
final val LABELtree = 8
178+
final val IMPORTtree = 9
179+
final val DOCDEFtree = 11
180+
final val TEMPLATEtree = 12
181+
final val BLOCKtree = 13
182+
final val CASEtree = 14
183+
// This node type has been removed.
184+
// final val SEQUENCEtree = 15
185+
final val ALTERNATIVEtree = 16
186+
final val STARtree = 17
187+
final val BINDtree = 18
188+
final val UNAPPLYtree = 19
189+
final val ARRAYVALUEtree = 20
190+
final val FUNCTIONtree = 21
191+
final val ASSIGNtree = 22
192+
final val IFtree = 23
193+
final val MATCHtree = 24
194+
final val RETURNtree = 25
195+
final val TREtree = 26
196+
final val THROWtree = 27
197+
final val NEWtree = 28
198+
final val TYPEDtree = 29
199+
final val TYPEAPPLYtree = 30
200+
final val APPLYtree = 31
201+
final val APPLYDYNAMICtree = 32
202+
final val SUPERtree = 33
203+
final val THIStree = 34
204+
final val SELECTtree = 35
205+
final val IDENTtree = 36
206+
final val LITERALtree = 37
207+
final val TYPEtree = 38
208+
final val ANNOTATEDtree = 39
209+
final val SINGLETONTYPEtree = 40
210+
final val SELECTFROMTYPEtree = 41
211+
final val COMPOUNDTYPEtree = 42
212+
final val APPLIEDTYPEtree = 43
213+
final val TYPEBOUNDStree = 44
214+
final val EXISTENTIALTYPEtree = 45
215+
216+
final val MODIFIERS = 50
217+
218+
final val firstSymTag = NONEsym
219+
final val lastSymTag = VALsym
220+
final val lastExtSymTag = EXTMODCLASSref
221+
222+
223+
//The following two are no longer accurate, because ANNOTATEDtpe,
224+
//SUPERtpe, ... are not in the same range as the other types
225+
//final val firstTypeTag = NOtpe
226+
//final val lastTypeTag = POLYtpe
227+
}

0 commit comments

Comments
 (0)