@@ -14,11 +14,10 @@ import scala.compat.Platform.currentTime
1414import scala .collection .{ mutable , immutable }
1515import io .{ SourceReader , AbstractFile , Path }
1616import reporters .{ Reporter , ConsoleReporter }
17- import util .{ ClassPath , MergedClassPath , StatisticsInfo , returning , stackTraceString }
17+ import util .{ ClassFileLookup , ClassPath , MergedClassPath , StatisticsInfo , returning }
1818import scala .reflect .ClassTag
19- import scala .reflect .internal .util .{ OffsetPosition , SourceFile , NoSourceFile , BatchSourceFile , ScriptSourceFile }
20- import scala .reflect .internal .pickling .{ PickleBuffer , PickleFormat }
21- import scala .reflect .io .VirtualFile
19+ import scala .reflect .internal .util .{ SourceFile , NoSourceFile , BatchSourceFile , ScriptSourceFile }
20+ import scala .reflect .internal .pickling .PickleBuffer
2221import symtab .{ Flags , SymbolTable , SymbolTrackers }
2322import symtab .classfile .Pickler
2423import plugins .Plugins
@@ -35,6 +34,8 @@ import backend.opt.{ Inliners, InlineExceptionHandlers, ConstantOptimization, Cl
3534import backend .icode .analysis ._
3635import scala .language .postfixOps
3736import scala .tools .nsc .ast .{TreeGen => AstTreeGen }
37+ import scala .tools .nsc .classpath .FlatClassPath
38+ import scala .tools .nsc .settings .ClassPathRepresentationType
3839
3940class Global (var currentSettings : Settings , var reporter : Reporter )
4041 extends SymbolTable
@@ -58,7 +59,12 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
5859
5960 class GlobalMirror extends Roots (NoSymbol ) {
6061 val universe : self.type = self
61- def rootLoader : LazyType = new loaders.PackageLoader (classPath)
62+ def rootLoader : LazyType = {
63+ settings.YclasspathImpl .value match {
64+ case ClassPathRepresentationType .Flat => new loaders.PackageLoaderUsingFlatClassPath (FlatClassPath .RootPackage , flatClassPath)
65+ case ClassPathRepresentationType .Recursive => new loaders.PackageLoader (recursiveClassPath)
66+ }
67+ }
6268 override def toString = " compiler mirror"
6369 }
6470 implicit val MirrorTag : ClassTag [Mirror ] = ClassTag [Mirror ](classOf [GlobalMirror ])
@@ -104,7 +110,14 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
104110 type PlatformClassPath = ClassPath [AbstractFile ]
105111 type OptClassPath = Option [PlatformClassPath ]
106112
107- def classPath : PlatformClassPath = platform.classPath
113+ def classPath : ClassFileLookup [AbstractFile ] = settings.YclasspathImpl .value match {
114+ case ClassPathRepresentationType .Flat => flatClassPath
115+ case ClassPathRepresentationType .Recursive => recursiveClassPath
116+ }
117+
118+ private def recursiveClassPath : ClassPath [AbstractFile ] = platform.classPath
119+
120+ private def flatClassPath : FlatClassPath = platform.flatClassPath
108121
109122 // sub-components --------------------------------------------------
110123
@@ -319,7 +332,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
319332 None
320333 }
321334
322- val charset = ( if ( settings.encoding.isSetByUser) Some (settings.encoding.value) else None ) flatMap loadCharset getOrElse {
335+ val charset = settings.encoding.valueSetByUser flatMap loadCharset getOrElse {
323336 settings.encoding.value = defaultEncoding // A mandatory charset
324337 Charset .forName(defaultEncoding)
325338 }
@@ -334,16 +347,16 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
334347 }
335348 }
336349
337- ( if ( settings.sourceReader.isSetByUser) Some (settings.sourceReader.value) else None ) flatMap loadReader getOrElse {
350+ settings.sourceReader.valueSetByUser flatMap loadReader getOrElse {
338351 new SourceReader (charset.newDecoder(), reporter)
339352 }
340353 }
341354
342- if (settings.verbose || settings.Ylogcp ) {
355+ if (settings.verbose || settings.Ylogcp )
343356 reporter.echo(
344- s " [search path for source files: ${classPath.sourcepaths.mkString( " , " ) }] \n " +
345- s " [search path for class files: ${classPath.asClasspathString} " )
346- }
357+ s " [search path for source files: ${classPath.asSourcePathString }] \n " +
358+ s " [search path for class files: ${classPath.asClassPathString} ] "
359+ )
347360
348361 // The current division between scala.reflect.* and scala.tools.nsc.* is pretty
349362 // clunky. It is often difficult to have a setting influence something without having
@@ -846,6 +859,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
846859
847860 /** Extend classpath of `platform` and rescan updated packages. */
848861 def extendCompilerClassPath (urls : URL * ): Unit = {
862+ if (settings.YclasspathImpl .value == ClassPathRepresentationType .Flat )
863+ throw new UnsupportedOperationException (" Flat classpath doesn't support extending the compiler classpath" )
864+
849865 val newClassPath = platform.classPath.mergeUrlsIntoClassPath(urls : _* )
850866 platform.currentClassPath = Some (newClassPath)
851867 // Reload all specified jars into this compiler instance
@@ -881,8 +897,11 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
881897 * entries on the classpath.
882898 */
883899 def invalidateClassPathEntries (paths : String * ): Unit = {
900+ if (settings.YclasspathImpl .value == ClassPathRepresentationType .Flat )
901+ throw new UnsupportedOperationException (" Flat classpath doesn't support the classpath invalidation" )
902+
884903 implicit object ClassPathOrdering extends Ordering [PlatformClassPath ] {
885- def compare (a: PlatformClassPath , b: PlatformClassPath ) = a.asClasspathString compare b.asClasspathString
904+ def compare (a: PlatformClassPath , b: PlatformClassPath ) = a.asClassPathString compare b.asClassPathString
886905 }
887906 val invalidated, failed = new mutable.ListBuffer [ClassSymbol ]
888907 classPath match {
@@ -910,10 +929,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
910929 informProgress(s " classpath updated on entries [ ${subst.keys mkString " ," }] " )
911930 def mkClassPath (elems : Iterable [PlatformClassPath ]): PlatformClassPath =
912931 if (elems.size == 1 ) elems.head
913- else new MergedClassPath (elems, classPath .context)
932+ else new MergedClassPath (elems, recursiveClassPath .context)
914933 val oldEntries = mkClassPath(subst.keys)
915934 val newEntries = mkClassPath(subst.values)
916- mergeNewEntries(newEntries, RootClass , Some (classPath ), Some (oldEntries), invalidated, failed)
935+ mergeNewEntries(newEntries, RootClass , Some (recursiveClassPath ), Some (oldEntries), invalidated, failed)
917936 }
918937 }
919938 def show (msg : String , syms : scala.collection.Traversable [Symbol ]) =
0 commit comments